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 2 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,4 +1,4 @@
import { defaultState as goalTimelineState } from "components/GoalTimeline/DefaultState";
import { defaultState as goalsState } from "components/GoalTimeline/Redux/GoalReduxTypes";
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";
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
2 changes: 1 addition & 1 deletion src/components/GoalTimeline/Redux/GoalReducer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice } from "@reduxjs/toolkit";

import { defaultState } from "components/GoalTimeline/DefaultState";
import { defaultState } from "components/GoalTimeline/Redux/GoalReduxTypes";
import {
MergeDupsData,
MergesCompleted,
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: [],
};
}
7 changes: 5 additions & 2 deletions src/components/GoalTimeline/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ 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 "components/GoalTimeline/Redux/GoalReduxTypes";
import { Goal, GoalType } from "types/goals";
import { goalTypeToGoal } from "utilities/goalUtilities";

jest.mock("backend", () => ({
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
@@ -1,3 +1,4 @@
import { GoalsState } from "components/GoalTimeline/Redux/GoalReduxTypes";
import { LoginState } from "components/Login/Redux/LoginReduxTypes";
import { CurrentProjectState } from "components/Project/ProjectReduxTypes";
import { ExportProjectState } from "components/ProjectExport/Redux/ExportProjectReduxTypes";
Expand All @@ -7,7 +8,6 @@ import { CharacterInventoryState } from "goals/CharacterInventory/Redux/Characte
import { MergeTreeState } from "goals/MergeDuplicates/Redux/MergeDupsReduxTypes";
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