Skip to content

Commit 24a4d7c

Browse files
committed
workspaceid atom
1 parent 8659220 commit 24a4d7c

8 files changed

Lines changed: 48 additions & 27 deletions

File tree

frontend/app/store/contextmenu.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ class ContextMenuModel {
7474
this.activeOpts = opts;
7575
const electronMenuItems = this._convertAndRegisterMenu(menu);
7676

77-
const workspace = globalStore.get(atoms.workspace);
77+
const workspaceId = globalStore.get(atoms.workspaceId);
7878
let oid: string;
7979

80-
if (workspace != null) {
81-
oid = workspace.oid;
80+
if (workspaceId != null) {
81+
oid = workspaceId;
8282
} else {
8383
oid = globalStore.get(atoms.builderId);
8484
}

frontend/app/store/global-atoms.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
4343
console.log("failed to initialize zoomFactorAtom", e);
4444
}
4545

46-
const workspaceAtom: Atom<Workspace> = atom((get) => {
46+
const workspaceIdAtom: Atom<string> = atom((get) => {
4747
const windowData = WOS.getObjectValue<WaveWindow>(WOS.makeORef("window", get(windowIdAtom)), get);
48-
if (windowData == null) {
48+
return windowData?.workspaceid ?? null;
49+
});
50+
const workspaceAtom: Atom<Workspace> = atom((get) => {
51+
const workspaceId = get(workspaceIdAtom);
52+
if (workspaceId == null) {
4953
return null;
5054
}
51-
return WOS.getObjectValue(WOS.makeORef("workspace", windowData.workspaceid), get);
55+
return WOS.getObjectValue(WOS.makeORef("workspace", workspaceId), get);
5256
});
5357
const fullConfigAtom = atom(null) as PrimitiveAtom<FullConfigType>;
5458
const waveaiModeConfigAtom = atom(null) as PrimitiveAtom<Record<string, AIModeConfigType>>;
@@ -123,6 +127,7 @@ function initGlobalAtoms(initOpts: GlobalInitOptions) {
123127
builderId: builderIdAtom,
124128
builderAppId: builderAppIdAtom,
125129
uiContext: uiContextAtom,
130+
workspaceId: workspaceIdAtom,
126131
workspace: workspaceAtom,
127132
fullConfigAtom,
128133
waveaiModeConfigAtom,

frontend/app/store/keymodel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ function getStaticTabBlockCount(): number {
129129
}
130130

131131
function simpleCloseStaticTab() {
132-
const ws = globalStore.get(atoms.workspace);
132+
const workspaceId = globalStore.get(atoms.workspaceId);
133133
const tabId = globalStore.get(atoms.staticTabId);
134134
const confirmClose = globalStore.get(getSettingsKeyAtom("tab:confirmclose")) ?? false;
135135
getApi()
136-
.closeTab(ws.oid, tabId, confirmClose)
136+
.closeTab(workspaceId, tabId, confirmClose)
137137
.then((didClose) => {
138138
if (didClose) {
139139
deleteLayoutModelForTab(tabId);

frontend/app/workspace/widgets.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export type WidgetsEnv = WaveEnvSubset<{
3030
};
3131
atoms: {
3232
fullConfigAtom: WaveEnv["atoms"]["fullConfigAtom"];
33-
workspace: WaveEnv["atoms"]["workspace"];
33+
workspaceId: WaveEnv["atoms"]["workspaceId"];
3434
hasCustomAIPresetsAtom: WaveEnv["atoms"]["hasCustomAIPresetsAtom"];
3535
};
3636
createBlock: WaveEnv["createBlock"];
@@ -348,7 +348,7 @@ SettingsFloatingWindow.displayName = "SettingsFloatingWindow";
348348
const Widgets = memo(() => {
349349
const env = useWaveEnv<WidgetsEnv>();
350350
const fullConfig = useAtomValue(env.atoms.fullConfigAtom);
351-
const workspace = useAtomValue(env.atoms.workspace);
351+
const workspaceId = useAtomValue(env.atoms.workspaceId);
352352
const hasCustomAIPresets = useAtomValue(env.atoms.hasCustomAIPresetsAtom);
353353
const [mode, setMode] = useState<"normal" | "compact" | "supercompact">("normal");
354354
const containerRef = useRef<HTMLDivElement>(null);
@@ -361,7 +361,7 @@ const Widgets = memo(() => {
361361
if (!hasCustomAIPresets && key === "defwidget@ai") {
362362
return false;
363363
}
364-
return shouldIncludeWidgetForWorkspace(widget, workspace?.oid);
364+
return shouldIncludeWidgetForWorkspace(widget, workspaceId);
365365
})
366366
);
367367
const widgets = sortByDisplayOrder(filteredWidgets);

frontend/preview/mock/mockwaveenv.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ function makeMockSettingsKeyAtom(
8888
}
8989

9090
function makeMockGlobalAtoms(
91-
settingsOverrides?: Partial<SettingsType>,
92-
atomOverrides?: Partial<GlobalAtomsType>,
93-
tabId?: string
91+
settingsOverrides: Partial<SettingsType>,
92+
atomOverrides: Partial<GlobalAtomsType>,
93+
tabId: string,
94+
getWaveObjectAtom: <T extends WaveObj>(oref: string) => PrimitiveAtom<T>
9495
): GlobalAtomsType {
9596
let fullConfig = DefaultFullConfig;
9697
if (settingsOverrides) {
@@ -101,11 +102,20 @@ function makeMockGlobalAtoms(
101102
}
102103
const fullConfigAtom = atom(fullConfig) as PrimitiveAtom<FullConfigType>;
103104
const settingsAtom = atom((get) => get(fullConfigAtom)?.settings ?? {}) as Atom<SettingsType>;
105+
const workspaceIdAtom: Atom<string> = atomOverrides?.workspaceId ?? (atom(null as string) as Atom<string>);
106+
const workspaceAtom: Atom<Workspace> = atom((get) => {
107+
const wsId = get(workspaceIdAtom);
108+
if (wsId == null) {
109+
return null;
110+
}
111+
return get(getWaveObjectAtom<Workspace>("workspace:" + wsId));
112+
});
104113
const defaults: GlobalAtomsType = {
105114
builderId: atom(""),
106115
builderAppId: atom("") as any,
107116
uiContext: atom({ windowid: "", activetabid: tabId ?? "" } as UIContext),
108-
workspace: atom(null as Workspace),
117+
workspaceId: workspaceIdAtom,
118+
workspace: workspaceAtom,
109119
fullConfigAtom,
110120
waveaiModeConfigAtom: atom({}) as any,
111121
settingsAtom,
@@ -125,7 +135,11 @@ function makeMockGlobalAtoms(
125135
if (!atomOverrides) {
126136
return defaults;
127137
}
128-
return { ...defaults, ...atomOverrides };
138+
const merged = { ...defaults, ...atomOverrides };
139+
if (!atomOverrides.workspace) {
140+
merged.workspace = workspaceAtom;
141+
}
142+
return merged;
129143
}
130144

131145
type MockWosFns = {
@@ -221,7 +235,14 @@ export function makeMockWaveEnv(mockEnv?: MockEnv): MockWaveEnv {
221235
const waveObjectDerivedAtomCache = new Map<string, Atom<any>>();
222236
const blockMetaKeyAtomCache = new Map<string, Atom<any>>();
223237
const connConfigKeyAtomCache = new Map<string, Atom<any>>();
224-
const atoms = makeMockGlobalAtoms(overrides.settings, overrides.atoms, overrides.tabId);
238+
const getWaveObjectAtom = <T extends WaveObj>(oref: string): PrimitiveAtom<T> => {
239+
if (!waveObjectValueAtomCache.has(oref)) {
240+
const obj = (overrides.mockWaveObjs?.[oref] ?? null) as T;
241+
waveObjectValueAtomCache.set(oref, atom(obj) as PrimitiveAtom<T>);
242+
}
243+
return waveObjectValueAtomCache.get(oref) as PrimitiveAtom<T>;
244+
};
245+
const atoms = makeMockGlobalAtoms(overrides.settings, overrides.atoms, overrides.tabId, getWaveObjectAtom);
225246
const localHostDisplayNameAtom = atom<string>((get) => {
226247
const configValue = get(atoms.settingsAtom)?.["conn:localhostdisplayname"];
227248
if (configValue != null) {
@@ -230,13 +251,7 @@ export function makeMockWaveEnv(mockEnv?: MockEnv): MockWaveEnv {
230251
return "user@localhost";
231252
});
232253
const mockWosFns: MockWosFns = {
233-
getWaveObjectAtom: <T extends WaveObj>(oref: string) => {
234-
if (!waveObjectValueAtomCache.has(oref)) {
235-
const obj = (overrides.mockWaveObjs?.[oref] ?? null) as T;
236-
waveObjectValueAtomCache.set(oref, atom(obj) as PrimitiveAtom<T>);
237-
}
238-
return waveObjectValueAtomCache.get(oref) as PrimitiveAtom<T>;
239-
},
254+
getWaveObjectAtom,
240255
mockSetWaveObj: <T extends WaveObj>(oref: string, obj: T) => {
241256
if (!waveObjectValueAtomCache.has(oref)) {
242257
waveObjectValueAtomCache.set(oref, atom(null as WaveObj));

frontend/preview/preview.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function PreviewRoot() {
9595
atoms: {
9696
uiContext: atom({ windowid: PreviewWindowId, activetabid: PreviewTabId } as UIContext),
9797
staticTabId: atom(PreviewTabId),
98+
workspaceId: atom(PreviewWorkspaceId),
9899
},
99100
})
100101
);
@@ -143,6 +144,7 @@ function PreviewApp() {
143144

144145
const PreviewTabId = crypto.randomUUID();
145146
const PreviewWindowId = crypto.randomUUID();
147+
const PreviewWorkspaceId = crypto.randomUUID();
146148
const PreviewClientId = crypto.randomUUID();
147149

148150
function initPreview() {

frontend/preview/previews/widgets.preview.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { atom, useAtom } from "jotai";
77
import { useRef } from "react";
88
import { applyMockEnvOverrides } from "../mock/mockwaveenv";
99

10-
const workspaceAtom = atom<Workspace>(null as Workspace);
1110
const resizableHeightAtom = atom(250);
1211

1312
function makeMockApp(name: string, icon: string, iconcolor: string): AppInfo {
@@ -91,7 +90,6 @@ function makeWidgetsEnv(baseEnv: WaveEnv, isDev: boolean, hasCustomAIPresets: bo
9190
rpc: { ListAllAppsCommand: () => Promise.resolve(apps ?? []) },
9291
atoms: {
9392
fullConfigAtom,
94-
workspace: workspaceAtom,
9593
hasCustomAIPresetsAtom: atom(hasCustomAIPresets),
9694
},
9795
});

frontend/types/custom.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ declare global {
1111
builderId: jotai.Atom<string>; // readonly (for builder mode)
1212
builderAppId: jotai.PrimitiveAtom<string>; // app being edited in builder mode
1313
uiContext: jotai.Atom<UIContext>; // driven from windowId, tabId
14-
workspace: jotai.Atom<Workspace>; // driven from WOS
14+
workspaceId: jotai.Atom<string>; // derived from window WOS object
15+
workspace: jotai.Atom<Workspace>; // driven from workspaceId via WOS
1516
fullConfigAtom: jotai.PrimitiveAtom<FullConfigType>; // driven from WOS, settings -- updated via WebSocket
1617
waveaiModeConfigAtom: jotai.PrimitiveAtom<Record<string, AIModeConfigType>>; // resolved AI mode configs -- updated via WebSocket
1718
settingsAtom: jotai.Atom<SettingsType>; // derrived from fullConfig

0 commit comments

Comments
 (0)