Skip to content

Commit

Permalink
Change plugin data map to object
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrunyon committed Jan 26, 2024
1 parent 6fadd77 commit 7c4cfb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
12 changes: 7 additions & 5 deletions packages/dashboard/src/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ export const updateDashboardData =
);

/**
* Action to update the dashboard data. Will combine the update with any existing dashboard data.
* Action to set the dashboard plugin data.
* Will replace any existing plugin data for the plugin in the dashboard with the data provided.
* @param id The id of the dashboard to set the data on
* @param pluginId The id of the plugin to set the data on
* @param data The data to replace the existing plugin data with
* @returns
* @returns Thunk action to dispatch
*/
export const setDashboardPluginData =
(
Expand All @@ -59,8 +60,9 @@ export const setDashboardPluginData =
dispatch(
setDashboardData(id, {
...getDashboardData(getState(), id),
pluginDataMap: new Map(
getPluginDataMapForDashboard(getState(), id)
).set(pluginId, data),
pluginDataMap: {
...getPluginDataMapForDashboard(getState(), id),
[pluginId]: data,
},
})
);
4 changes: 2 additions & 2 deletions packages/dashboard/src/redux/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const getPluginDataMapForDashboard = (
store: RootState,
dashboardId: string
): PluginDataMap =>
getDashboardData(store, dashboardId).pluginDataMap ?? EMPTY_MAP;
getDashboardData(store, dashboardId).pluginDataMap ?? EMPTY_OBJECT;

/**
* @param store The redux store
Expand All @@ -77,4 +77,4 @@ export const getPluginDataForDashboard = (
store: RootState,
dashboardId: string,
pluginId: string
): PluginData => getPluginDataMapForDashboard(store, dashboardId).get(pluginId);
): PluginData => getPluginDataMapForDashboard(store, dashboardId)[pluginId];
5 changes: 4 additions & 1 deletion packages/redux/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ export interface Workspace {

export type PluginData = unknown;

export type PluginDataMap = Map<string, PluginData>;
export type PluginDataMap = Record<string, PluginData>;

export type DashboardData = Record<string, unknown> & {
title?: string;
closed?: unknown[];
filterSets?: unknown[];
pluginDataMap?: PluginDataMap;
};

Expand Down

0 comments on commit 7c4cfb4

Please sign in to comment.