Skip to content

Commit 5e71b7d

Browse files
cannarelladevkingmakerbot
authored andcommitted
Frontend: New deletion modals, some UI and Logic bugfix
Co-authored-by: Francesco Cheinasso <cheinasso.francesco@gmail.com>
1 parent 2cffb2c commit 5e71b7d

File tree

18 files changed

+336
-245
lines changed

18 files changed

+336
-245
lines changed

frontend/src/components/activePage/ActiveView/ActiveView.tsx

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { DeleteOutlined } from '@ant-design/icons';
21
import { Col, Space } from 'antd';
3-
import Button from 'antd-button-color';
42
import { FC, useEffect, useState } from 'react';
5-
import { User, WorkspaceRole } from '../../../utils';
3+
import { User, Workspace, WorkspaceRole } from '../../../utils';
64
import { SessionValue, StorageKeys } from '../../../utilsStorage';
75
import Box from '../../common/Box';
8-
import { ModalAlert } from '../../common/ModalAlert';
6+
import ModalGroupDeletion from '../ModalGroupDeletion/ModalGroupDeletion';
97
import TableInstanceLogic from '../TableInstance/TableInstanceLogic';
108
import TableWorkspaceLogic from '../TableWorkspaceLogic/TableWorkspaceLogic';
119
import Toolbox from '../Toolbox/Toolbox';
@@ -16,12 +14,7 @@ const advanced = new SessionValue(StorageKeys.Active_Headers, 'true');
1614

1715
export interface IActiveViewProps {
1816
user: User;
19-
workspaces: Array<{
20-
prettyName: string;
21-
role: WorkspaceRole;
22-
namespace: string;
23-
id: string;
24-
}>;
17+
workspaces: Array<Workspace>;
2518
managerView: boolean;
2619
}
2720

@@ -40,6 +33,7 @@ const ActiveView: FC<IActiveViewProps> = ({ ...props }) => {
4033
);
4134
const [showCheckbox, setShowCheckbox] = useState(false);
4235
const [selectiveDestroy, setSelectiveDestroy] = useState<string[]>([]);
36+
const [selectedPersistent, setSelectedPersistent] = useState<boolean>(false);
4337

