Skip to content

Commit b73d448

Browse files
authored
Merge pull request #129 from FlowTestAI/watcher-fix
fix file system to ide updates for env and flowtest tabs
2 parents 3144747 + d66093d commit b73d448

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/flowtest-electron/src/app/watcher.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ class Watcher {
9292
change(mainWindow, pathname, collectionId, watchPath) {
9393
console.log(`[Watcher] file ${pathname} changed`);
9494
if (this.isFlowTestFile(pathname)) {
95+
const content = readFile(pathname);
96+
const flowData = serialize(JSON.parse(content));
9597
const file = {
9698
name: path.basename(pathname),
97-
pathname: pathname,
99+
pathname,
100+
flowData,
98101
};
99102
mainWindow.webContents.send('main:update-flowtest', file, collectionId);
100103
} else if (this.isEnvFile(pathname, watchPath)) {

src/stores/CollectionStore.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ const useCollectionStore = create((set, get) => ({
117117

118118
// check if there are any open tabs, if yes mark them saved
119119
const tab = useTabStore.getState().tabs.find((t) => t.id === existingEnv.id);
120-
if (tab && tab.variablesDraft) {
121-
tab.variables = cloneDeep(tab.variablesDraft);
120+
if (tab) {
121+
tab.variables = cloneDeep(file.variables);
122122
tab.variablesDraft = null;
123123
}
124124
} else {
@@ -286,9 +286,9 @@ const useCollectionStore = create((set, get) => ({
286286
// console.log(`Collection updated: ${JSON.stringify(collection)}`);
287287

288288
// check if there are any open tabs, if yes mark them saved
289-
const tab = useTabStore.getState().tabs.find((t) => t.id === item.id);
290-
if (tab && tab.flowDataDraft) {
291-
useTabStore.getState().saveFlowTestTab(tab);
289+
const existingTab = useTabStore.getState().tabs.find((t) => t.id === item.id);
290+
if (existingTab) {
291+
useTabStore.getState().saveFlowTestTab(existingTab, cloneDeep(file.flowData));
292292
}
293293
}
294294
}

src/stores/TabStore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const useTabStore = create((set, get) => ({
3333
set((state) => ({ tabs: [...state.tabs, newTab] }));
3434
set(() => ({ focusTabId: newTab.id }));
3535
},
36-
saveFlowTestTab: (tab) => {
36+
saveFlowTestTab: (tab, updatedFlowData) => {
3737
set(
3838
produce((state) => {
3939
const existingTab = state.tabs.find(
@@ -45,7 +45,7 @@ export const useTabStore = create((set, get) => ({
4545
tab.type === OBJ_TYPES.flowtest,
4646
);
4747
if (existingTab) {
48-
existingTab.flowData = cloneDeep(existingTab.flowDataDraft);
48+
existingTab.flowData = updatedFlowData;
4949
existingTab.flowDataDraft = null;
5050
}
5151
}),

0 commit comments

Comments
 (0)