Skip to content

Commit bb8ee60

Browse files
Refactor Open Environment variables user flow, Also remove unused import and fix formatting in EnvironmentSidebar component
1 parent 58669f8 commit bb8ee60

File tree

1 file changed

+27
-52
lines changed

1 file changed

+27
-52
lines changed

platform/firecamp-platform/src/components/common/environment/sidebar/EnvironmentSidebar.tsx

+27-52
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FC, useEffect, useRef } from 'react';
22
import { shallow } from 'zustand/shallow';
33
import { Braces, Plus } from 'lucide-react';
44
import { Tree, UncontrolledTreeEnvironment } from '@firecamp/ui/src/tree';
5-
import { Notes, Button } from '@firecamp/ui';
5+
import { Notes } from '@firecamp/ui';
66
import { EEnvironmentScope } from '@firecamp/types';
77
import { Container, ProgressBar, Pane, ToolBar } from '@firecamp/ui';
88
import treeRenderer from './tree/itemRenderer';
@@ -30,7 +30,7 @@ export default EnvironmentSidebar;
3030
const ProgressBarContainer = () => {
3131
const { isProgressing } = useEnvStore(
3232
(s) => ({
33-
isProgressing: s.isProgressing,
33+
isProgressing: s.isProgressing
3434
}),
3535
shallow
3636
);
@@ -40,13 +40,11 @@ const ProgressBarContainer = () => {
4040
const EnvironmentCollection = () => {
4141
const treeRef = useRef();
4242
const { open: openTab } = useTabStore.getState();
43-
const { envTdpInstance, registerTDP, unRegisterTDP } = useEnvStore(
44-
(s: IEnvironmentStore) => ({
45-
envTdpInstance: s.envTdpInstance,
46-
registerTDP: s.registerTDP_,
47-
unRegisterTDP: s.unRegisterTDP_,
48-
})
49-
);
43+
const { envTdpInstance, registerTDP, unRegisterTDP } = useEnvStore((s: IEnvironmentStore) => ({
44+
envTdpInstance: s.envTdpInstance,
45+
registerTDP: s.registerTDP_,
46+
unRegisterTDP: s.unRegisterTDP_
47+
}));
5048
const { createEnvironmentPrompt } = platformContext.platform;
5149
useEffect(() => {
5250
registerTDP();
@@ -55,8 +53,8 @@ const EnvironmentCollection = () => {
5553
const openEnv = (env) => {
5654
openTab(env, { id: env.__ref.id, type: ETabEntityTypes.Environment });
5755
};
58-
const openCreateColEnv = () => { };
59-
const deleteEnv = () => { };
56+
const openCreateColEnv = () => {};
57+
const deleteEnv = () => {};
6058

6159
if (!envTdpInstance) return <></>;
6260
return (
@@ -94,16 +92,11 @@ const EnvironmentCollection = () => {
9492
...props,
9593
openEnv: openEnv,
9694
openCreateEnv: openCreateColEnv,
97-
deleteEnv,
95+
deleteEnv
9896
})
9997
}
10098
>
101-
<Tree
102-
treeId="tree-1"
103-
rootItem="root"
104-
treeLabel="Tree Example"
105-
ref={treeRef}
106-
/>
99+
<Tree treeId="tree-1" rootItem="root" treeLabel="Tree Example" ref={treeRef} />
107100
</UncontrolledTreeEnvironment>
108101
</div>
109102
);
@@ -114,13 +107,14 @@ const EnvironmentCollection = () => {
114107

115108
const CollectionScopedEnvCollection = () => {
116109
const treeRef = useRef();
117-
const { envTdpInstance, registerTDP, unRegisterTDP, deleteEnvironment } =
118-
useEnvStore((s: IEnvironmentStore) => ({
110+
const { envTdpInstance, registerTDP, unRegisterTDP, deleteEnvironment } = useEnvStore(
111+
(s: IEnvironmentStore) => ({
119112
envTdpInstance: s.colEnvTdpInstance,
120113
registerTDP: s.registerTDP,
121114
unRegisterTDP: s.unRegisterTDP,
122-
deleteEnvironment: s.deleteEnvironment,
123-
}));
115+
deleteEnvironment: s.deleteEnvironment
116+
})
117+
);
124118
useEffect(() => {
125119
registerTDP();
126120
return () => unRegisterTDP();
@@ -130,27 +124,25 @@ const CollectionScopedEnvCollection = () => {
130124
platformContext.app.modals.openCloneEnvironment({
131125
scope: EEnvironmentScope.Collection,
132126
collectionId: colId,
133-
envId,
127+
envId
134128
});
135129
};
136130

137-
const openCreateColEnv = () => { };
131+
const openCreateColEnv = () => {};
138132

139133
const deleteEnv = (envId: string) => {
140134
platformContext.window
141135
.confirm({
142136
message: 'Are you sure to delete the environment?',
143-
labels: { confirm: 'Yes, delete it.' },
137+
labels: { confirm: 'Yes, delete it.' }
144138
})
145139
.then(() => {
146140
deleteEnvironment(envId)
147141
.then((r) => {
148142
return r;
149143
})
150144
.catch((e) => {
151-
platformContext.app.notify.alert(
152-
e.response?.data?.message || e.message
153-
);
145+
platformContext.app.notify.alert(e.response?.data?.message || e.message);
154146
});
155147
});
156148
};
@@ -195,16 +187,11 @@ const CollectionScopedEnvCollection = () => {
195187
...props,
196188
openEnv: openColEnv,
197189
openCreateEnv: openCreateColEnv,
198-
deleteEnv,
190+
deleteEnv
199191
})
200192
}
201193
>
202-
<Tree
203-
treeId="tree-1"
204-
rootItem="root"
205-
treeLabel="Tree Example"
206-
ref={treeRef}
207-
/>
194+
<Tree treeId="tree-1" rootItem="root" treeLabel="Tree Example" ref={treeRef} />
208195
</UncontrolledTreeEnvironment>
209196
</>
210197
);
@@ -217,31 +204,19 @@ const Globals = () => {
217204
const globalEnv = useEnvStore((s) => s.globalEnv, shallow);
218205
const { open: openTab } = useTabStore.getState();
219206
const openEnv = (env) => {
220-
openTab(
221-
{ ...env },
222-
{ id: env.__ref.id, type: ETabEntityTypes.Environment }
223-
);
207+
openTab({ ...env }, { id: env.__ref.id, type: ETabEntityTypes.Environment });
224208
};
225209

226210
return (
227211
<div className="rct-tree-item-li focus:rct-tree-item-li-focused border-b border-app-border">
228-
<div className="px-2 mt-5 mb-1 rct-tree-item-title-container focus:rct-tree-item-title-container-focused hover:rct-tree-item-title-container-focused !opacity-100 cursor-pointer">
212+
<div
213+
className="px-2 mt-5 mb-1 rct-tree-item-title-container focus:rct-tree-item-title-container-focused hover:rct-tree-item-title-container-focused !opacity-100 cursor-pointer"
214+
onClick={() => openEnv(globalEnv)}
215+
>
229216
<Braces className="flex-none my-0.5" size={18} opacity={1} />
230217
<span className="w-full overflow-hidden text-ellipsis items-center block pl-1 text-base">
231218
{globalEnv?.name}
232219
</span>
233-
<div className="flex ml-auto rct-tree-item-li-action items-center">
234-
<Button
235-
text={'Open'}
236-
onClick={() => openEnv(globalEnv)}
237-
classNames={{
238-
root: 'hover:!bg-focusColor !text-app-foreground-inactive'
239-
}}
240-
ghost
241-
compact
242-
xs
243-
/>
244-
</div>
245220
</div>
246221
</div>
247222
);

0 commit comments

Comments
 (0)