|
1 | 1 | import { OBJ_TYPES } from 'constants/Common'; |
2 | 2 | import { cloneDeep } from 'lodash'; |
3 | 3 | import { create } from 'zustand'; |
| 4 | +import { produce } from 'immer'; |
4 | 5 |
|
5 | 6 | export const useTabStore = create((set, get) => ({ |
6 | 7 | tabs: [], |
@@ -34,51 +35,61 @@ export const useTabStore = create((set, get) => ({ |
34 | 35 | }, |
35 | 36 | // these state changes are meant to be triggered by canvas in focus |
36 | 37 | updateFlowTestNodes: (nodes) => { |
37 | | - if (get().focusTabId) { |
38 | | - const existingTab = get().tabs.find((t) => t.id === get().focusTabId); |
39 | | - if (existingTab) { |
40 | | - if (!existingTab.flowDataDraft) { |
41 | | - existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {}; |
| 38 | + set( |
| 39 | + produce((state) => { |
| 40 | + if (state.focusTabId) { |
| 41 | + const existingTab = state.tabs.find((t) => t.id === state.focusTabId); |
| 42 | + if (existingTab) { |
| 43 | + if (!existingTab.flowDataDraft) { |
| 44 | + existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {}; |
| 45 | + } |
| 46 | + existingTab.flowDataDraft.nodes = nodes; |
| 47 | + } |
42 | 48 | } |
43 | | - existingTab.flowDataDraft.nodes = nodes; |
44 | | - } |
45 | | - console.log(existingTab); |
46 | | - } |
| 49 | + }), |
| 50 | + ); |
47 | 51 | }, |
48 | 52 | // these state changes are meant to be triggered by canvas in focus |
49 | 53 | updateFlowTestEdges: (edges) => { |
50 | | - if (get().focusTabId) { |
51 | | - const existingTab = get().tabs.find((t) => t.id === get().focusTabId); |
52 | | - if (existingTab) { |
53 | | - if (!existingTab.flowDataDraft) { |
54 | | - existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {}; |
| 54 | + set( |
| 55 | + produce((state) => { |
| 56 | + if (state.focusTabId) { |
| 57 | + const existingTab = state.tabs.find((t) => t.id === state.focusTabId); |
| 58 | + if (existingTab) { |
| 59 | + if (!existingTab.flowDataDraft) { |
| 60 | + existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {}; |
| 61 | + } |
| 62 | + existingTab.flowDataDraft.edges = edges; |
| 63 | + } |
55 | 64 | } |
56 | | - existingTab.flowDataDraft.edges = edges; |
57 | | - } |
58 | | - console.log(existingTab); |
59 | | - } |
| 65 | + }), |
| 66 | + ); |
60 | 67 | }, |
61 | 68 | // these state changes are meant to be triggered by canvas in focus |
62 | 69 | updateFlowTestViewport: (viewport) => { |
63 | | - if (get().focusTabId) { |
64 | | - const existingTab = get().tabs.find((t) => t.id === get().focusTabId); |
65 | | - if (existingTab) { |
66 | | - if (!existingTab.flowDataDraft) { |
67 | | - existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {}; |
| 70 | + set( |
| 71 | + produce((state) => { |
| 72 | + if (state.focusTabId) { |
| 73 | + const existingTab = state.tabs.find((t) => t.id === state.focusTabId); |
| 74 | + if (existingTab) { |
| 75 | + if (!existingTab.flowDataDraft) { |
| 76 | + existingTab.flowDataDraft = existingTab.flowData ? cloneDeep(existingTab.flowData) : {}; |
| 77 | + } |
| 78 | + existingTab.flowDataDraft.viewport = viewport; |
| 79 | + } |
68 | 80 | } |
69 | | - existingTab.flowDataDraft.viewport = viewport; |
70 | | - } |
71 | | - console.log(existingTab); |
72 | | - } |
| 81 | + }), |
| 82 | + ); |
73 | 83 | }, |
74 | | - updateFlowTestLogs: (logs) => { |
75 | | - if (get().focusTabId) { |
76 | | - const existingTab = get().tabs.find((t) => t.id === get().focusTabId); |
77 | | - if (existingTab) { |
78 | | - existingTab.logs = logs; |
79 | | - } |
80 | | - console.log(existingTab); |
81 | | - } |
| 84 | + updateFlowTestLogs: (tabId, logs) => { |
| 85 | + set( |
| 86 | + produce((state) => { |
| 87 | + const existingTab = state.tabs.find((t) => t.id === tabId); |
| 88 | + if (existingTab) { |
| 89 | + existingTab.logs = logs; |
| 90 | + } |
| 91 | + }), |
| 92 | + ); |
82 | 93 | }, |
83 | 94 | addEnvTab: (env, collectionId) => { |
84 | 95 | const existingTab = get().tabs.find( |
|
0 commit comments