@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22import { XMarkIcon } from '@heroicons/react/24/outline' ;
33import { useTabStore } from 'stores/TabStore' ;
44import ConfirmActionModal from 'components/molecules/modals/ConfirmActionModal' ;
5+ import { isEqual } from 'lodash' ;
56
67const 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 ) ;
0 commit comments