4438
const selectToDestroy = (instanceId: string) => {
4539
selectiveDestroy.includes(instanceId)
@@ -70,28 +64,14 @@ const ActiveView: FC<IActiveViewProps> = ({ ...props }) => {
7064

7165
return (
7266
<Col span={24} lg={22} xxl={20}>
73-
<ModalAlert
74-
headTitle="Destroy Selected"
67+
<ModalGroupDeletion
68+
view={WorkspaceRole.manager}
69+
persistent={selectedPersistent}
70+
selective={true}
71+
instanceList={selectiveDestroy}
7572
show={showAlert}
76-
message="ATTENTION"
77-
description={`Are you sure do you want to destroy the ${selectiveDestroy.length} selected instances. This operation is dangerous and irreversible!`}
78-
type="error"
79-
buttons={[
80-
<Button
81-
type="danger"
82-
shape="round"
83-
size="middle"
84-
icon={<DeleteOutlined />}
85-
className="border-0"
86-
onClick={() => {
87-
setDestroySelectedTrigger(true);
88-
setShowAlert(false);
89-
}}
90-
>
91-
Destroy Selected
92-
</Button>,
93-
]}
9473
setShow={setShowAlert}
74+
destroy={() => setDestroySelectedTrigger(true)}
9575
/>
9676
<Box
9777
header={{
@@ -149,6 +129,7 @@ const ActiveView: FC<IActiveViewProps> = ({ ...props }) => {
149129
setDestroySelectedTrigger={setDestroySelectedTrigger}
150130
selectiveDestroy={selectiveDestroy}
151131
selectToDestroy={selectToDestroy}
132+
setSelectedPersistent={setSelectedPersistent}
152133
/>
153134
</div>
154135
) : (

frontend/src/components/activePage/ActiveViewLogic/ActiveViewLogic.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Spin } from 'antd';
33
import ActiveView from '../ActiveView/ActiveView';
44
import { WorkspaceRole } from '../../../utils';
55
import { TenantContext } from '../../../graphql-components/tenantContext/TenantContext';
6+
import { makeWorkspace } from '../../../utilsLogic';
67

78
const ActiveViewLogic: FC<{}> = ({ ...props }) => {
89
const {
@@ -12,17 +13,7 @@ const ActiveViewLogic: FC<{}> = ({ ...props }) => {
1213
} = useContext(TenantContext);
1314

1415
const workspaces =
15-
tenantData?.tenant?.spec?.workspaces?.map(workspace => {
16-
const { workspaceWrapperTenantV1alpha2, name, role } = workspace!;
17-
const { spec, status } =
18-
workspaceWrapperTenantV1alpha2?.itPolitoCrownlabsV1alpha1Workspace!;
19-
return {
20-
prettyName: spec?.prettyName as string,
21-
role: WorkspaceRole[role!],
22-
namespace: status?.namespace?.name!,
23-
id: name!,
24-
};
25-
}) || [];
16+
tenantData?.tenant?.spec?.workspaces?.map(makeWorkspace) || [];
2617

2718
const managerWorkspaces = workspaces?.filter(
2819
ws => ws.role === WorkspaceRole.manager
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { DeleteOutlined } from '@ant-design/icons';
2+
import { Divider } from 'antd';
3+
import Button from 'antd-button-color';
4+
import { Dispatch, FC, SetStateAction, useState } from 'react';
5+
import { ReactComponent as SvgInfinite } from '../../../assets/infinite.svg';
6+
import { WorkspaceRole } from '../../../utils';
7+
import { ModalAlert } from '../../common/ModalAlert';
8+
9+
export interface IModalGroupDeletionProps {
10+
view: WorkspaceRole;
11+
persistent: boolean;
12+
selective: boolean;
13+
groupName?: string;
14+
instanceList: Array<string>;
15+
show: boolean;
16+
setShow: Dispatch<SetStateAction<boolean>>;
17+
destroy: () => void;
18+
}
19+
20+
const ModalGroupDeletion: FC<IModalGroupDeletionProps> = ({ ...props }) => {
21+
const {
22+
view,
23+
persistent,
24+
selective,
25+
groupName,
26+
instanceList,
27+
show,
28+
setShow,
29+
destroy,
30+
} = props;
31+
const [confirmDeletion, setConfirmDeletion] = useState(false);
32+
33+
const title = selective ? 'Destroy Selected' : 'Destroy All';
34+
const message = <b>ATTENTION</b>;
35+
const description = (
36+
<>
37+
<div>
38+
Are you sure that you want to destroy
39+
{selective ? (
40+
<>{` the ${instanceList.length} selected instances`}</>
41+
) : groupName ? (
42+
<>
43+
{' all instances of '}
44+
<b>
45+
<i>{groupName}</i>
46+
</b>
47+
</>
48+
) : (
49+
' all instances'
50+
)}
51+
? <br />
52+
This operation is <u>dangerous and irreversible</u>!
53+
</div>
54+
55+
{persistent ? (
56+
<div className="text-center text-xs">
57+
<Divider type="horizontal" className="my-3" />
58+
<div className="flex items-end">
59+
<i>
60+
(Seems you are also trying to destroy one or more Persistent
61+
instances
62+
<SvgInfinite
63+
width="16px"
64+
className="ml-1.5 success-color-fg align-bottom"
65+
/>
66+
.
67+
{view === WorkspaceRole.manager
68+
? ' You need to confirm their deletion)'
69+
: ' They will be skipped, you need to MANUALLY destroy them)'}
70+
</i>
71+
</div>
72+
</div>
73+
) : (
74+
''
75+
)}
76+
</>
77+
);
78+
const buttons = [
79+
<Button
80+
key="destroy_all"
81+
type="danger"
82+
shape="round"
83+
size="middle"
84+
disabled={!confirmDeletion}
85+
icon={<DeleteOutlined />}
86+
className="border-0"
87+
onClick={() => {
88+
destroy();
89+
setShow(false);
90+
}}
91+
>
92+
{selective ? 'Destroy Selected' : 'Destroy All'}
93+
</Button>,
94+
];
95+
96+
const checkbox = {
97+
confirmCheckbox: confirmDeletion,
98+
setConfirmCheckbox: setConfirmDeletion,
99+
checkboxLabel: 'I understand the risk and I want to proceed',
100+
};
101+
102+
return (
103+
<ModalAlert
104+
headTitle={title}
105+
show={show}
106+
message={message}
107+
description={description}
108+
type="error"
109+
buttons={buttons}
110+
setShow={setShow}
111+
checkbox={checkbox}
112+
/>
113+
);
114+
};
115+
116+
export default ModalGroupDeletion;

frontend/src/components/activePage/TableInstance/TableInstance.tsx

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ErrorContext } from '../../../errorHandling/ErrorContext';
66
import { useDeleteInstanceMutation } from '../../../generated-types';
77
import { TenantContext } from '../../../graphql-components/tenantContext/TenantContext';
88
import { Instance, WorkspaceRole } from '../../../utils';
9-
import { ModalAlert } from '../../common/ModalAlert';
9+
import ModalGroupDeletion from '../ModalGroupDeletion/ModalGroupDeletion';
1010
import RowInstanceActions from './RowInstanceActions/RowInstanceActions';
1111
import RowInstanceHeader from './RowInstanceHeader/RowInstanceHeader';
1212
import RowInstanceTitle from './RowInstanceTitle/RowInstanceTitle';
@@ -54,16 +54,20 @@ const TableInstance: FC<ITableInstanceProps> = ({ ...props }) => {
5454
});
5555

5656
const destroyAll = () => {
57-
instances.forEach(instance => {
58-
deleteInstanceMutation({
59-
variables: {
60-
instanceId: instance.name,
61-
tenantNamespace: instance.tenantNamespace!,
62-
},
57+
instances
58+
.filter(i => i.persistent === false)
59+
.forEach(instance => {
60+
deleteInstanceMutation({
61+
variables: {
62+
instanceId: instance.name,
63+
tenantNamespace: instance.tenantNamespace!,
64+
},
65+
});
6366
});
64-
});
6567
};
6668

69+
const disabled = !instances.find(i => i.persistent === false);
70+
6771
// Filtering from all instances that ones which are included in the "selectiveDestroy" IDs list
6872
const selectedIn = instances.filter(i => selectiveDestroy?.includes(i.id));
6973

@@ -101,6 +105,7 @@ const TableInstance: FC<ITableInstanceProps> = ({ ...props }) => {
101105
showHeader={false}
102106
pagination={false}
103107
rowClassName=""
108+
rowKey={i => 1}
104109
>
105110
<Column
106111
title="Header"
@@ -188,28 +193,18 @@ const TableInstance: FC<ITableInstanceProps> = ({ ...props }) => {
188193
e.stopPropagation();
189194
setShowAlert(true);
190195
}}
196+
disabled={disabled}
191197
>
192198
Destroy All
193199
</Button>
194-
<ModalAlert
195-
headTitle="Destroy All"
200+
<ModalGroupDeletion
201+
view={WorkspaceRole.user}
202+
persistent={!!instances.find(i => i.persistent === true)}
203+
selective={false}
204+
instanceList={instances.map(i => i.id)}
196205
show={showAlert}
197-
message="Warning"
198-
description="This operation will delete all your instances and it is not reversible. Do you want to continue?"
199-
type="warning"
200-
buttons={[
201-
<Button
202-
type="danger"
203-
shape="round"
204-
size="middle"
205-
icon={<DeleteOutlined />}
206-
className="border-0"
207-
onClick={() => destroyAll()}
208-
>
209-
Destroy All
210-
</Button>,
211-
]}
212206
setShow={setShowAlert}
207+
destroy={destroyAll}
213208
/>
214209
</div>
215210
)}

frontend/src/components/activePage/TableInstance/TableInstanceLogic.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { TenantContext } from '../../../graphql-components/tenantContext/TenantC
1515
import { matchK8sObject, replaceK8sObject } from '../../../k8sUtils';
1616
import { Instance, User, WorkspaceRole } from '../../../utils';
1717
import {
18-
getSubObjType,
18+
getSubObjTypeK8s,
1919
makeGuiInstance,
2020
notifyStatus,
2121
sorter,
@@ -79,7 +79,7 @@ const TableInstanceLogic: FC<ITableInstanceLogicProps> = ({ ...props }) => {
7979
if (prev.instanceList?.instances) {
8080
let instances = [...prev.instanceList.instances];
8181
const found = instances.find(matchK8sObject(instance, false));
82-
objType = getSubObjType(found, instance, updateType);
82+
objType = getSubObjTypeK8s(found, instance, updateType);
8383
switch (objType) {
8484
case SubObjType.Deletion:
8585
instances = instances.filter(matchK8sObject(instance, true));
@@ -131,7 +131,7 @@ const TableInstanceLogic: FC<ITableInstanceLogicProps> = ({ ...props }) => {
131131

132132
const instances =
133133
dataInstances?.instanceList?.instances
134-
?.map((i, n) => makeGuiInstance(i, tenantId))
134+
?.map(i => makeGuiInstance(i, tenantId))
135135
.sort((a, b) =>
136136
sorter(
137137
a,

frontend/src/components/activePage/TableTemplate/TableTemplate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const TableTemplate: FC<ITableTemplateProps> = ({ ...props }) => {
5050
} = props;
5151
const { hasSSHKeys } = useContext(TenantContext);
5252
const [expandedId, setExpandedId] = useState(
53-
expandedT.get(templates[0].workspaceId).split(',')
53+
expandedT.get(templates[0].workspaceName).split(',')
5454
);
5555
const { apolloErrorCatcher } = useContext(ErrorContext);
5656

@@ -105,7 +105,7 @@ const TableTemplate: FC<ITableTemplateProps> = ({ ...props }) => {
105105
];
106106

107107
useEffect(() => {
108-
expandedT.set(expandedId.join(','), templates[0].workspaceId);
108+
expandedT.set(expandedId.join(','), templates[0].workspaceName);
109109
// eslint-disable-next-line react-hooks/exhaustive-deps
110110
}, [expandedId]);
111111

0 commit comments

Comments
 (0)