Skip to content

Commit 34ef6e9

Browse files
committed
[MergeDups] Toast when actions fail
1 parent 4612156 commit 34ef6e9

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

public/locales/en/translation.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@
417417
"protectedSenseInfo": "This sense cannot be deleted or dropped into another sense. You may still move it to another word or drop other senses into this one to merge them.",
418418
"protectedWord": "This word was imported with data that The Combine doesn't handle.",
419419
"protectedWordInfo": "To prevent deletion, the final sense of this word cannot be removed.",
420-
"protectedData": "Protected data: {{ val }}"
420+
"protectedData": "Protected data: {{ val }}",
421+
"dropIntoSidebarWarning": "You cannot drop senses into the sidebar.",
422+
"dropProtectedSenseWarning": "You cannot merge a protected sense into another sense."
421423
},
422424
"protectReason": {
423425
"annotations": "annotations",

src/goals/MergeDuplicates/MergeDupsStep/MergeDragDrop/index.tsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Drawer, Grid, ImageList, ImageListItem, Tooltip } from "@mui/material";
33
import { CSSProperties, ReactElement, useState } from "react";
44
import { DragDropContext, Droppable, DropResult } from "react-beautiful-dnd";
55
import { useTranslation } from "react-i18next";
6+
import { toast } from "react-toastify";
67
import { v4 } from "uuid";
78

89
import { appBarHeight } from "components/AppBar/AppBarTypes";
@@ -63,20 +64,22 @@ export default function MergeDragDrop(): ReactElement {
6364
setSrcToDelete(src);
6465
} else if (res.combine) {
6566
// Case 2: the sense was dropped on another sense.
67+
const dest: MergeTreeReference = JSON.parse(res.combine.draggableId);
68+
if (dest.order !== undefined) {
69+
// Case 2a: If the target is a sidebar sub-sense, it cannot receive a combine.
70+
toast.warning(t("mergeDups.helpText.dropIntoSidebarWarning"));
71+
return;
72+
}
6673
if (src.isSenseProtected && !src.order) {
67-
// Case 2a: Cannot merge a protected sense into another sense.
74+
// Case 2b: Cannot merge a protected sense into another sense.
75+
toast.warning(t("mergeDups.helpText.dropProtectedSenseWarning"));
6876
const destWordId = res.combine.droppableId;
6977
if (srcWordId !== destWordId) {
7078
// The target sense is in a different word, so move instead of combine.
7179
dispatch(moveSense({ destOrder: 0, destWordId, src }));
7280
}
7381
return;
7482
}
75-
const dest: MergeTreeReference = JSON.parse(res.combine.draggableId);
76-
if (dest.order !== undefined) {
77-
// Case 2b: If the target is a sidebar sub-sense, it cannot receive a combine.
78-
return;
79-
}
8083
const combinePayload: CombineSenseMergePayload = { dest, src };
8184
dispatch(combineSense(combinePayload));
8285
} else if (res.destination) {
@@ -87,18 +90,21 @@ export default function MergeDragDrop(): ReactElement {
8790
// Case 3a: The source, dest droppables are different.
8891
if (destWordId.split(" ").length > 1) {
8992
// If the destination is SidebarDrop, it cannot receive drags from elsewhere.
93+
toast.warning(t("mergeDups.helpText.dropIntoSidebarWarning"));
9094
return;
9195
}
9296
// Move the sense to the dest MergeWord.
9397
const movePayload: MoveSensePayload = { destOrder, destWordId, src };
9498
dispatch(moveSense(movePayload));
9599
} else {
96100
// Case 3b: The source & dest droppables are the same, so we reorder, not move.
97-
if (
98-
src.order === destOrder ||
99-
(destOrder === 0 && src.order !== undefined && sidebarProtected)
100-
) {
101-
// If the sense wasn't moved or was moved within the sidebar above a protected sense, do nothing.
101+
if (src.order === destOrder) {
102+
// If the sense wasn't moved, do nothing.
103+
return;
104+
}
105+
const toTop = destOrder === 0 && src.order !== undefined;
106+
if (toTop && sidebarProtected) {
107+
// If the sense was moved within the sidebar above a protected sense, do nothing.
102108
return;
103109
}
104110
const orderPayload: OrderSensePayload = { destOrder, src };

0 commit comments

Comments
 (0)