-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wizard: Add an ability to delete clusters from UI
+ Added delete Button + Added useDeleteCluster hook Resolves Issue #65
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
frontend/src/widgets/ClusterConfigForm/hooks/useDeleteCluster.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
import { | ||
useQueryClient, | ||
useMutation, | ||
UseMutationResult, | ||
} from '@tanstack/react-query'; | ||
import { appConfigApiClient as api } from 'lib/api'; | ||
import { ApplicationConfigPropertiesKafkaClusters } from 'generated-sources'; | ||
|
||
export function useDeleteCluster(): [ | ||
UseMutationResult<void, unknown, string, unknown>, | ||
boolean | ||
] { | ||
const client = useQueryClient(); | ||
const [isDeleteing, setIsDeleting] = React.useState(false); | ||
|
||
return [ | ||
useMutation( | ||
async (clusterName: string) => { | ||
setIsDeleting(true); | ||
const existingConfig = await api.getCurrentConfig(); | ||
const existingClusters = | ||
existingConfig.properties?.kafka?.clusters || []; | ||
|
||
let clusters: ApplicationConfigPropertiesKafkaClusters[] = []; | ||
|
||
if (existingClusters.length > 0) { | ||
clusters = existingClusters.filter((c) => c.name !== clusterName); | ||
} | ||
const config = { | ||
...existingConfig, | ||
properties: { | ||
...existingConfig.properties, | ||
kafka: { clusters }, | ||
}, | ||
}; | ||
return api.restartWithConfig({ restartRequest: { config } }); | ||
}, | ||
{ | ||
onSuccess: () => { | ||
client.invalidateQueries(['app', 'config']); | ||
setIsDeleting(false); | ||
}, | ||
} | ||
), | ||
isDeleteing, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters