Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MergeDups] Track deleted senses #2953

Merged
merged 26 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5adc294
Use that sidebar can't be open with one sense
imnasnainaec Jan 31, 2024
898910d
Close sidebar if only one sense left
imnasnainaec Feb 1, 2024
f59b8d2
Update sidebar tests
imnasnainaec Feb 1, 2024
b46e78b
Frame sidebar check more generally
imnasnainaec Feb 1, 2024
0209a5f
Don't open sidebar without multiple senses
imnasnainaec Feb 1, 2024
bb544c5
Add test
imnasnainaec Feb 1, 2024
b4dc1b4
Tidy
imnasnainaec Feb 1, 2024
c1f9a91
Add better move destOrder coverage
imnasnainaec Feb 1, 2024
fa5f956
Remove superfluous const
imnasnainaec Feb 2, 2024
fc06513
Add comment
imnasnainaec Feb 2, 2024
e555530
Add comment
imnasnainaec Feb 2, 2024
704ca73
Clarify comment
imnasnainaec Feb 2, 2024
a9b0cd6
Update mock sidebar and comments
imnasnainaec Feb 2, 2024
baa8175
Merge branch 'master' into merge-reducer
imnasnainaec Feb 6, 2024
88c06fb
Merge branch 'master' into merge-reducer
imnasnainaec Feb 6, 2024
2520144
Sort imports
imnasnainaec Feb 6, 2024
a30422c
Merge branch 'master' into merge-reducer
imnasnainaec Feb 12, 2024
0190258
Merge branch 'master' into merge-reducer
imnasnainaec Feb 14, 2024
0642e19
Merge branch 'master' into merge-reducer
imnasnainaec Feb 16, 2024
96ca20b
Track deleted senses
imnasnainaec Feb 16, 2024
b108de7
Merge branch 'master' into merge-deleted-senses
imnasnainaec Feb 23, 2024
463224e
Merge branch 'master' into merge-deleted-senses
imnasnainaec Feb 23, 2024
3a1a028
Merge branch 'master' into merge-deleted-senses
imnasnainaec Mar 5, 2024
bde6cbf
Merge branch 'master' into merge-deleted-senses
imnasnainaec Mar 20, 2024
e63b996
Merge branch 'master' into merge-deleted-senses
imnasnainaec Mar 21, 2024
5a808ba
Merge branch 'master' into merge-deleted-senses
imnasnainaec Mar 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/goals/MergeDuplicates/MergeDupsTreeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ export const defaultSidebar: Sidebar = {
};

export interface MergeTree {
deletedSenseGuids: string[];
sidebar: Sidebar;
words: Hash<MergeTreeWord>;
}

