Skip to content

Commit

Permalink
Refactor dashboard components to utilize JSONFunctions for deserializ…
Browse files Browse the repository at this point in the history
…ation of dashboard view configurations
  • Loading branch information
simlarsen committed Nov 28, 2024
1 parent 2f8495e commit 5c2fa28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ArgumentsForm: FunctionComponent<ComponentProps> = (
hideSubmitButton={true}
ref={formRef}
initialValues={{
...(component || {}),
...(component?.arguments || {}),
}}
onChange={(values: FormValues<JSONObject>) => {
setComponent({
Expand Down
7 changes: 6 additions & 1 deletion Dashboard/src/Components/Dashboard/Canvas/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import DashboardBaseComponentElement from "../Components/DashboardBaseComponent"
import { GetReactElementFunction } from "Common/UI/Types/FunctionTypes";
import ObjectID from "Common/Types/ObjectID";
import ComponentSettingsSideOver from "./ComponentSettingsSideOver";
import JSONFunctions from "Common/Types/JSONFunctions";

export interface ComponentProps {
dashboardViewConfig: DashboardViewConfig;
Expand Down Expand Up @@ -153,7 +154,11 @@ const DashboardCanvas: FunctionComponent<ComponentProps> = (
components: [...updatedComponents],
};

props.onDashboardViewConfigChange(updatedDashboardViewConfig);
props.onDashboardViewConfigChange(
JSONFunctions.deserializeValue(
updatedDashboardViewConfig,
) as DashboardViewConfig,
);
};

const renderComponent: RenderComponentFunction = (
Expand Down
19 changes: 12 additions & 7 deletions Dashboard/src/Components/Dashboard/DashboardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import PageLoader from "Common/UI/Components/Loader/PageLoader";
import DashboardViewConfigUtil from "Common/Utils/Dashboard/DashboardViewConfig";
import DefaultDashboardSize from "Common/Types/Dashboard/DashboardSize";
import { PromiseVoidFunction, VoidFunction } from "Common/Types/FunctionTypes";
import JSONFunctions from "Common/Types/JSONFunctions";

export interface ComponentProps {
dashboardId: ObjectID;
Expand Down Expand Up @@ -116,8 +117,10 @@ const DashboardViewer: FunctionComponent<ComponentProps> = (
}

setDashboardViewConfig(
dashboard.dashboardViewConfig ||
DashboardViewConfigUtil.createDefaultDashboardViewConfig(),
JSONFunctions.deserializeValue(
dashboard.dashboardViewConfig ||
DashboardViewConfigUtil.createDefaultDashboardViewConfig(),
) as DashboardViewConfig,
);
setDashboardName(dashboard.name || "Untitled Dashboard");
} catch (err) {
Expand Down Expand Up @@ -203,10 +206,12 @@ const DashboardViewer: FunctionComponent<ComponentProps> = (
}

const newDashboardConfig: DashboardViewConfig =
DashboardViewConfigUtil.addComponentToDashboard({
component: newComponent,
dashboardViewConfig: dashboardViewConfig,
});
JSONFunctions.deserializeValue(
DashboardViewConfigUtil.addComponentToDashboard({
component: newComponent,
dashboardViewConfig: dashboardViewConfig,
}),
) as DashboardViewConfig;

setDashboardViewConfig(newDashboardConfig);
}}
Expand All @@ -215,7 +220,7 @@ const DashboardViewer: FunctionComponent<ComponentProps> = (
<DashboardCanvas
dashboardViewConfig={dashboardViewConfig}
onDashboardViewConfigChange={(newConfig: DashboardViewConfig) => {
setDashboardViewConfig(JSON.parse(JSON.stringify(newConfig)));
setDashboardViewConfig(newConfig);
}}
onComponentSelected={(componentId: ObjectID) => {
// Do nothing
Expand Down

0 comments on commit 5c2fa28

Please sign in to comment.