console: add confirm dialog before untracking stored procedures

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9305
GitOrigin-RevId: 5764f00a7558f2a9f5c16b220ebceb63f0685d5f
This commit is contained in:
Vijay Prasanna 2023-05-26 01:11:15 +05:30 committed by hasura-bot
parent 8f0451ce42
commit 01b54b49b6

View File

@ -18,6 +18,8 @@ import {
STORED_PROCEDURE_UNTRACK_ERROR, STORED_PROCEDURE_UNTRACK_ERROR,
STORED_PROCEDURE_UNTRACK_SUCCESS, STORED_PROCEDURE_UNTRACK_SUCCESS,
} from '../../constants'; } from '../../constants';
import { useDestructiveAlert } from '../../../../../new-components/Alert';
import { getQualifiedTable } from '../../../ManageTable/utils';
// this is local type for the table row. Do not export // this is local type for the table row. Do not export
type RowType = { dataSourceName: string } & StoredProcedure; type RowType = { dataSourceName: string } & StoredProcedure;
@ -42,30 +44,45 @@ export const ListStoredProcedures = () => {
.flat() .flat()
); );
// const { hasuraAlert } = useHasuraAlert();
const { destructiveConfirm } = useDestructiveAlert();
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
const onRemoveClick = (data: RowType, index: number) => { const onRemoveClick = (data: RowType, index: number) => {
setActiveRow(index); destructiveConfirm({
untrackStoredProcedure({ resourceName: getQualifiedTable(data.stored_procedure).join(' / '),
data: { resourceType: 'Stored Procedure',
dataSourceName: data.dataSourceName, destroyTerm: 'remove',
stored_procedure: data.stored_procedure, onConfirm: () =>
}, new Promise(resolve => {
onSuccess: () => { setActiveRow(index);
hasuraToast({
type: 'success', untrackStoredProcedure({
title: STORED_PROCEDURE_UNTRACK_SUCCESS, data: {
}); dataSourceName: data.dataSourceName,
}, stored_procedure: data.stored_procedure,
onError: err => { },
hasuraToast({ onSuccess: () => {
type: 'error', hasuraToast({
title: STORED_PROCEDURE_UNTRACK_ERROR, type: 'success',
children: <DisplayToastErrorMessage message={err.message} />, title: STORED_PROCEDURE_UNTRACK_SUCCESS,
}); });
}, resolve(true);
onSettled: () => { },
setActiveRow(undefined); onError: err => {
}, hasuraToast({
type: 'error',
title: STORED_PROCEDURE_UNTRACK_ERROR,
children: <DisplayToastErrorMessage message={err.message} />,
});
resolve(false);
},
onSettled: () => {
setActiveRow(undefined);
},
});
}),
}); });
}; };