Skip to content

Commit b2bf290

Browse files
ivicacclaude
andcommitted
2948 client - Rename layout direction store to workflow UUID semantics
The store now tracks currentWorkflowUuid and directionsByWorkflowUuid so the API name matches what it actually stores. Bumps persist version to drop stale id-keyed entries from previous releases. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 81ea89b commit b2bf290

3 files changed

Lines changed: 44 additions & 44 deletions

File tree

client/src/pages/platform/workflow-editor/hooks/useWorkflowEditorCanvas.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ const useWorkflowEditorCanvas = ({
8080
setNodes: state.setNodes,
8181
}))
8282
);
83-
const {layoutDirection, setWorkflowId} = useLayoutDirectionStore(
83+
const {layoutDirection, setCurrentWorkflowUuid} = useLayoutDirectionStore(
8484
useShallow((state) => ({
8585
layoutDirection: state.layoutDirection,
86-
setWorkflowId: state.setWorkflowId,
86+
setCurrentWorkflowUuid: state.setCurrentWorkflowUuid,
8787
}))
8888
);
8989
const copilotPanelOpen = useCopilotPanelStore((state) => state.copilotPanelOpen);
@@ -554,7 +554,7 @@ const useWorkflowEditorCanvas = ({
554554

555555
useEffect(() => {
556556
if (workflowUuid) {
557-
setWorkflowId(workflowUuid);
557+
setCurrentWorkflowUuid(workflowUuid);
558558
}
559559

560560
setViewport(

client/src/pages/platform/workflow-editor/stores/tests/useLayoutDirectionStore.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ describe('useLayoutDirectionStore', () => {
77
beforeEach(() => {
88
// Reset to a clean state by clearing the Zustand store entirely
99
useLayoutDirectionStore.setState({
10-
currentWorkflowId: '',
11-
directionsByWorkflow: {},
10+
currentWorkflowUuid: '',
11+
directionsByWorkflowUuid: {},
1212
layoutDirection: 'TB',
1313
});
1414
});
@@ -23,23 +23,23 @@ describe('useLayoutDirectionStore', () => {
2323
const {result} = renderHook(() => useLayoutDirectionStore());
2424

2525
act(() => {
26-
result.current.setWorkflowId('workflow-1');
26+
result.current.setCurrentWorkflowUuid('workflow-1');
2727
});
2828

2929
act(() => {
3030
result.current.setLayoutDirection('LR');
3131
});
3232

3333
expect(result.current.layoutDirection).toBe('LR');
34-
expect(result.current.directionsByWorkflow['workflow-1']).toBe('LR');
34+
expect(result.current.directionsByWorkflowUuid['workflow-1']).toBe('LR');
3535
});
3636

3737
it('should restore saved direction when switching to a workflow', () => {
3838
const {result} = renderHook(() => useLayoutDirectionStore());
3939

4040
// Set workflow-1 to LR
4141
act(() => {
42-
result.current.setWorkflowId('workflow-1');
42+
result.current.setCurrentWorkflowUuid('workflow-1');
4343
});
4444

4545
act(() => {
@@ -48,43 +48,43 @@ describe('useLayoutDirectionStore', () => {
4848

4949
// Switch to workflow-2 (should default to TB)
5050
act(() => {
51-
result.current.setWorkflowId('workflow-2');
51+
result.current.setCurrentWorkflowUuid('workflow-2');
5252
});
5353

5454
expect(result.current.layoutDirection).toBe('TB');
5555

5656
// Switch back to workflow-1 (should restore LR)
5757
act(() => {
58-
result.current.setWorkflowId('workflow-1');
58+
result.current.setCurrentWorkflowUuid('workflow-1');
5959
});
6060

6161
expect(result.current.layoutDirection).toBe('LR');
6262
});
6363

64-
it('should default to TB for unknown workflow IDs', () => {
64+
it('should default to TB for unknown workflow UUIDs', () => {
6565
const {result} = renderHook(() => useLayoutDirectionStore());
6666

6767
act(() => {
68-
result.current.setWorkflowId('unknown-workflow');
68+
result.current.setCurrentWorkflowUuid('unknown-workflow');
6969
});
7070

7171
expect(result.current.layoutDirection).toBe('TB');
7272
});
7373

74-
it('should not update state when setting the same workflow ID', () => {
74+
it('should not update state when setting the same workflow UUID', () => {
7575
const {result} = renderHook(() => useLayoutDirectionStore());
7676

7777
act(() => {
78-
result.current.setWorkflowId('workflow-1');
78+
result.current.setCurrentWorkflowUuid('workflow-1');
7979
});
8080

8181
act(() => {
8282
result.current.setLayoutDirection('LR');
8383
});
8484

85-
// Setting the same ID should be a no-op
85+
// Setting the same UUID should be a no-op
8686
act(() => {
87-
result.current.setWorkflowId('workflow-1');
87+
result.current.setCurrentWorkflowUuid('workflow-1');
8888
});
8989

9090
expect(result.current.layoutDirection).toBe('LR');
@@ -94,30 +94,30 @@ describe('useLayoutDirectionStore', () => {
9494
const {result} = renderHook(() => useLayoutDirectionStore());
9595

9696
act(() => {
97-
result.current.setWorkflowId('workflow-1');
97+
result.current.setCurrentWorkflowUuid('workflow-1');
9898
});
9999

100100
act(() => {
101101
result.current.setLayoutDirection('LR');
102102
});
103103

104104
act(() => {
105-
result.current.setWorkflowId('workflow-2');
105+
result.current.setCurrentWorkflowUuid('workflow-2');
106106
});
107107

108108
act(() => {
109109
result.current.setLayoutDirection('TB');
110110
});
111111

112-
expect(result.current.directionsByWorkflow['workflow-1']).toBe('LR');
113-
expect(result.current.directionsByWorkflow['workflow-2']).toBe('TB');
112+
expect(result.current.directionsByWorkflowUuid['workflow-1']).toBe('LR');
113+
expect(result.current.directionsByWorkflowUuid['workflow-2']).toBe('TB');
114114
});
115115

116116
it('should toggle layout direction', () => {
117117
const {result} = renderHook(() => useLayoutDirectionStore());
118118

119119
act(() => {
120-
result.current.setWorkflowId('workflow-1');
120+
result.current.setCurrentWorkflowUuid('workflow-1');
121121
});
122122

123123
expect(result.current.layoutDirection).toBe('TB');

client/src/pages/platform/workflow-editor/stores/useLayoutDirectionStore.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@ import {create} from 'zustand';
33
import {devtools, persist} from 'zustand/middleware';
44

55
interface LayoutDirectionStateI {
6-
currentWorkflowId: string;
7-
directionsByWorkflow: Record<string, LayoutDirectionType>;
6+
currentWorkflowUuid: string;
7+
directionsByWorkflowUuid: Record<string, LayoutDirectionType>;
88
layoutDirection: LayoutDirectionType;
9+
setCurrentWorkflowUuid: (workflowUuid: string) => void;
910
setLayoutDirection: (layoutDirection: LayoutDirectionType) => void;
10-
setWorkflowId: (workflowId: string) => void;
1111
}
1212

1313
const useLayoutDirectionStore = create<LayoutDirectionStateI>()(
1414
devtools(
1515
persist(
1616
(set, get) => ({
17-
currentWorkflowId: '',
18-
directionsByWorkflow: {},
17+
currentWorkflowUuid: '',
18+
directionsByWorkflowUuid: {},
1919
layoutDirection: DEFAULT_LAYOUT_DIRECTION,
2020

21-
setLayoutDirection: (layoutDirection) =>
22-
set((state) => ({
23-
directionsByWorkflow: {
24-
...state.directionsByWorkflow,
25-
[state.currentWorkflowId]: layoutDirection,
26-
},
27-
layoutDirection,
28-
})),
29-
30-
setWorkflowId: (workflowId) => {
31-
if (workflowId === get().currentWorkflowId) {
21+
setCurrentWorkflowUuid: (workflowUuid) => {
22+
if (workflowUuid === get().currentWorkflowUuid) {
3223
return;
3324
}
3425

3526
set((state) => ({
36-
currentWorkflowId: workflowId,
37-
layoutDirection: state.directionsByWorkflow[workflowId] ?? DEFAULT_LAYOUT_DIRECTION,
27+
currentWorkflowUuid: workflowUuid,
28+
layoutDirection: state.directionsByWorkflowUuid[workflowUuid] ?? DEFAULT_LAYOUT_DIRECTION,
3829
}));
3930
},
31+
32+
setLayoutDirection: (layoutDirection) =>
33+
set((state) => ({
34+
directionsByWorkflowUuid: {
35+
...state.directionsByWorkflowUuid,
36+
[state.currentWorkflowUuid]: layoutDirection,
37+
},
38+
layoutDirection,
39+
})),
4040
}),
4141
{
4242
migrate: (persisted, version) => {
43-
if (version === 0) {
44-
return {directionsByWorkflow: {}};
43+
if (version < 2) {
44+
return {directionsByWorkflowUuid: {}};
4545
}
4646

47-
return persisted as {directionsByWorkflow: Record<string, LayoutDirectionType>};
47+
return persisted as {directionsByWorkflowUuid: Record<string, LayoutDirectionType>};
4848
},
4949
name: 'bytechef.layout-direction',
50-
partialize: (state) => ({directionsByWorkflow: state.directionsByWorkflow}),
51-
version: 1,
50+
partialize: (state) => ({directionsByWorkflowUuid: state.directionsByWorkflowUuid}),
51+
version: 2,
5252
}
5353
)
5454
)

0 commit comments

Comments
 (0)