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

Clean up goal redux to match other redux #2974

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/components/App/DefaultState.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defaultState as goalTimelineState } from "components/GoalTimeline/DefaultState";
import { defaultState as loginState } from "components/Login/Redux/LoginReduxTypes";
import { defaultState as currentProjectState } from "components/Project/ProjectReduxTypes";
import { defaultState as exportProjectState } from "components/ProjectExport/Redux/ExportProjectReduxTypes";
import { defaultState as pronunciationsState } from "components/Pronunciations/Redux/PronunciationsReduxTypes";
import { defaultState as treeViewState } from "components/TreeView/Redux/TreeViewReduxTypes";
import { defaultState as characterInventoryState } from "goals/CharacterInventory/Redux/CharacterInventoryReduxTypes";
import { defaultState as mergeDuplicateGoal } from "goals/MergeDuplicates/Redux/MergeDupsReduxTypes";
import { defaultState as goalsState } from "goals/Redux/GoalReduxTypes";
import { defaultState as reviewEntriesState } from "goals/ReviewEntries/Redux/ReviewEntriesReduxTypes";
import { defaultState as analyticsState } from "types/Redux/analyticsReduxTypes";

Expand All @@ -23,7 +23,7 @@ export const defaultState = {
pronunciationsState: { ...pronunciationsState },

//goal timeline and current goal
goalsState: { ...goalTimelineState },
goalsState: { ...goalsState },

//merge duplicates goal and review deferred duplicates goal
mergeDuplicateGoal: { ...mergeDuplicateGoal },
Expand Down
5 changes: 1 addition & 4 deletions src/components/GoalTimeline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { useTranslation } from "react-i18next";

import { getCurrentPermissions, getGraylistEntries } from "backend";
import GoalList from "components/GoalTimeline/GoalList";
import {
asyncAddGoal,
asyncGetUserEdits,
} from "components/GoalTimeline/Redux/GoalActions";
import { asyncAddGoal, asyncGetUserEdits } from "goals/Redux/GoalActions";
import { StoreState } from "types";
import { Goal, GoalType } from "types/goals";
import { useAppDispatch, useAppSelector } from "types/hooks";
Expand Down
18 changes: 9 additions & 9 deletions src/components/GoalTimeline/tests/GoalRedux.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,6 @@ import "tests/reactI18nextMock";
import { Edit, MergeUndoIds, Permission, User, UserEdit } from "api/models";
import * as LocalStorage from "backend/localStorage";
import GoalTimeline from "components/GoalTimeline";
import {
addCharInvChangesToGoal,
addCompletedMergeToGoal,
asyncAddGoal,
asyncAdvanceStep,
asyncGetUserEdits,
asyncUpdateGoal,
setCurrentGoal,
} from "components/GoalTimeline/Redux/GoalActions";
import {
CharacterChange,
CharacterStatus,
Expand All @@ -28,6 +19,15 @@ import {
ReviewDeferredDups,
} from "goals/MergeDuplicates/MergeDupsTypes";
import { goalDataMock } from "goals/MergeDuplicates/Redux/tests/MergeDupsDataMock";
import {
addCharInvChangesToGoal,
addCompletedMergeToGoal,
asyncAddGoal,
asyncAdvanceStep,
asyncGetUserEdits,
asyncUpdateGoal,
setCurrentGoal,
} from "goals/Redux/GoalActions";
import { setupStore } from "store";
import { GoalStatus, GoalType } from "types/goals";
import { Path } from "types/path";
Expand Down
8 changes: 4 additions & 4 deletions src/components/GoalTimeline/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import "tests/reactI18nextMock";

import { Permission } from "api/models";
import GoalTimeline, { createSuggestionData } from "components/GoalTimeline";
import { defaultState } from "components/GoalTimeline/DefaultState";
import { Goal, GoalType, GoalsState } from "types/goals";
import { type GoalsState, defaultState } from "goals/Redux/GoalReduxTypes";
import { Goal, GoalType } from "types/goals";
import { goalTypeToGoal } from "utilities/goalUtilities";

jest.mock("backend", () => ({
getCurrentPermissions: () => mockGetCurrentPermissions(),
getGraylistEntries: (maxLists: number) => mockGetGraylistEntries(maxLists),
}));
jest.mock("components/GoalTimeline/Redux/GoalActions", () => ({
jest.mock("components/Pronunciations/Recorder");
jest.mock("goals/Redux/GoalActions", () => ({
asyncAddGoal: (goal: Goal) => mockChooseGoal(goal),
asyncGetUserEdits: () => jest.fn(),
}));
jest.mock("components/Pronunciations/Recorder");
jest.mock("types/hooks", () => {
return {
...jest.requireActual("types/hooks"),
Expand Down
2 changes: 1 addition & 1 deletion src/components/ProjectScreen/CreateProjectActions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { WritingSystem } from "api/models";
import { createProject, finishUploadLift, getProject } from "backend";
import router from "browserRouter";
import { asyncCreateUserEdits } from "components/GoalTimeline/Redux/GoalActions";
import { setNewCurrentProject } from "components/Project/ProjectActions";
import { asyncCreateUserEdits } from "goals/Redux/GoalActions";
import { StoreStateDispatch } from "types/Redux/actions";
import { Path } from "types/path";
import { newProject } from "types/project";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { Action, PayloadAction } from "@reduxjs/toolkit";
import { Project } from "api/models";
import { getFrontierWords } from "backend";
import router from "browserRouter";
import {
addCharInvChangesToGoal,
asyncUpdateGoal,
} from "components/GoalTimeline/Redux/GoalActions";
import { asyncUpdateCurrentProject } from "components/Project/ProjectActions";
import {
CharacterStatus,
Expand All @@ -27,6 +23,10 @@ import {
CharacterSetEntry,
getCharacterStatus,
} from "goals/CharacterInventory/Redux/CharacterInventoryReduxTypes";
import {
addCharInvChangesToGoal,
asyncUpdateGoal,
} from "goals/Redux/GoalActions";
import { StoreState } from "types";
import { StoreStateDispatch } from "types/Redux/actions";
import { Path } from "types/path";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ jest.mock("backend", () => ({
getFrontierWords: (...args: any[]) => mockGetFrontierWords(...args),
}));
jest.mock("browserRouter");
jest.mock("components/GoalTimeline/Redux/GoalActions", () => ({
asyncUpdateGoal: (...args: any[]) => mockAsyncUpdateGoal(...args),
addCharInvChangesToGoal: (...args: any[]) =>
mockAddCharInvChangesToGoal(...args),
}));
jest.mock("components/Project/ProjectActions", () => ({
asyncUpdateCurrentProject: (...args: any[]) =>
mockAsyncUpdateCurrentProject(...args),
}));
jest.mock("goals/Redux/GoalActions", () => ({
asyncUpdateGoal: (...args: any[]) => mockAsyncUpdateGoal(...args),
addCharInvChangesToGoal: (...args: any[]) =>
mockAddCharInvChangesToGoal(...args),
}));

const mockAddCharInvChangesToGoal = jest.fn();
const mockAsyncUpdateCurrentProject = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion src/goals/DefaultGoal/BaseGoalScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import loadable from "@loadable/component";
import { ReactElement, useEffect } from "react";

import { setCurrentGoal } from "components/GoalTimeline/Redux/GoalActions";
import PageNotFound from "components/PageNotFound/component";
import DisplayProgress from "goals/DefaultGoal/DisplayProgress";
import Loading from "goals/DefaultGoal/Loading";
import { clearTree } from "goals/MergeDuplicates/Redux/MergeDupsActions";
import { setCurrentGoal } from "goals/Redux/GoalActions";
import { resetReviewEntries } from "goals/ReviewEntries/Redux/ReviewEntriesActions";
import { StoreState } from "types";
import { Goal, GoalStatus, GoalType } from "types/goals";
Expand Down
2 changes: 1 addition & 1 deletion src/goals/DefaultGoal/NextGoalScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ReactElement } from "react";
import { useNavigate } from "react-router-dom";

import { asyncAddGoal } from "components/GoalTimeline/Redux/GoalActions";
import PageNotFound from "components/PageNotFound/component";
import MergeDupsContinueDialog from "goals/MergeDuplicates/MergeDupsContinueDialog";
import { asyncAddGoal } from "goals/Redux/GoalActions";
import { StoreState } from "types";
import { GoalType } from "types/goals";
import { useAppDispatch, useAppSelector } from "types/hooks";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { ReactElement, useState } from "react";
import { useTranslation } from "react-i18next";

import { LoadingButton } from "components/Buttons";
import { asyncAdvanceStep } from "components/GoalTimeline/Redux/GoalActions";
import {
deferMerge,
mergeAll,
setSidebar,
} from "goals/MergeDuplicates/Redux/MergeDupsActions";
import { asyncAdvanceStep } from "goals/Redux/GoalActions";
import { useAppDispatch } from "types/hooks";
import theme from "types/theme";

Expand Down
8 changes: 4 additions & 4 deletions src/goals/MergeDuplicates/Redux/MergeDupsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { Action, PayloadAction } from "@reduxjs/toolkit";

import { Word } from "api/models";
import * as backend from "backend";
import {
addCompletedMergeToGoal,
asyncUpdateGoal,
} from "components/GoalTimeline/Redux/GoalActions";
import {
defaultSidebar,
MergeTreeReference,
Expand Down Expand Up @@ -38,6 +34,10 @@ import {
OrderSensePayload,
SetVernacularPayload,
} from "goals/MergeDuplicates/Redux/MergeDupsReduxTypes";
import {
addCompletedMergeToGoal,
asyncUpdateGoal,
} from "goals/Redux/GoalActions";
import { StoreState } from "types";
import { StoreStateDispatch } from "types/Redux/actions";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as Backend from "backend";
import { getDuplicates, getGraylistEntries } from "backend";
import { getCurrentUser, getProjectId } from "backend/localStorage";
import router from "browserRouter";
import { CharacterChange } from "goals/CharacterInventory/CharacterInventoryTypes";
import { dispatchMergeStepData } from "goals/MergeDuplicates/Redux/MergeDupsActions";
import {
addCharInvChangesToGoalAction,
addCompletedMergeToGoalAction,
Expand All @@ -15,9 +17,7 @@ import {
setGoalDataAction,
setGoalStatusAction,
updateStepFromDataAction,
} from "components/GoalTimeline/Redux/GoalReducer";
import { CharacterChange } from "goals/CharacterInventory/CharacterInventoryTypes";
import { dispatchMergeStepData } from "goals/MergeDuplicates/Redux/MergeDupsActions";
} from "goals/Redux/GoalReducer";
import { EntryEdit } from "goals/ReviewEntries/ReviewEntriesTypes";
import { StoreState } from "types";
import { StoreStateDispatch } from "types/Redux/actions";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createSlice } from "@reduxjs/toolkit";

import { defaultState } from "components/GoalTimeline/DefaultState";
import {
MergeDupsData,
MergesCompleted,
} from "goals/MergeDuplicates/MergeDupsTypes";
import { defaultState } from "goals/Redux/GoalReduxTypes";
import {
EntriesEdited,
EntryEdit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Goal, GoalsState, GoalType } from "types/goals";
import { Goal, GoalType } from "types/goals";

// The representation of goals in the redux store
export interface GoalsState {
allGoalTypes: GoalType[];
currentGoal: Goal;
goalTypeSuggestions: GoalType[];
history: Goal[];
previousGoalType: GoalType;
}

// GoalType.ReviewDeferredDups is also implemented,
// but is conditionally available
Expand All @@ -15,12 +24,3 @@ export const defaultState: GoalsState = {
history: [],
previousGoalType: GoalType.Default,
};

export function emptyGoalState(): GoalsState {
return {
...defaultState,
allGoalTypes: [],
currentGoal: { ...new Goal(), guid: expect.any(String) },
goalTypeSuggestions: [],
};
}
5 changes: 1 addition & 4 deletions src/goals/ReviewEntries/Redux/ReviewEntriesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { Action, PayloadAction } from "@reduxjs/toolkit";

import { Pronunciation, Sense, Word } from "api/models";
import * as backend from "backend";
import {
addEntryEditToGoal,
asyncUpdateGoal,
} from "components/GoalTimeline/Redux/GoalActions";
import { uploadFileFromPronunciation } from "components/Pronunciations/utilities";
import { addEntryEditToGoal, asyncUpdateGoal } from "goals/Redux/GoalActions";
import {
deleteWordAction,
resetReviewEntriesAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jest.mock("backend", () => ({
updateWord: (word: Word) => mockUpdateWord(word),
uploadAudio: (args: any[]) => mockUploadAudio(...args),
}));
jest.mock("components/GoalTimeline/Redux/GoalActions", () => ({
jest.mock("goals/Redux/GoalActions", () => ({
addEntryEditToGoal: () => jest.fn(),
asyncUpdateGoal: () => jest.fn(),
}));
Expand Down
2 changes: 1 addition & 1 deletion src/goals/ReviewEntries/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jest.mock("backend", () => ({
getFrontierWords: (...args: any[]) => mockGetFrontierWords(...args),
}));
jest.mock("components/TreeView", () => "div");
jest.mock("components/GoalTimeline/Redux/GoalActions", () => ({}));
jest.mock("goals/Redux/GoalActions", () => ({}));
jest.mock("types/hooks", () => ({
useAppDispatch: () => jest.fn(),
}));
Expand Down
2 changes: 1 addition & 1 deletion src/rootReducer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { combineReducers, Reducer } from "redux";

import goalsReducer from "components/GoalTimeline/Redux/GoalReducer";
import loginReducer from "components/Login/Redux/LoginReducer";
import projectReducer from "components/Project/ProjectReducer";
import exportProjectReducer from "components/ProjectExport/Redux/ExportProjectReducer";
import pronunciationsReducer from "components/Pronunciations/Redux/PronunciationsReducer";
import treeViewReducer from "components/TreeView/Redux/TreeViewReducer";
import characterInventoryReducer from "goals/CharacterInventory/Redux/CharacterInventoryReducer";
import mergeDupStepReducer from "goals/MergeDuplicates/Redux/MergeDupsReducer";
import goalsReducer from "goals/Redux/GoalReducer";
import reviewEntriesReducer from "goals/ReviewEntries/Redux/ReviewEntriesReducer";
import { StoreState } from "types";
import analyticsReducer from "types/Redux/analytics";
Expand Down
25 changes: 8 additions & 17 deletions src/types/goals.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { v4 } from "uuid";

import { User } from "api/models";
import { type User } from "api/models";
import {
CharInvChanges,
CharInvData,
CharInvStepData,
type CharInvChanges,
type CharInvData,
type CharInvStepData,
} from "goals/CharacterInventory/CharacterInventoryTypes";
import {
MergeDupsData,
MergeStepData,
MergesCompleted,
type MergeDupsData,
type MergeStepData,
type MergesCompleted,
} from "goals/MergeDuplicates/MergeDupsTypes";
import { EntriesEdited } from "goals/ReviewEntries/ReviewEntriesTypes";
import { type EntriesEdited } from "goals/ReviewEntries/ReviewEntriesTypes";
import { newUser } from "types/user";

export type GoalData = CharInvData | MergeDupsData;
Expand All @@ -23,15 +23,6 @@ export interface GoalProps {
goal?: Goal;
}

// The representation of goals in the redux store
export interface GoalsState {
allGoalTypes: GoalType[];
currentGoal: Goal;
goalTypeSuggestions: GoalType[];
history: Goal[];
previousGoalType: GoalType;
}

// The enum value is a permanent id for UserEdits and should not be changed.
export enum GoalType {
Default = -1,
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { PronunciationsState } from "components/Pronunciations/Redux/Pronunciati
import { TreeViewState } from "components/TreeView/Redux/TreeViewReduxTypes";
import { CharacterInventoryState } from "goals/CharacterInventory/Redux/CharacterInventoryReduxTypes";
import { MergeTreeState } from "goals/MergeDuplicates/Redux/MergeDupsReduxTypes";
import { GoalsState } from "goals/Redux/GoalReduxTypes";
import { ReviewEntriesState } from "goals/ReviewEntries/Redux/ReviewEntriesReduxTypes";
import { AnalyticsState } from "types/Redux/analyticsReduxTypes";
import { GoalsState } from "types/goals";

//root store structure
export interface StoreState {
Expand Down
Loading