Skip to content

Commit 1f31d24

Browse files
committed
update environment tab via zustand state store
1 parent 03238f4 commit 1f31d24

3 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/components/molecules/environment/index.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,36 @@ const Env = ({ tab }) => {
3434

3535
return (
3636
<div className='p-4' key={tab.id}>
37-
<table className='w-full leading-normal'>
37+
<table className='w-full table-fixed leading-normal'>
3838
<thead>
3939
<tr className='bg-ghost-50 text-ghost-600 text-left text-xs font-bold uppercase tracking-wider'>
40-
<th className='border-ghost-200 max-w-4 border p-5'>S. No.</th>
41-
<th className='border-ghost-200 border p-5 '>Key</th>
42-
<th className='border-ghost-200 border p-5'>Value</th>
43-
<th className='border-ghost-200 max-w-4 border p-5'>Action</th>
40+
<th className='border-ghost-200 border p-5' style={{ width: '50px' }}>
41+
S. No.
42+
</th>
43+
<th className='border-ghost-200 border p-5' style={{ width: '100px' }}>
44+
Key
45+
</th>
46+
<th className='border-ghost-200 border p-5' style={{ width: '200px' }}>
47+
Value
48+
</th>
49+
<th className='border-ghost-200 border p-5' style={{ width: '50px' }}>
50+
Action
51+
</th>
4452
</tr>
4553
</thead>
4654
<tbody>
4755
{Object.entries(variables).map(([key, value], index) => (
4856
<tr key={index} className='text-ghost-700 hover:bg-ghost-50 border-b border-gray-200 text-sm'>
49-
<td className='whitespace-no-wrap max-w-4 p-5'>{index + 1}</td>
50-
<td className='whitespace-no-wrap p-5'>{key}</td>
51-
<td className='whitespace-no-wrap p-5'>{value}</td>
52-
<td className='whitespace-no-wrap max-w-4 p-5'>
57+
<td className='whitespace-no-wrap p-5' style={{ width: '50px' }}>
58+
{index + 1}
59+
</td>
60+
<td className='whitespace-no-wrap truncate p-5' style={{ width: '100px' }}>
61+
{key}
62+
</td>
63+
<td className='whitespace-no-wrap truncate p-5' style={{ width: '200px' }}>
64+
{value}
65+
</td>
66+
<td className='whitespace-no-wrap p-5' style={{ width: '50px' }}>
5367
<div
5468
className='hover:bg-ghost-200 relative inline-block cursor-pointer rounded-md p-2 text-left transition duration-200 ease-out'
5569
onClick={() => {

src/stores/CollectionStore.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ const useCollectionStore = create((set, get) => ({
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);
120120
if (tab) {
121-
tab.variables = cloneDeep(file.variables);
122-
tab.variablesDraft = null;
121+
useTabStore.getState().saveEnvTab(tab, cloneDeep(file.variables));
123122
}
124123
} else {
125124
const timestamp = Date.now();

src/stores/TabStore.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ export const useTabStore = create((set, get) => ({
157157
}),
158158
);
159159
},
160+
saveEnvTab: (tab, variables) => {
161+
set(
162+
produce((state) => {
163+
const existingTab = state.tabs.find(
164+
(t) => t.id === tab.id && t.name === tab.name && t.type === OBJ_TYPES.environment,
165+
);
166+
if (existingTab) {
167+
existingTab.variables = variables;
168+
existingTab.variablesDraft = null;
169+
}
170+
}),
171+
);
172+
},
160173
closeTab: (id, collectionId) => {
161174
set((state) => ({ tabs: state.tabs.filter((t) => t.id !== id) }));
162175
if (get().focusTabId === id) {

0 commit comments

Comments
 (0)