Skip to content

Commit fb8bfc2

Browse files
authored
Merge pull request #8 from bcdev/yogesh-add-panel-title-contribution
Add Panel Title Contribution
2 parents 86f2cb5 + f0f8e8b commit fb8bfc2

File tree

10 files changed

+54
-14
lines changed

10 files changed

+54
-14
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: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
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";
76
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
}
@@ -48,7 +55,12 @@ function Panel({ panelModel, panelState, onPropertyChange }: PanelProps) {
4855
</span>
4956
);
5057
}
51-
return <div style={panelContainerStyle}>{panelElement}</div>;
58+
return (
59+
<div style={panelContainerStyle}>
60+
<div style={panelHeaderStyle}>{panelModel.title}</div>
61+
{panelElement}
62+
</div>
63+
);
5264
}
5365

5466
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+
}

dashipy/dashipy/contribs/panel.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
from typing import Any
2+
13
from dashipy.lib import Contribution
24

35

46
class Panel(Contribution):
57
"""Panel contribution"""
8+
def __init__(self, name: str, title: str):
9+
super().__init__(name)
10+
self.title = title
11+
12+
def to_dict(self) -> dict[str, Any]:
13+
return {
14+
**super().to_dict(),
15+
"title": self.title
16+
17+
}

dashipy/dashipy/lib/extension.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ def decorator(function: Callable) -> Callable:
4646

4747
return decorator
4848

49+
def __str__(self):
50+
return self.name
51+
4952

5053
class Extension:
5154
"""A UI Extension."""

dashipy/dashipy/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
DASHI_EXTENSIONS_KEY = "dashi.extensions"
1818
DASHI_CONTRIBUTION_POINTS_KEY = "dashi.contribution_points"
1919

20+
# This would done by extension of xcube server
2021
Extension.add_contrib_point("panels", Panel)
2122

2223

dashipy/my_extension/my_panel_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dashipy.lib import Output, Input, Component
88

99

10-
panel = Panel(__name__)
10+
panel = Panel(__name__, title="Panel A")
1111

1212

1313
@panel.layout()

dashipy/my_extension/my_panel_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dashipy.lib import Output, Input, Component
88

99

10-
panel = Panel(__name__)
10+
panel = Panel(__name__, title="Panel B")
1111

1212

1313
@panel.layout()

0 commit comments

Comments
 (0)