Skip to content

Commit

Permalink
Merge pull request #4859 from voxel51/bugfix/missing-panel-state-scope
Browse files Browse the repository at this point in the history
fix state scope missing in some panel hooks
  • Loading branch information
brimoor authored Sep 27, 2024
2 parents 7ebfd94 + d3960f8 commit 887654f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions app/packages/spaces/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ export const panelStateSelector = selectorFamily({
(params: PanelStateParameter) =>
({ get }) => {
const { panelId, local, scope } = params;
const stateAtom = getStateAtom(local, scope);
const fallbackScope = get(panelIdToScopeAtom)[panelId];
const computedScope = scope ?? fallbackScope;
const stateAtom = getStateAtom(local, computedScope);
return get(stateAtom).get(panelId);
},
set:
(params: PanelStateParameter) =>
({ get, set }, newValue) => {
const { panelId, local, scope } = params;
const stateAtom = getStateAtom(local, scope);
const fallbackScope = get(panelIdToScopeAtom)[panelId];
const computedScope = scope ?? fallbackScope;
const stateAtom = getStateAtom(local, computedScope);
const newState = new Map(get(stateAtom));
newState.set(panelId, newValue);
set(stateAtom, newState);
Expand Down Expand Up @@ -125,7 +129,7 @@ export const savedWorkspacesAtom = atom({
},
});

export const panelIdToScopeAtom = atom({
export const panelIdToScopeAtom = atom<PanelIdToScopeType>({
key: "panelIdToScopeAtom",
default: {},
});
Expand All @@ -134,3 +138,7 @@ function getStateAtom(local?: boolean, scope?: string) {
const nonGridScope = scope !== "grid";
return local || nonGridScope ? panelsLocalStateAtom : panelsStateAtom;
}

type PanelIdToScopeType = {
[panelId: string]: string;
};

0 comments on commit 887654f

Please sign in to comment.