Skip to content

Commit 7fec4d2

Browse files
authored
Merge pull request #26 from bcdev/forman-21-support_contrib_state
Support contrib state
2 parents c986b4d + ff534c2 commit 7fec4d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+499
-243
lines changed

dashi/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dashi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dashipopashi",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "An experimental library for integrating interactive charts into existing JavaScript applications.",
55
"type": "module",
66
"files": [
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { updateContributionState } from "@/lib";
1+
import { updateContributionContainer } from "@/lib";
22
import type { PanelState } from "@/demo/types";
33

44
export function hidePanel(panelIndex: number) {
5-
updateContributionState<PanelState>("panels", panelIndex, { visible: false });
5+
updateContributionContainer<PanelState>("panels", panelIndex, {
6+
visible: false,
7+
});
68
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { updateContributionState } from "@/lib";
1+
import { updateContributionContainer } from "@/lib";
22
import type { PanelState } from "@/demo/types";
33

44
export function showPanel(panelIndex: number) {
5-
updateContributionState<PanelState>("panels", panelIndex, { visible: true });
5+
updateContributionContainer<PanelState>("panels", panelIndex, {
6+
visible: true,
7+
});
68
}

dashi/src/demo/components/Panel.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import type { CSSProperties, ReactElement } from "react";
22
import CircularProgress from "@mui/material/CircularProgress";
3-
4-
import {
5-
type ComponentChangeHandler,
6-
type ContributionState,
7-
Component,
8-
} from "@/lib";
3+
import { Component } from "@/lib";
4+
import type { ComponentState, ComponentChangeHandler } from "@/lib";
95
import type { PanelState } from "@/demo/types";
106

117
const panelContainerStyle: CSSProperties = {
@@ -32,39 +28,43 @@ const panelContentStyle: CSSProperties = {
3228
padding: 2,
3329
};
3430

35-
interface PanelProps extends ContributionState<PanelState> {
31+
interface PanelProps extends PanelState {
32+
componentProps?: ComponentState;
33+
componentStatus?: string;
34+
componentError?: { message: string };
3635
onChange: ComponentChangeHandler;
3736
}
3837

3938
function Panel({
40-
name,
41-
state,
42-
component,
43-
componentResult,
39+
title,
40+
visible,
41+
componentProps,
42+
componentStatus,
43+
componentError,
4444
onChange,
4545
}: PanelProps) {
46-
if (!state.visible) {
46+
if (!visible) {
4747
return null;
4848
}
4949
let panelElement: ReactElement | null = null;
50-
if (component) {
51-
panelElement = <Component {...component} onChange={onChange} />;
52-
} else if (componentResult.error) {
50+
if (componentProps) {
51+
panelElement = <Component {...componentProps} onChange={onChange} />;
52+
} else if (componentError) {
5353
panelElement = (
5454
<span>
55-
Error loading {name}: {componentResult.error.message}
55+
Error loading panel {title}: {componentError.message}
5656
</span>
5757
);
58-
} else if (componentResult.status === "pending") {
58+
} else if (componentStatus === "pending") {
5959
panelElement = (
6060
<span>
61-
<CircularProgress size={30} color="secondary" /> Loading {name}...
61+
<CircularProgress size={30} color="secondary" /> Loading {title}...
6262
</span>
6363
);
6464
}
6565
return (
6666
<div style={panelContainerStyle}>
67-
<div style={panelHeaderStyle}>{state.title}</div>
67+
<div style={panelHeaderStyle}>{title}</div>
6868
<div style={panelContentStyle}>{panelElement}</div>
6969
</div>
7070
);

dashi/src/demo/components/PanelsControl.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ function PanelsControl() {
1717
<FormGroup sx={{ display: "flex", flexDirection: "row" }}>
1818
{panelStates.map((panelState, panelIndex) => {
1919
const id = `panels.${panelIndex}`;
20+
const { title, visible } = panelState.container;
2021
return (
2122
<FormControlLabel
2223
key={panelIndex}
23-
label={panelState.state.title}
24+
label={title}
2425
control={
2526
<Checkbox
2627
color="secondary"
2728
id={id}
28-
checked={panelState.state.visible || false}
29+
checked={visible || false}
2930
value={panelIndex}
3031
onChange={(e) => {
3132
if (e.currentTarget.checked) {

dashi/src/demo/components/PanelsRow.tsx

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { JSX } from "react";
2-
31
import { type ComponentChangeEvent, handleComponentChange } from "@/lib";
42
import { usePanelStates } from "@/demo/hooks";
53
import Panel from "./Panel";
@@ -17,23 +15,21 @@ function PanelsRow() {
1715
) => {
1816
handleComponentChange("panels", panelIndex, panelEvent);
1917
};
20-
const visiblePanels: JSX.Element[] = [];
21-
panelStates.forEach((panelState, panelIndex) => {
22-
if (panelState.state.visible) {
23-
visiblePanels.push(
24-
<Panel
25-
key={panelIndex}
26-
{...panelState}
27-
onChange={(e) => handlePanelChange(panelIndex, e)}
28-
/>,
29-
);
30-
}
18+
const panels = panelStates.map((panelState, panelIndex) => {
19+
const { container, component, componentResult } = panelState;
20+
return (
21+
<Panel
22+
key={panelIndex}
23+
{...container}
24+
componentProps={component}
25+
componentStatus={componentResult.status}
26+
componentError={componentResult.error}
27+
onChange={(e) => handlePanelChange(panelIndex, e)}
28+
/>
29+
);
3130
});
32-
const panelElements = <>{visiblePanels}</>;
3331
return (
34-
<div style={{ display: "flex", gap: 5, paddingTop: 10 }}>
35-
{panelElements}
36-
</div>
32+
<div style={{ display: "flex", gap: 5, paddingTop: 10 }}>{panels}</div>
3733
);
3834
}
3935

dashi/src/lib/actions/configureFramework.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { store } from "@/lib/store";
22
import type { FrameworkOptions } from "@/lib/types/state/store";
3-
import { configureLogging } from "@/lib/utils/configureLogging";
3+
import { configureLogging } from "@/lib/actions/helpers/configureLogging";
44
import { handleHostStoreChange } from "./handleHostStoreChange";
55

66
export function configureFramework<S extends object = object>(

dashi/src/lib/actions/handleComponentChange.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function handleComponentChange(
1717
contribIndex,
1818
stateChanges: [
1919
{
20-
kind: "Component",
20+
link: "component",
2121
id: changeEvent.componentId,
2222
property: changeEvent.propertyName,
2323
value: changeEvent.propertyValue,
@@ -57,7 +57,8 @@ function getCallbackRequests(
5757
const inputs = callback.inputs;
5858
const inputIndex = inputs.findIndex(
5959
(input) =>
60-
(!input.kind || input.kind === "Component") &&
60+
!input.noTrigger &&
61+
(!input.link || input.link === "component") &&
6162
input.id === changeEvent.componentId &&
6263
input.property === changeEvent.propertyName,
6364
);

dashi/src/lib/actions/handleHostStoreChange.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type {
55
CallbackRef,
66
CallbackRequest,
77
ContribRef,
8-
Input,
98
InputRef,
109
} from "@/lib/types/model/callback";
10+
import type { Input } from "@/lib/types/model/channel";
1111
import { getInputValues } from "@/lib/actions/helpers/getInputValues";
1212
import { getValue, type PropertyPath } from "@/lib/utils/getValue";
1313
import { invokeCallbacks } from "@/lib/actions/helpers/invokeCallbacks";
@@ -59,6 +59,9 @@ function getCallbackRequests<S extends object = object>(
5959

6060
const getHostStorePropertyRefs = memoizeOne(_getHostStorePropertyRefs);
6161

62+
/**
63+
* Get the static list of host state property references for all contributions.
64+
*/
6265
function _getHostStorePropertyRefs(): PropertyRef[] {
6366
const { contributionsRecord } = store.getState();
6467
const propertyRefs: PropertyRef[] = [];
@@ -68,13 +71,13 @@ function _getHostStorePropertyRefs(): PropertyRef[] {
6871
(contribution.callbacks || []).forEach(
6972
(callback, callbackIndex) =>
7073
(callback.inputs || []).forEach((input, inputIndex) => {
71-
if (input.kind === "AppState") {
74+
if (!input.noTrigger && input.link === "app") {
7275
propertyRefs.push({
7376
contribPoint,
7477
contribIndex,
7578
callbackIndex,
7679
inputIndex,
77-
propertyPath: input.property.split("."),
80+
propertyPath: input.property!.split("."),
7881
});
7982
}
8083
}),

0 commit comments

Comments
 (0)