Skip to content

Commit cc95945

Browse files
committed
feat: open alert on tag delete error
1 parent 6736701 commit cc95945

5 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/taxonomy/tag-list/TagListTable.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const TagListTable = ({ taxonomyId, maxDepth }: TagListTableProps) => {
137137
draftError,
138138
createRowMutation: createTagMutation,
139139
updateRowMutation: updateTagMutation,
140+
deleteRowMutation: deleteTagMutation,
140141
toast,
141142
setToast,
142143
setIsCreatingTopRow: setIsCreatingTopTag,

src/taxonomy/tag-list/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ const useEditActions = ({
307307
});
308308
} catch (error) {
309309
const errorMessage = getErrorMessage(error);
310+
setDraftError(errorMessage);
310311
setToast({ show: true, message: intl.formatMessage(messages.tagDeleteErrorMessage, { errorMessage }) });
311312
}
312313
};

src/taxonomy/tree-table/SaveErrorAlert.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ import {
55

66
import { Info } from '@openedx/paragon/icons';
77
import { useIntl } from '@edx/frontend-platform/i18n';
8+
// @ts-ignore
89
import './TableView.scss';
910
import messages from './messages';
1011

1112
interface SaveErrorAlertProps {
1213
draftError: string | undefined;
1314
isError: boolean | undefined;
1415
isUpdateError: boolean | undefined;
16+
isDeleteError: boolean | undefined;
1517
}
16-
const SaveErrorAlert = ({ draftError, isError, isUpdateError }: SaveErrorAlertProps) => {
18+
const SaveErrorAlert = ({ draftError, isError, isUpdateError, isDeleteError }: SaveErrorAlertProps) => {
1719
const intl = useIntl();
18-
const hasError: boolean = Boolean((isError || isUpdateError) && !!draftError);
20+
const hasError: boolean = Boolean((isError || isUpdateError || isDeleteError) && !!draftError);
1921
const [alertOpen, setAlertOpen] = React.useState(hasError);
2022

2123
useEffect(() => {
2224
setAlertOpen(hasError);
23-
}, [hasError, isError, isUpdateError, draftError]);
25+
}, [hasError, isError, isUpdateError, isDeleteError, draftError]);
2426

2527
if (!alertOpen) { return null; }
2628

src/taxonomy/tree-table/TableView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const TableView = ({
4343
draftError,
4444
createRowMutation,
4545
updateRowMutation,
46+
deleteRowMutation,
4647
handleCreateRow,
4748
toast,
4849
setToast,
@@ -75,10 +76,11 @@ const TableView = ({
7576

7677
const { isError } = createRowMutation;
7778
const { isError: isUpdateError } = updateRowMutation;
79+
const { isError: isDeleteError } = deleteRowMutation;
7880

7981
return (
8082
<>
81-
<SaveErrorAlert draftError={draftError} isError={isError} isUpdateError={isUpdateError} />
83+
<SaveErrorAlert draftError={draftError} isError={isError} isUpdateError={isUpdateError} isDeleteError={isDeleteError} />
8284
<Card className="tag-list-card">
8385
<Card.Section className="p-0">
8486
<div className="d-flex justify-content-end align-items-center p-4">

src/taxonomy/tree-table/TreeTableContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface TreeTableContextValue {
2929
creatingParentId: RowId | null;
3030
setCreatingParentId: (id: RowId | null) => void;
3131
setDraftError: (error: string) => void;
32+
deleteRowMutation: CreateRowMutationState;
3233
validate: (value: string, mode?: 'soft' | 'hard') => boolean;
3334
handleUpdateRow: (value: string, originalValue: string) => void;
3435
editingRowId: RowId | null;
@@ -53,6 +54,7 @@ export const TreeTableContext = createContext<TreeTableContextValue>({
5354
draftError: '',
5455
createRowMutation: {},
5556
updateRowMutation: {},
57+
deleteRowMutation: {},
5658
toast: { show: false, message: '', variant: 'success' },
5759
setToast: () => {},
5860
setIsCreatingTopRow: () => {},

0 commit comments

Comments
 (0)