Skip to content

Commit 5d8898e

Browse files
committed
Initial panel title contribution
1 parent 6c437d8 commit 5d8898e

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

dashi/src/actions/setComponentVisibility.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export function setComponentVisibility(
88
panelIndex: number,
99
visible: boolean,
1010
) {
11-
const getState = appStore.getState;
12-
const contributionStates = getState().contributionStatesRecord[contribPoint];
11+
const { contributionStatesRecord } = appStore.getState();
12+
const contributionStates = contributionStatesRecord[contribPoint];
1313
const contributionState = contributionStates[panelIndex];
1414
if (contributionState.visible === visible) {
1515
return; // nothing to do

dashi/src/actions/updateContributionState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function updateContributionState(
66
panelIndex: number,
77
panelState: Partial<ContributionState>,
88
) {
9-
const contributionStatesRecord = appStore.getState().contributionStatesRecord;
9+
const { contributionStatesRecord } = appStore.getState();
1010
const contribStates = contributionStatesRecord[contribPoint]!;
1111
appStore.setState({
1212
contributionStatesRecord: {

dashi/src/app/Panel.tsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import {CSSProperties, ReactElement} from "react";
1+
import { CSSProperties, ReactElement } from "react";
22

3-
import { Contribution } from "../model/contribution";
43
import { PropertyChangeHandler } from "../model/component";
54
import DashiComponent from "../components/DashiComponent";
65
import { ContributionState } from "../store/appStore";
7-
import {CircularProgress} from "@mui/material";
6+
import { CircularProgress } from "@mui/material";
7+
import { PanelModel } from "../model/panel";
88

99
const panelContainerStyle: CSSProperties = {
1010
display: "flex",
@@ -15,8 +15,15 @@ const panelContainerStyle: CSSProperties = {
1515
border: "1px gray solid",
1616
};
1717

18+
const panelHeaderStyle: CSSProperties = {
19+
display: "flex",
20+
flexDirection: "column",
21+
width: "100%",
22+
textAlign: "center",
23+
};
24+
1825
interface PanelProps {
19-
panelModel: Contribution;
26+
panelModel: PanelModel;
2027
panelState: ContributionState;
2128
onPropertyChange: PropertyChangeHandler;
2229
}
@@ -41,9 +48,19 @@ function Panel({ panelModel, panelState, onPropertyChange }: PanelProps) {
4148
</span>
4249
);
4350
} else if (componentModelResult.status === "pending") {
44-
panelElement = <span><CircularProgress size={30} color="secondary" /> Loading {panelModel.name}...</span>;
51+
panelElement = (
52+
<span>
53+
<CircularProgress size={30} color="secondary" /> Loading{" "}
54+
{panelModel.name}...
55+
</span>
56+
);
4557
}
46-
return <div style={panelContainerStyle}>{panelElement}</div>;
58+
return (
59+
<div style={panelContainerStyle}>
60+
<div style={panelHeaderStyle}>{panelModel.title}</div>
61+
{panelElement}
62+
</div>
63+
);
4764
}
4865

4966
export default Panel;

dashi/src/app/PanelsRow.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,26 @@ import { PropertyChangeEvent } from "../model/component";
33
import useAppStore from "../store/appStore";
44
import Panel from "./Panel";
55
import handleComponentPropertyChange from "../actions/handleComponentPropertyChange";
6+
import { PanelModel } from "../model/panel";
67

78
const contribPoint = "panels";
89

910
function PanelsRow() {
10-
const appState = useAppStore();
11-
12-
console.log("appState", appState);
11+
const contributionStatesRecord = useAppStore(
12+
(state) => state.contributionStatesRecord,
13+
);
14+
const contributionsRecordResult = useAppStore(
15+
(state) => state.contributionsRecordResult,
16+
);
1317

1418
let panelElements: ReactElement | null = null;
15-
const contributionsRecordResult = appState.contributionsRecordResult;
1619
if (contributionsRecordResult.data) {
17-
const panelModels = contributionsRecordResult.data[contribPoint];
18-
const panelStates = appState.contributionStatesRecord[contribPoint];
20+
// TODO: Validate that PanelModel contains a title (It should be valid).
21+
// It can be done in one central place and not everytime we need to render a panel
22+
const panelModels = contributionsRecordResult.data[
23+
contribPoint
24+
] as PanelModel[];
25+
const panelStates = contributionStatesRecord[contribPoint];
1926
if (
2027
!panelModels ||
2128
!panelStates ||

dashi/src/model/panel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Contribution } from "./contribution";
2+
3+
export interface PanelModel extends Contribution {
4+
title: string;
5+
}

0 commit comments

Comments
 (0)