Skip to content

Commit cd04440

Browse files
committed
select all modules
1 parent 723ad66 commit cd04440

File tree

3 files changed

+94
-39
lines changed

3 files changed

+94
-39
lines changed

cyclops-ui/src/components/pages/Modules/Modules.tsx

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,27 @@ const Modules = () => {
5151
description: "",
5252
});
5353

54-
const [checkedModules, setCheckedModules] = useState<string[]>([]);
54+
const [checkedModules, setCheckedModules] = useState<Set<string>>(new Set());
55+
56+
const handleModuleSelect = (moduleName: string, checked: boolean) => {
57+
setCheckedModules((prev) => {
58+
const updatedSet = new Set(prev);
59+
if (checked) {
60+
updatedSet.add(moduleName);
61+
} else {
62+
updatedSet.delete(moduleName);
63+
}
64+
return updatedSet;
65+
});
66+
};
5567

56-
const handleCheckboxChange = (moduleName: string, checked: boolean) => {
57-
setCheckedModules((prev) =>
58-
checked
59-
? [...prev, moduleName]
60-
: prev.filter((name) => name !== moduleName),
61-
);
68+
const handleSelectAllModules = (checked: boolean) => {
69+
if (!checked) {
70+
setCheckedModules(new Set());
71+
return;
72+
}
73+
74+
setCheckedModules(new Set(filteredData.map((module: any) => module.name)));
6275
};
6376

6477
useEffect(() => {
@@ -120,14 +133,16 @@ const Modules = () => {
120133

121134
const handleBatchReconcile = () => {
122135
axios
123-
.post(`/api/modules/reconcile`, { modules: checkedModules })
136+
.post(`/api/modules/reconcile`, {
137+
modules: checkedModules.keys().toArray(),
138+
})
124139
.then(() => {
125140
notification.success({
126141
message: "Reconciliation triggered",
127142
description: `Modules have been queued for reconciliation.`,
128143
duration: 10,
129144
});
130-
setCheckedModules([]);
145+
setCheckedModules(new Set());
131146
})
132147
.catch((error) => {
133148
setError(mapResponseError(error));
@@ -261,6 +276,16 @@ const Modules = () => {
261276
<Col key={index} xs={24} sm={12} md={8} lg={8} xl={6}>
262277
<a href={"/modules/" + module.name}>
263278
<Card
279+
styles={{
280+
header: {
281+
borderRadius: "4px 7px 0 0",
282+
backgroundColor: checkedModules.has(module.name)
283+
? mode === "light"
284+
? "#fcd8ae"
285+
: "#5e3301"
286+
: "",
287+
},
288+
}}
264289
title={
265290
<div
266291
style={{
@@ -280,9 +305,9 @@ const Modules = () => {
280305
{module.name}
281306
</div>
282307
<Checkbox
283-
checked={checkedModules.includes(module.name)}
308+
checked={checkedModules.has(module.name)}
284309
onChange={(e) =>
285-
handleCheckboxChange(module.name, e.target.checked)
310+
handleModuleSelect(module.name, e.target.checked)
286311
}
287312
/>
288313
</div>
@@ -422,35 +447,40 @@ const Modules = () => {
422447
/>
423448
)}
424449

425-
<Row gutter={[20, 0]}>
426-
<Col span={14}>
427-
<Title level={2}>Deployed modules</Title>
428-
</Col>
429-
<Col span={4}>
430-
<Button
431-
onClick={handleBatchReconcile}
432-
disabled={checkedModules.length === 0}
433-
block
434-
style={{
435-
fontWeight: "600",
436-
}}
437-
>
438-
<PlusCircleOutlined />
439-
Reconcile
440-
</Button>
450+
<Row gutter={[20, 0]} align="middle" justify="space-between">
451+
<Col>
452+
<Title level={3}>Deployed modules</Title>
441453
</Col>
442-
<Col span={6}>
443-
<Button
444-
type={"primary"}
445-
onClick={handleClick}
446-
block
447-
style={{
448-
fontWeight: "600",
449-
}}
450-
>
451-
<PlusCircleOutlined />
452-
Add module
453-
</Button>
454+
<Col>
455+
<Row gutter={[10, 0]} align="middle">
456+
<Col>
457+
<Checkbox
458+
onChange={(e) => handleSelectAllModules(e.target.checked)}
459+
>
460+
Select all modules
461+
</Checkbox>
462+
</Col>
463+
<Col>
464+
<Button
465+
onClick={handleBatchReconcile}
466+
disabled={checkedModules.size === 0}
467+
style={{ fontWeight: "600" }}
468+
block
469+
>
470+
<PlusCircleOutlined /> Reconcile
471+
</Button>
472+
</Col>
473+
<Col>
474+
<Button
475+
type="primary"
476+
onClick={handleClick}
477+
style={{ fontWeight: "600", width: "240px" }}
478+
block
479+
>
480+
<PlusCircleOutlined /> Add module
481+
</Button>
482+
</Col>
483+
</Row>
454484
</Col>
455485
</Row>
456486

cyclops-ui/src/components/shared/CreateModule/CreateModule.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface CreateModuleProps {
8080
moduleNamespace: string,
8181
templateRef: any,
8282
values: string,
83+
lockTemplateVersion?: boolean,
8384
gitOpsWrite?: any,
8485
) => Promise<any>;
8586
onSubmitModuleSuccess: (moduleName: string) => void;
@@ -188,6 +189,7 @@ export const CreateModuleComponent = ({
188189

189190
const moduleName = values["cyclops_module_name"];
190191
const moduleNamespace = values["cyclops_module_namespace"];
192+
const lockTemplateVersion = values["cyclops_module_lock_version"];
191193

192194
values = findMaps(config.root.properties, values, {});
193195

@@ -201,6 +203,7 @@ export const CreateModuleComponent = ({
201203
sourceType: template.ref.sourceType,
202204
},
203205
values,
206+
lockTemplateVersion,
204207
resolveGitOpsWrite(values),
205208
)
206209
.then(() => {
@@ -560,6 +563,26 @@ export const CreateModuleComponent = ({
560563
<Divider
561564
style={{ marginTop: "12px", marginBottom: "12px" }}
562565
/>
566+
<Form.Item
567+
name="cyclops_module_lock_version"
568+
id="cyclops_module_lock_version"
569+
label={
570+
<div>
571+
Lock template version
572+
<p style={{ color: "#8b8e91", marginBottom: "0px" }}>
573+
If toggled, this Module will not automatically
574+
follow the latest version of the template selected
575+
and you will have to bump the template version while
576+
editing the module.
577+
</p>
578+
</div>
579+
}
580+
style={{ padding: "0px 12px 0px 12px" }}
581+
hasFeedback={true}
582+
validateDebounce={1000}
583+
>
584+
<Switch />
585+
</Form.Item>
563586
<Form.Item
564587
name="cyclops_module_namespace"
565588
id="cyclops_module_namespace"

cyclops-ui/src/utils/api/api.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export async function createModule(
7474
moduleNamespace: string,
7575
templateRef: any,
7676
values: any,
77+
lockTemplateVersion?: boolean,
7778
gitOpsWrite?: any,
7879
) {
7980
return await axios.post(`/api/modules/new`, {
@@ -87,6 +88,7 @@ export async function createModule(
8788
version: templateRef.version,
8889
sourceType: templateRef.sourceType,
8990
},
91+
lockTemplateVersion: lockTemplateVersion,
9092
});
9193
}
9294

0 commit comments

Comments
 (0)