Skip to content

Commit 657ea54

Browse files
committed
Wizard: Add an ability to delete clusters from UI
+ Added delete Button + useUpdateAppConfig changed to delete clusters Resolves Issue #65
1 parent 11a57d1 commit 657ea54

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

frontend/src/lib/hooks/api/appConfig.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ export function useAppConfig() {
1515
return useQuery(['app', 'config'], () => api.getCurrentConfig());
1616
}
1717

18-
export function useUpdateAppConfig({ initialName }: { initialName?: string }) {
18+
export function useUpdateAppConfig({
19+
initialName,
20+
deleteCluster,
21+
}: {
22+
initialName?: string;
23+
deleteCluster?: boolean;
24+
}) {
1925
const client = useQueryClient();
2026
return useMutation(
2127
async (cluster: ApplicationConfigPropertiesKafkaClusters) => {
@@ -27,10 +33,12 @@ export function useUpdateAppConfig({ initialName }: { initialName?: string }) {
2733
if (existingClusters.length > 0) {
2834
if (!initialName) {
2935
clusters = [...existingClusters, cluster];
30-
} else {
36+
} else if (!deleteCluster) {
3137
clusters = existingClusters.map((c) =>
3238
c.name === initialName ? cluster : c
3339
);
40+
} else {
41+
clusters = existingClusters.filter((c) => c.name !== initialName);
3442
}
3543
} else {
3644
clusters = [cluster];

frontend/src/widgets/ClusterConfigForm/index.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ 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';
2526

2627
interface ClusterConfigFormProps {
2728
hasCustomConfig?: boolean;
@@ -52,12 +53,36 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
5253

5354
const validate = useValidateAppConfig();
5455
const update = useUpdateAppConfig({ initialName: initialValues.name });
56+
const deleteCluster = useUpdateAppConfig({
57+
initialName: initialValues.name,
58+
deleteCluster: true,
59+
});
60+
const confirm = useConfirm(true);
61+
5562
const {
5663
value: isFormDisabled,
5764
setTrue: disableForm,
5865
setFalse: enableForm,
5966
} = useBoolean();
6067

68+
const confirmClusterDelete = () =>
69+
confirm('Are you sure want to delete this cluster?', async () => {
70+
if (initialValues.name) {
71+
const data = methods.getValues();
72+
const config = transformFormDataToPayload(data);
73+
try {
74+
await deleteCluster.mutateAsync(config);
75+
navigate('/');
76+
} catch (error) {
77+
showAlert('error', {
78+
id: 'app-config-update-error',
79+
title: 'Error updating application config',
80+
message: 'There was an error updating the application config',
81+
});
82+
}
83+
}
84+
});
85+
6186
const onSubmit = async (data: ClusterConfigFormValues) => {
6287
const config = transformFormDataToPayload(data);
6388
try {
@@ -146,6 +171,16 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
146171
>
147172
Submit
148173
</Button>
174+
{initialValues.name && (
175+
<Button
176+
buttonSize="L"
177+
buttonType="danger"
178+
inProgress={deleteCluster.isLoading}
179+
onClick={confirmClusterDelete}
180+
>
181+
Delete
182+
</Button>
183+
)}
149184
</S.ButtonWrapper>
150185
</FlexFieldset>
151186
</StyledForm>

0 commit comments

Comments
 (0)