From d3960f888657ee6fa44454907a899afc4b02e773 Mon Sep 17 00:00:00 2001 From: imanjra Date: Fri, 27 Sep 2024 14:06:47 -0400 Subject: [PATCH] fix state scope missing in some panel hooks --- app/packages/spaces/src/state.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/packages/spaces/src/state.ts b/app/packages/spaces/src/state.ts index 7cb54b6e69..360ab4caae 100644 --- a/app/packages/spaces/src/state.ts +++ b/app/packages/spaces/src/state.ts @@ -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); @@ -125,7 +129,7 @@ export const savedWorkspacesAtom = atom({ }, }); -export const panelIdToScopeAtom = atom({ +export const panelIdToScopeAtom = atom({ key: "panelIdToScopeAtom", default: {}, }); @@ -134,3 +138,7 @@ function getStateAtom(local?: boolean, scope?: string) { const nonGridScope = scope !== "grid"; return local || nonGridScope ? panelsLocalStateAtom : panelsStateAtom; } + +type PanelIdToScopeType = { + [panelId: string]: string; +};