@@ -2,6 +2,8 @@ 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' ;
6+ import { OBJ_TYPES } from 'constants/Common' ;
57
68const Tabs = ( ) => {
79 const tabs = useTabStore ( ( state ) => state . tabs ) ;
@@ -12,32 +14,41 @@ const Tabs = () => {
1214 const closeTab = useTabStore ( ( state ) => state . closeTab ) ;
1315 const [ closingTabId , setClosingTabId ] = useState ( '' ) ;
1416 const [ closingCollectionId , setClosingCollectionId ] = useState ( '' ) ;
17+
1518 const activeTabStyles =
1619 'before:absolute before:h-[0.25rem] before:w-full before:bg-slate-300 before:content-[""] before:bottom-0 before:left-0' ;
1720 const tabCommonStyles =
18- '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' ;
19- const messageForConfirmActionModal = 'You have unsaved changes in the flowtest, are you sure you want to close it?' ;
20- const handleCloseTab = ( event ) => {
21+ '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 flex-nowrap' ;
22+ const messageForConfirmActionModal = `You have unsaved changes in the ${ focusTab ?. type } , are you sure you want to close it?` ;
23+
24+ const handleCloseTab = ( event , tab ) => {
2125 event . stopPropagation ( ) ;
2226 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 ) ;
2927
30- if ( isDirty ) {
31- console . debug ( `Confirm close for tabId: ${ tabId } : collectionId: ${ collectionId } ` ) ;
32- setConfirmActionModalOpen ( true ) ;
33- return ;
28+ setClosingTabId ( tab . id ) ;
29+ setClosingCollectionId ( tab . collectionId ) ;
30+
31+ if ( tab . type === OBJ_TYPES . flowtest ) {
32+ if ( tab . flowDataDraft && ! isEqual ( tab . flowData , tab . flowDataDraft ) ) {
33+ console . debug ( `Confirm close for tabId: ${ tab . id } : collectionId: ${ tab . collectionId } ` ) ;
34+ setConfirmActionModalOpen ( true ) ;
35+ return ;
36+ }
37+ } else if ( tab . type === OBJ_TYPES . environment ) {
38+ if ( tab . variablesDraft && ! isEqual ( tab . variables , tab . variablesDraft ) ) {
39+ console . debug ( `Confirm close for tabId: ${ tab . id } : collectionId: ${ tab . collectionId } ` ) ;
40+ setConfirmActionModalOpen ( true ) ;
41+ return ;
42+ }
3443 }
35- closeTab ( tabId , collectionId ) ;
44+ closeTab ( tab . id , tab . collectionId ) ;
3645 } ;
46+
3747 return (
38- < div role = 'tablist' className = 'tabs tabs-lg' >
48+ < div role = 'tablist' className = 'overflow-scroll tabs tabs-lg' >
3949 { tabs
4050 // tabs belonging to one collection will be shown at a time
51+ //.reverse()
4152 . filter ( ( t ) => t . collectionId === focusTab . collectionId )
4253 . map ( ( tab , index ) => {
4354 return (
@@ -52,12 +63,12 @@ const Tabs = () => {
5263 data-id = { tab . id }
5364 data-collection-id = { tab . collectionId }
5465 >
55- < a > { tab . name } </ a >
66+ < a className = 'text-nowrap' > { tab . name } </ a >
5667 { /* close needs to be a separate clickable component other wise it gets confused with above */ }
5768 < div
5869 className = 'flex items-center h-full px-2 hover:rounded hover:rounded-l-none hover:bg-slate-200'
5970 data-tab-id = { tab . id }
60- onClick = { handleCloseTab }
71+ onClick = { ( e ) => handleCloseTab ( e , tab ) }
6172 >
6273 < XMarkIcon className = 'w-4 h-4' />
6374 </ div >
0 commit comments