Skip to content

Commit b518748

Browse files
authored
[ReviewEntries] Store edits from Pronunciations column (#3926)
1 parent ca31e32 commit b518748

File tree

4 files changed

+15
-28
lines changed

4 files changed

+15
-28
lines changed

src/goals/Redux/GoalActions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ export function dispatchStepData(goal: Goal) {
201201
};
202202
}
203203

204+
/** Add entry update to the current goal. */
205+
export function asyncUpdateEntry(oldId: string, newId: string) {
206+
return async (dispatch: StoreStateDispatch) => {
207+
dispatch(addEntryEditToGoal({ newId, oldId }));
208+
await dispatch(asyncUpdateGoal());
209+
};
210+
}
211+
204212
// Helper Functions
205213

206214
export function getUserEditId(): string | undefined {

src/goals/ReviewEntries/ReviewEntriesTable/Cells/EditCell/EditDialog.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ import { CancelConfirmDialog } from "components/Dialogs";
3535
import PronunciationsBackend from "components/Pronunciations/PronunciationsBackend";
3636
import PronunciationsFrontend from "components/Pronunciations/PronunciationsFrontend";
3737
import { uploadFileFromPronunciation } from "components/Pronunciations/utilities";
38-
import { addEntryEditToGoal, asyncUpdateGoal } from "goals/Redux/GoalActions";
3938
import EditSensesCardContent from "goals/ReviewEntries/ReviewEntriesTable/Cells/EditCell/EditSensesCardContent";
4039
import {
4140
cleanWord,
4241
isSenseChanged,
4342
} from "goals/ReviewEntries/ReviewEntriesTable/Cells/EditCell/utilities";
44-
import { useAppDispatch, useAppSelector } from "rootRedux/hooks";
45-
import { type StoreState, type StoreStateDispatch } from "rootRedux/types";
43+
import { useAppSelector } from "rootRedux/hooks";
44+
import { type StoreState } from "rootRedux/types";
4645
import { themeColors } from "types/theme";
4746
import {
4847
type FileWithSpeakerId,
@@ -54,14 +53,6 @@ import {
5453
TextFieldWithFont,
5554
} from "utilities/fontComponents";
5655

57-
/** Add word update to the current goal. */
58-
function asyncUpdateWord(oldId: string, newId: string) {
59-
return async (dispatch: StoreStateDispatch) => {
60-
dispatch(addEntryEditToGoal({ newId, oldId }));
61-
await dispatch(asyncUpdateGoal());
62-
};
63-
}
64-
6556
/** Update word in the backend */
6657
export async function updateFrontierWord(
6758
newWord: Word,
@@ -116,8 +107,6 @@ interface EditDialogProps {
116107
}
117108

118109
export default function EditDialog(props: EditDialogProps): ReactElement {
119-
const dispatch = useAppDispatch();
120-
121110
const analysisWritingSystems = useAppSelector(
122111
(state: StoreState) =>
123112
state.currentProjectState.project.analysisWritingSystems
@@ -297,10 +286,7 @@ export default function EditDialog(props: EditDialogProps): ReactElement {
297286
props.word.audio
298287
);
299288

300-
// Update in goal
301-
await dispatch(asyncUpdateWord(props.word.id, newId));
302-
303-
// Update in ReviewEntries state
289+
// Update in goal and ReviewEntries state
304290
await props.confirm(newId);
305291

306292
// Close

src/goals/ReviewEntries/ReviewEntriesTable/Cells/EditCell/tests/EditDialog.test.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,10 @@ jest.mock(
3434
"goals/ReviewEntries/ReviewEntriesTable/Cells/EditCell/EditSenseDialog"
3535
);
3636
jest.mock("i18n", () => ({}));
37-
jest.mock("rootRedux/hooks", () => ({
38-
...jest.requireActual("rootRedux/hooks"),
39-
useAppDispatch: () => mockDispatch,
40-
}));
4137

4238
const mockClose = jest.fn();
4339
const mockConfirm = jest.fn();
4440
const mockDeleteAudio = jest.fn();
45-
const mockDispatch = jest.fn();
4641
const mockUpdateWord = jest.fn();
4742

4843
const mockTextFieldEvent = (
@@ -116,7 +111,6 @@ describe("EditDialog", () => {
116111
expect(mockClose).toHaveBeenCalledTimes(1);
117112
expect(mockConfirm).not.toHaveBeenCalled();
118113
expect(mockUpdateWord).not.toHaveBeenCalled();
119-
expect(mockDispatch).not.toHaveBeenCalled();
120114
});
121115

122116
test("cancel button opens dialog if changes", async () => {
@@ -147,7 +141,6 @@ describe("EditDialog", () => {
147141
expect(mockClose).not.toHaveBeenCalled();
148142
expect(mockConfirm).not.toHaveBeenCalled();
149143
expect(mockUpdateWord).not.toHaveBeenCalled();
150-
expect(mockDispatch).not.toHaveBeenCalled();
151144

152145
// Click the cancel button and confirm the cancel
153146
await act(async () => {
@@ -164,7 +157,6 @@ describe("EditDialog", () => {
164157
expect(mockClose).toHaveBeenCalledTimes(1);
165158
expect(mockConfirm).not.toHaveBeenCalled();
166159
expect(mockUpdateWord).not.toHaveBeenCalled();
167-
expect(mockDispatch).not.toHaveBeenCalled();
168160
});
169161

170162
test("save button closes if no changes", async () => {
@@ -180,7 +172,6 @@ describe("EditDialog", () => {
180172
expect(mockClose).toHaveBeenCalledTimes(1);
181173
expect(mockConfirm).not.toHaveBeenCalled();
182174
expect(mockUpdateWord).not.toHaveBeenCalled();
183-
expect(mockDispatch).not.toHaveBeenCalled();
184175
});
185176

186177
test("save button saves changes and closes", async () => {
@@ -207,7 +198,6 @@ describe("EditDialog", () => {
207198
expect(mockUpdateWord).toHaveBeenCalledTimes(1);
208199
const updatedWord: Word = mockUpdateWord.mock.calls[0][0];
209200
expect(updatedWord.flag.text).toEqual(newFlagText);
210-
expect(mockDispatch).toHaveBeenCalled();
211201
});
212202
});
213203

src/goals/ReviewEntries/ReviewEntriesTable/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
setReviewEntriesColumnOrder,
2626
setReviewEntriesColumnVisibility,
2727
} from "components/Project/ProjectActions";
28+
import { asyncUpdateEntry } from "goals/Redux/GoalActions";
2829
import * as Cell from "goals/ReviewEntries/ReviewEntriesTable/Cells";
2930
import * as ff from "goals/ReviewEntries/ReviewEntriesTable/filterFn";
3031
import * as sf from "goals/ReviewEntries/ReviewEntriesTable/sortingFn";
@@ -173,9 +174,11 @@ export default function ReviewEntriesTable(props: {
173174
});
174175
};
175176

176-
/** Replaces word (`.id === oldId`) in the state
177+
/** Adds the word update to the current Goal, then
178+
* replaces word (`.id === oldId`) in the state
177179
* with word (`.id === newId`) fetched from the backend. */
178180
const replaceWord = async (oldId: string, newId: string): Promise<void> => {
181+
await dispatch(asyncUpdateEntry(oldId, newId));
179182
const newWord = await getWord(newId);
180183
setData((prev) => {
181184
// Prevent table from jumping back to first page

0 commit comments

Comments
 (0)