File tree Expand file tree Collapse file tree
components/molecules/environment Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ const Env = ({ tab }) => {
3333 } ) ;
3434
3535 return (
36- < div className = 'p-4' >
36+ < div className = 'p-4' key = { tab . id } >
3737 < table className = 'w-full leading-normal' >
3838 < thead >
3939 < tr className = 'bg-ghost-50 text-ghost-600 text-left text-xs font-bold uppercase tracking-wider' >
Original file line number Diff line number Diff line change @@ -8,12 +8,12 @@ const useEnvStore = create((set, get) => ({
88 } ,
99 handleAddVariable : ( key , value ) => {
1010 set ( ( state ) => ( { variables : { ...state . variables , [ key ] : value } } ) ) ;
11- useTabStore . getState ( ) . updateEnvTab ( get ( ) . variables ) ;
11+ useTabStore . getState ( ) . updateEnvTab ( useTabStore . getState ( ) . focusTabId , get ( ) . variables ) ;
1212 } ,
1313 handleDeleteVariable : ( key ) => {
1414 const { [ key ] : _ , ...newVariables } = get ( ) . variables ;
1515 set ( { variables : newVariables } ) ;
16- useTabStore . getState ( ) . updateEnvTab ( get ( ) . variables ) ;
16+ useTabStore . getState ( ) . updateEnvTab ( useTabStore . getState ( ) . focusTabId , get ( ) . variables ) ;
1717 } ,
1818} ) ) ;
1919
Original file line number Diff line number Diff line change @@ -142,18 +142,20 @@ export const useTabStore = create((set, get) => ({
142142 set ( ( state ) => ( { tabs : [ ...state . tabs , newTab ] } ) ) ;
143143 set ( ( ) => ( { focusTabId : newTab . id } ) ) ;
144144 } ,
145- // these state changes are meant to be triggered by env tab in focus
146- updateEnvTab : ( variables ) => {
147- if ( get ( ) . focusTabId ) {
148- const existingTab = get ( ) . tabs . find ( ( t ) => t . id === get ( ) . focusTabId ) ;
149- if ( existingTab ) {
150- if ( ! existingTab . variablesDraft ) {
151- existingTab . variablesDraft = cloneDeep ( existingTab . variables ) ;
145+ updateEnvTab : ( tabId , variables ) => {
146+ set (
147+ produce ( ( state ) => {
148+ if ( tabId ) {
149+ const existingTab = state . tabs . find ( ( t ) => t . id === tabId ) ;
150+ if ( existingTab ) {
151+ if ( ! existingTab . variablesDraft ) {
152+ existingTab . variablesDraft = cloneDeep ( existingTab . variables ) ;
153+ }
154+ existingTab . variablesDraft = variables ;
155+ }
152156 }
153- existingTab . variablesDraft = variables ;
154- }
155- console . log ( existingTab ) ;
156- }
157+ } ) ,
158+ ) ;
157159 } ,
158160 closeTab : ( id , collectionId ) => {
159161 set ( ( state ) => ( { tabs : state . tabs . filter ( ( t ) => t . id !== id ) } ) ) ;
You can’t perform that action at this time.
0 commit comments