export const defaultTree: MergeTree = { sidebar: defaultSidebar, words: {} };
export const defaultTree: MergeTree = {
deletedSenseGuids: [],
sidebar: defaultSidebar,
words: {},
};
24 changes: 12 additions & 12 deletions src/goals/MergeDuplicates/Redux/MergeDupsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
type Sidebar,
convertSenseToMergeTreeSense,
convertWordToMergeTreeWord,
defaultData,
defaultSidebar,
defaultTree,
newMergeTreeWord,
Expand Down Expand Up @@ -74,12 +75,13 @@ const mergeDuplicatesSlice = createSlice({
deleteSenseAction: (state, action) => {
const srcRef: MergeTreeReference = action.payload;
const srcWordId = srcRef.wordId;
const words = state.tree.words;
const { deletedSenseGuids, words } = state.tree;

const sensesGuids = words[srcWordId].sensesGuids;
const srcGuids = sensesGuids[srcRef.mergeSenseId];
if (srcRef.order === undefined || srcGuids.length === 1) {
// A sense deleted from a word.
deletedSenseGuids.push(...srcGuids);
delete sensesGuids[srcRef.mergeSenseId];
if (!Object.keys(sensesGuids).length) {
delete words[srcWordId];
Expand All @@ -92,6 +94,7 @@ const mergeDuplicatesSlice = createSlice({
}
} else {
// A sense deleted from the sidebar.
deletedSenseGuids.push(srcGuids[srcRef.order]);
srcGuids.splice(srcRef.order, 1);
if (srcGuids.length < 2) {
// If not multiple senses in the sidebar, reset the sidebar.
Expand All @@ -107,12 +110,9 @@ const mergeDuplicatesSlice = createSlice({
getMergeWordsAction: (state) => {
// Handle words with all senses deleted.
const possibleWords = Object.values(state.data.words);
// List of all non-deleted senses.
const nonDeletedSenses = Object.values(state.tree.words).flatMap((w) =>
Object.values(w.sensesGuids).flatMap((s) => s)
);
const deletedSenseGuids = state.tree.deletedSenseGuids;
const deletedWords = possibleWords.filter((w) =>
w.senses.every((s) => !nonDeletedSenses.includes(s.guid))
w.senses.every((s) => deletedSenseGuids.includes(s.guid))
);
state.mergeWords = deletedWords.map((w) =>
newMergeWords(w, [{ srcWordId: w.id, getAudio: false }], true)
Expand All @@ -123,7 +123,7 @@ const mergeDuplicatesSlice = createSlice({
const mergeSenses = buildSenses(
mergeWord.sensesGuids,
state.data,
nonDeletedSenses
deletedSenseGuids
);
const mergeWords = createMergeWords(
wordId,
Expand Down Expand Up @@ -265,7 +265,7 @@ const mergeDuplicatesSlice = createSlice({
});
wordsTree[word.id] = convertWordToMergeTreeWord(word);
});
state.data = { senses, words };
state.data = { ...defaultData, senses, words };
state.tree = { ...defaultTree, words: wordsTree };
state.mergeWords = [];
}
Expand All @@ -285,7 +285,7 @@ const mergeDuplicatesSlice = createSlice({
function buildSenses(
sensesGuids: Hash<string[]>,
data: MergeData,
nonDeletedSenses: string[]
deletedSenseGuids: string[]
): Hash<MergeTreeSense[]> {
const senses: Hash<MergeTreeSense[]> = {};
for (const senseGuids of Object.values(sensesGuids)) {
Expand All @@ -305,9 +305,9 @@ function buildSenses(
srcWordId: wordId,
sense: {
...sense,
accessibility: nonDeletedSenses.includes(sense.guid)
? Status.Separate
: Status.Deleted,
accessibility: deletedSenseGuids.includes(sense.guid)
? Status.Deleted
: Status.Separate,
},
});
}
Expand Down
12 changes: 10 additions & 2 deletions src/goals/MergeDuplicates/Redux/tests/MergeDupsActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ describe("MergeDupActions", () => {
it("delete one sense from word with multiple senses", async () => {
const WA = newMergeTreeWord(vernA, { ID1: [S1] });
const WB = newMergeTreeWord(vernB, { ID1: [S3], ID2: [S4] });
const tree: MergeTree = { ...defaultTree, words: { WA, WB } };
const tree: MergeTree = {
...defaultTree,
deletedSenseGuids: [S2],
words: { WA, WB },
};
const store = setupStore({
...preloadedState,
mergeDuplicateGoal: { ...defaultMergeState, data, tree },
Expand All @@ -237,7 +241,11 @@ describe("MergeDupActions", () => {
// Delete both senses from B
it("delete all senses from a word", async () => {
const WA = newMergeTreeWord(vernA, { ID1: [S1], ID2: [S2] });
const tree: MergeTree = { ...defaultTree, words: { WA } };
const tree: MergeTree = {
...defaultTree,
deletedSenseGuids: [S3, S4],
words: { WA },
};
const store = setupStore({
...preloadedState,
mergeDuplicateGoal: { ...defaultMergeState, data, tree },
Expand Down
Loading