Skip to content

Commit

Permalink
Wizard: Add an ability to delete clusters from UI
Browse files Browse the repository at this point in the history
+ Added delete Button
+ useUpdateAppConfig changed to delete clusters

Resolves Issue #65
  • Loading branch information
Nilumilak committed Feb 20, 2024
1 parent 11a57d1 commit 657ea54
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
12 changes: 10 additions & 2 deletions frontend/src/lib/hooks/api/appConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ export function useAppConfig() {
return useQuery(['app', 'config'], () => api.getCurrentConfig());
}

export function useUpdateAppConfig({ initialName }: { initialName?: string }) {
export function useUpdateAppConfig({
initialName,
deleteCluster,
}: {
initialName?: string;
deleteCluster?: boolean;
}) {
const client = useQueryClient();
return useMutation(
async (cluster: ApplicationConfigPropertiesKafkaClusters) => {
Expand All @@ -27,10 +33,12 @@ export function useUpdateAppConfig({ initialName }: { initialName?: string }) {
if (existingClusters.length > 0) {
if (!initialName) {
clusters = [...existingClusters, cluster];
} else {
} else if (!deleteCluster) {
clusters = existingClusters.map((c) =>
c.name === initialName ? cluster : c
);
} else {
clusters = existingClusters.filter((c) => c.name !== initialName);
}
} else {
clusters = [cluster];
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/widgets/ClusterConfigForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Metrics from 'widgets/ClusterConfigForm/Sections/Metrics';
import CustomAuthentication from 'widgets/ClusterConfigForm/Sections/CustomAuthentication';
import Authentication from 'widgets/ClusterConfigForm/Sections/Authentication/Authentication';
import KSQL from 'widgets/ClusterConfigForm/Sections/KSQL';
import { useConfirm } from 'lib/hooks/useConfirm';

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

const validate = useValidateAppConfig();
const update = useUpdateAppConfig({ initialName: initialValues.name });
const deleteCluster = useUpdateAppConfig({
initialName: initialValues.name,
deleteCluster: true,
});
const confirm = useConfirm(true);

const {
value: isFormDisabled,
setTrue: disableForm,
setFalse: enableForm,
} = useBoolean();

const confirmClusterDelete = () =>
confirm('Are you sure want to delete this cluster?', async () => {
if (initialValues.name) {
const data = methods.getValues();
const config = transformFormDataToPayload(data);
try {
await deleteCluster.mutateAsync(config);
navigate('/');
} catch (error) {
showAlert('error', {
id: 'app-config-update-error',
title: 'Error updating application config',
message: 'There was an error updating the application config',
});
}
}
});

const onSubmit = async (data: ClusterConfigFormValues) => {
const config = transformFormDataToPayload(data);
try {
Expand Down Expand Up @@ -146,6 +171,16 @@ const ClusterConfigForm: React.FC<ClusterConfigFormProps> = ({
>
Submit
</Button>
{initialValues.name && (
<Button
buttonSize="L"
buttonType="danger"
inProgress={deleteCluster.isLoading}
onClick={confirmClusterDelete}
>
Delete
</Button>
)}
</S.ButtonWrapper>
</FlexFieldset>
</StyledForm>
Expand Down

0 comments on commit 657ea54

Please sign in to comment.