Skip to content

Commit 1778ecd

Browse files
committed
rely on flowdata draft for save
1 parent f7eadc5 commit 1778ecd

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

src/components/atoms/Tabs.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22
import { XMarkIcon } from '@heroicons/react/24/outline';
33
import { useTabStore } from 'stores/TabStore';
44
import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal';
5+
import { isEqual } from 'lodash';
56

67
const Tabs = () => {
78
const tabs = useTabStore((state) => state.tabs);
@@ -12,28 +13,31 @@ const Tabs = () => {
1213
const closeTab = useTabStore((state) => state.closeTab);
1314
const [closingTabId, setClosingTabId] = useState('');
1415
const [closingCollectionId, setClosingCollectionId] = useState('');
16+
1517
const activeTabStyles =
1618
'before:absolute before:h-[0.25rem] before:w-full before:bg-slate-300 before:content-[""] before:bottom-0 before:left-0';
1719
const tabCommonStyles =
1820
'tab flex items-center gap-x-2 border-r border-neutral-300 bg-transparent pr-0 tracking-[0.15em] transition duration-500 ease-in text-sm';
1921
const messageForConfirmActionModal = 'You have unsaved changes in the flowtest, are you sure you want to close it?';
20-
const handleCloseTab = (event) => {
22+
23+
const handleCloseTab = (event, tab) => {
2124
event.stopPropagation();
2225
event.preventDefault();
23-
const tabId = event.currentTarget.dataset.tabId;
24-
const { isDirty, collectionId } = tabs.find((tab) => {
25-
if (tab.id === tabId) return tab;
26-
});
27-
setClosingTabId(tabId);
28-
setClosingCollectionId(collectionId);
26+
// const tabId = event.currentTarget.dataset.tabId;
27+
// const { isDirty, collectionId } = tabs.find((tab) => {
28+
// if (tab.id === tabId) return tab;
29+
// });
30+
setClosingTabId(tab.id);
31+
setClosingCollectionId(tab.collectionId);
2932

30-
if (isDirty) {
31-
console.debug(`Confirm close for tabId: ${tabId} : collectionId: ${collectionId}`);
33+
if (tab.flowDataDraft && !isEqual(tab.flowData, tab.flowDataDraft)) {
34+
console.debug(`Confirm close for tabId: ${tab.id} : collectionId: ${tab.collectionId}`);
3235
setConfirmActionModalOpen(true);
3336
return;
3437
}
35-
closeTab(tabId, collectionId);
38+
closeTab(tab.id, tab.collectionId);
3639
};
40+
3741
return (
3842
<div role='tablist' className='tabs tabs-lg'>
3943
{tabs
@@ -55,11 +59,11 @@ const Tabs = () => {
5559
<a>{tab.name}</a>
5660
{/* close needs to be a separate clickable component other wise it gets confused with above */}
5761
<div
58-
className='flex items-center h-full px-2 hover:rounded hover:rounded-l-none hover:bg-slate-200'
62+
className='flex h-full items-center px-2 hover:rounded hover:rounded-l-none hover:bg-slate-200'
5963
data-tab-id={tab.id}
60-
onClick={handleCloseTab}
64+
onClick={(e) => handleCloseTab(e, tab)}
6165
>
62-
<XMarkIcon className='w-4 h-4' />
66+
<XMarkIcon className='h-4 w-4' />
6367
</div>
6468
</div>
6569
);

src/components/molecules/modals/SaveFlowModal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const SaveFlowModal = ({ tab }) => {
1515
}
1616

1717
function saveHandle() {
18-
updateFlowTest(tab.pathname, tab.flowData, tab.collectionId)
18+
updateFlowTest(tab.pathname, tab.flowDataDraft, tab.collectionId)
1919
.then((result) => {
2020
console.log(`Updated flowtest: path = ${tab.pathname}, collectionId = ${tab.collectionId}, result: ${result}`);
2121
toast.success(`Updated the flowtest: ${tab.pathname}`);

src/stores/CollectionStore.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import { useEventStore } from './EventListenerStore.js';
1111
import { useTabStore } from './TabStore.js';
1212
import { OBJ_TYPES } from 'constants/Common.js';
13+
import { cloneDeep } from 'lodash';
1314

1415
const useCollectionStore = create((set, get) => ({
1516
collections: [],
@@ -269,8 +270,9 @@ const useCollectionStore = create((set, get) => ({
269270

270271
// check if there are any open tabs, if yes mark them saved
271272
const tab = useTabStore.getState().tabs.find((t) => t.id === item.id);
272-
if (tab) {
273-
tab.isDirty = false;
273+
if (tab && tab.flowDataDraft) {
274+
tab.flowData = cloneDeep(tab.flowDataDraft);
275+
tab.flowDataDraft = null;
274276
}
275277
}
276278
}

src/stores/tabstore.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('Tab store', () => {
4242
expect(tabs[0].type).toEqual('flowtest');
4343
expect(tabs[0].name).toEqual(flowtest.name);
4444
expect(tabs[0].pathname).toEqual(flowtest.pathname);
45-
expect(tabs[0].isDirty).toEqual(false);
4645
expect(tabs[0].flowData).toEqual(undefined);
4746
expect(result.current.focusTabId).toEqual(flowtest.id);
4847

0 commit comments

Comments
 (0)