Skip to content

Commit 32b90bf

Browse files
committed
Wizard: Add an ability to delete clusters from UI
+ Added delete Button + Added useDeleteCluster hook Resolves Issue #65
1 parent 11a57d1 commit 32b90bf

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import {
3+
useQueryClient,
4+
useMutation,
5+
UseMutationResult,
6+
} from '@tanstack/react-query';
7+
import { appConfigApiClient as api } from 'lib/api';
8+
import { ApplicationConfigPropertiesKafkaClusters } from 'generated-sources';
9+
10+
export function useDeleteCluster(): [
11+
UseMutationResult<void, unknown, string, unknown>,
12+
boolean
13+
] {
14+
const client = useQueryClient();
15+
const [isDeleteing, setIsDeleting] = React.useState(false);
16+
17+
return [
18+
useMutation(
19+
async (clusterName: string) => {
20+
setIsDeleting(true);
21+
const existingConfig = await api.getCurrentConfig();
22+
const existingClusters =
23+
existingConfig.properties?.kafka?.clusters || [];
24+
25+
let clusters: ApplicationConfigPropertiesKafkaClusters[] = [];
26+
27+
if (existingClusters.length > 0) {
28+
clusters = existingClusters.filter((c) => c.name !== clusterName);
29+
}
30+
const config = {
31+
...existingConfig,
32+
properties: {
33+
...existingConfig.properties,
34+
kafka: { clusters },
35+
},
36+
};
37+
return api.restartWithConfig({ restartRequest: { config } });
38+
},
39+
{
40+
onSuccess: () => {
41+
client.invalidateQueries(['app', 'config']);
42+
setIsDeleting(false);
43+
},
44+
}
45+
),
46+
isDeleteing,
47+
];
48+
}

frontend/src/widgets/ClusterConfigForm/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import Metrics from 'widgets/ClusterConfigForm/Sections/Metrics';
2222
import CustomAuthentication from 'widgets/ClusterConfigForm/Sections/CustomAuthentication';
2323
import Authentication from 'widgets/ClusterConfigForm/Sections/Authentication/Authentication';
2424
import KSQL from 'widgets/ClusterConfigForm/Sections/KSQL';
25+
import { useConfirm } from 'lib/hooks/useConfirm';
26+
27+
import { useDeleteCluster } from './hooks/useDeleteCluster';
2528

2629
interface ClusterConfigFormProps {
2730
hasCustomConfig?: boolean;
@@ -52,12 +55,23 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
5255

5356
const validate = useValidateAppConfig();
5457
const update = useUpdateAppConfig({ initialName: initialValues.name });
58+
const [deleteCluster, isDeleting] = useDeleteCluster();
59+
const confirm = useConfirm(true);
60+
5561
const {
5662
value: isFormDisabled,
5763
setTrue: disableForm,
5864
setFalse: enableForm,
5965
} = useBoolean();
6066

67+
const confirmClusterDelete = () =>
68+
confirm('Are you sure want to delete this cluster?', async () => {
69+
if (initialValues.name) {
70+
await deleteCluster.mutateAsync(initialValues.name);
71+
navigate('/');
72+
}
73+
});
74+
6175
const onSubmit = async (data: ClusterConfigFormValues) => {
6276
const config = transformFormDataToPayload(data);
6377
try {
@@ -146,6 +160,17 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
146160
>
147161
Submit
148162
</Button>
163+
{initialValues.name && (
164+
<Button
165+
type="button"
166+
buttonSize="L"
167+
buttonType="danger"
168+
inProgress={isDeleting}
169+
onClick={confirmClusterDelete}
170+
>
171+
Delete
172+
</Button>
173+
)}
149174
</S.ButtonWrapper>
150175
</FlexFieldset>
151176
</StyledForm>

0 commit comments

Comments
 (0)