Skip to content

Commit c15a6ba

Browse files
authored
[GEN-1574]: delete actions (#1657)
1 parent d42c32b commit c15a6ba

File tree

9 files changed

+32
-125
lines changed

9 files changed

+32
-125
lines changed

frontend/webapp/containers/main/actions/choose-action-modal/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import styled from 'styled-components';
2-
import React, { useMemo, useState } from 'react';
32
import { ChooseActionBody } from '../';
3+
import React, { useMemo, useState } from 'react';
4+
import { useActionCRUD, useActionFormData } from '@/hooks/actions';
45
import { ACTION_OPTIONS, type ActionOption } from './action-options';
5-
import { useActionFormData, useCreateAction } from '@/hooks/actions';
66
import { AutocompleteInput, Modal, NavigationButtons, Text, Divider, FadeLoader } from '@/reuseable-components';
77

88
const DefineActionContainer = styled.section`
@@ -43,7 +43,7 @@ interface AddActionModalProps {
4343

4444
export const AddActionModal: React.FC<AddActionModalProps> = ({ isModalOpen, handleCloseModal }) => {
4545
const { formData, handleFormChange, resetFormData, validateForm } = useActionFormData();
46-
const { createAction, loading } = useCreateAction({ onSuccess: handleClose });
46+
const { createAction, loading } = useActionCRUD({ onSuccess: handleClose });
4747
const [selectedItem, setSelectedItem] = useState<ActionOption | null>(null);
4848

4949
const isFormOk = useMemo(() => !!selectedItem && validateForm(), [selectedItem, formData]);

frontend/webapp/containers/main/overview/overview-drawer/index.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import DrawerFooter from './drawer-footer';
77
import { SourceDrawer } from '../../sources';
88
import { Drawer } from '@/reuseable-components';
99
import { DeleteEntityModal } from '@/components';
10-
import { useActualSources, useNotify, useUpdateDestination } from '@/hooks';
1110
import { ActionDrawer, type ActionDrawerHandle } from '../../actions';
1211
import { DestinationDrawer, type DestinationDrawerHandle } from '../../destinations';
12+
import { useActionCRUD, useActualSources, useNotify, useUpdateDestination } from '@/hooks';
1313
import { getMainContainerLanguageLogo, WORKLOAD_PROGRAMMING_LANGUAGES } from '@/utils/constants/programming-languages';
1414
import { WorkloadId, K8sActualSource, ActualDestination, OVERVIEW_ENTITY_TYPES, PatchSourceRequestInput, ActionDataParsed } from '@/types';
15-
import { useUpdateAction } from '@/hooks/actions/useUpdateAction';
1615

1716
const componentMap = {
1817
source: SourceDrawer,
@@ -31,7 +30,7 @@ const OverviewDrawer = () => {
3130
const [title, setTitle] = useState('');
3231

3332
const notify = useNotify();
34-
const { updateAction } = useUpdateAction();
33+
const { updateAction, deleteAction } = useActionCRUD();
3534
const { updateExistingDestination } = useUpdateDestination();
3635
const { updateActualSource, deleteSourcesForNamespace } = useActualSources();
3736

@@ -177,7 +176,9 @@ const OverviewDrawer = () => {
177176
}
178177

179178
if (type === OVERVIEW_ENTITY_TYPES.ACTION) {
180-
alert('TODO !');
179+
const { id, type } = item as ActionDataParsed;
180+
181+
await deleteAction(id, type);
181182
}
182183

183184
if (type === OVERVIEW_ENTITY_TYPES.DESTINATION) {

frontend/webapp/graphql/mutations/action.ts

+6
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ export const UPDATE_ACTION = gql`
1515
}
1616
}
1717
`;
18+
19+
export const DELETE_ACTION = gql`
20+
mutation DeleteAction($id: ID!, $actionType: String!) {
21+
deleteAction(id: $id, actionType: $actionType)
22+
}
23+
`;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './destination';
22
export * from './source';
33
export * from './namespace';
4+
export * from './action';
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from './useActionFormData';
22
export * from './useActions';
33
export * from './useActionState';
4-
export * from './useCreateAction';
54
export * from './useGetActions';
5+
export * from './useActionCRUD';

frontend/webapp/hooks/actions/useActionCRUD.ts

+15-39
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useNotify } from '../useNotify';
33
import { useMutation } from '@apollo/client';
44
import type { ActionInput, ActionsType } from '@/types';
55
import { useComputePlatform } from '../compute-platform';
6-
import { CREATE_ACTION, DELETE_ACTION, UPDATE_ACTION } from '@/graphql/mutations/action';
6+
import { CREATE_ACTION, DELETE_ACTION, UPDATE_ACTION } from '@/graphql/mutations';
77

88
interface UseActionCrudParams {
99
onSuccess?: () => void;
@@ -15,57 +15,33 @@ export const useActionCRUD = (params?: UseActionCrudParams) => {
1515
const { refetch } = useComputePlatform();
1616
const notify = useNotify();
1717

18-
const handleError = (title: string, message: string) => {
19-
notify({
20-
title,
21-
message,
22-
type: 'error',
23-
target: 'notification',
24-
crdType: 'notification',
25-
});
18+
const notifyUser = (title: string, message: string, type: 'error' | 'success') => {
19+
notify({ title, message, type, target: 'notification', crdType: 'notification' });
20+
};
2621

27-
if (params?.onError) params.onError();
22+
const handleError = (title: string, message: string) => {
23+
notifyUser(title, message, 'error');
24+
params?.onError?.();
2825
};
2926

3027
const handleComplete = (title: string, message: string) => {
28+
notifyUser(title, message, 'success');
3129
setDrawerItem(null);
3230
refetch();
33-
notify({
34-
title,
35-
message,
36-
type: 'success',
37-
target: 'notification',
38-
crdType: 'notification',
39-
});
40-
41-
if (params?.onSuccess) params.onSuccess();
31+
params?.onSuccess?.();
4232
};
4333

4434
const [createAction, cState] = useMutation(CREATE_ACTION, {
45-
onError: (error) => {
46-
handleError('Create Action', error.message);
47-
},
48-
onCompleted: () => {
49-
handleComplete('Create Action', 'successfully created');
50-
},
35+
onError: (error) => handleError('Create Action', error.message),
36+
onCompleted: () => handleComplete('Create Action', 'successfully created'),
5137
});
52-
5338
const [updateAction, uState] = useMutation(UPDATE_ACTION, {
54-
onError: (error) => {
55-
handleError('Update Action', error.message);
56-
},
57-
onCompleted: () => {
58-
handleComplete('Update Action', 'successfully updated');
59-
},
39+
onError: (error) => handleError('Update Action', error.message),
40+
onCompleted: () => handleComplete('Update Action', 'successfully updated'),
6041
});
61-
6242
const [deleteAction, dState] = useMutation(DELETE_ACTION, {
63-
onError: (error) => {
64-
handleError('Delete Action', error.message);
65-
},
66-
onCompleted: () => {
67-
handleComplete('Delete Action', 'successfully deleted');
68-
},
43+
onError: (error) => handleError('Delete Action', error.message),
44+
onCompleted: () => handleComplete('Delete Action', 'successfully deleted'),
6945
});
7046

7147
return {

frontend/webapp/hooks/actions/useCreateAction.ts

-37
This file was deleted.

frontend/webapp/hooks/actions/useUpdateAction.ts

-40
This file was deleted.

frontend/webapp/types/actions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export interface ActionItem {
7878

7979
export interface ActionData {
8080
id: string;
81-
type: string;
81+
type: ActionsType;
8282
spec: ActionItem | string;
8383
}
8484

0 commit comments

Comments
 (0)