Skip to content

Commit

Permalink
Merge branch 'master' into merge-stack-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
imnasnainaec authored Jan 12, 2021
2 parents b612c6c + d0e95ea commit 21c3357
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 134 deletions.
2 changes: 1 addition & 1 deletion src/components/App/DefaultState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { defaultState as reviewEntriesState } from "../../goals/ReviewEntries/Re
import { defaultProject } from "../../types/project";
import { defaultState as loginState } from "../Login/LoginReducer";
import { defaultState as goalTimelineState } from "../GoalTimeline/DefaultState";
import { defaultState as goalSelectorState } from "../GoalTimeline/GoalSwitcher/GoalSelectorScroll/GoalSelectorReducer";
import { defaultState as goalSelectorState } from "../GoalTimeline/GoalSelectorScroll/GoalSelectorReducer";
import { defaultState as passwordResetState } from "../PasswordReset/reducer";
import { defaultState as exportProjectState } from "../ProjectExport/ExportProjectReducer";
import { defaultState as createProjectState } from "../ProjectScreen/CreateProject/CreateProjectReducer";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { StoreAction, StoreActions } from "../../../rootActions";
import { GoalSelectorState } from "../../../types/goals";
import {
GoalScrollAction,
SELECT_ACTION,
MOUSE_ACTION,
SELECT_ACTION,
} from "./GoalSelectorAction";
import { GoalSelectorState } from "../../../../types/goals";
import { StoreAction, StoreActions } from "../../../../rootActions";

export const defaultState: GoalSelectorState = {
selectedIndex: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { ReactElement } from "react";

import Card from "@material-ui/core/Card";
import { Button, CardContent, Typography } from "@material-ui/core";
import { Goal, GoalName } from "../../../../types/goals";
import React, { ReactElement } from "react";
import {
LocalizeContextProps,
withLocalize,
Translate,
withLocalize,
} from "react-localize-redux";
import ContextMenu from "../../../ContextMenu/ContextMenu";
import { styleAddendum } from "../../../../types/theme";

import { Goal, GoalName } from "../../../types/goals";
import { styleAddendum } from "../../../types/theme";
import ContextMenu from "../../ContextMenu/ContextMenu";

const CLICK_SENSITIVITY: number = 10;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import GoalSelectorScroll from "./GoalSelectorScroll";
import { connect } from "react-redux";
import { Dispatch } from "redux";

import { StoreState } from "../../../types";
import { GoalSelectorState } from "../../../types/goals";
import {
GoalScrollAction,
scrollSelectorIndexAction,
scrollSelectorMouseAction,
} from "./GoalSelectorAction";

import { connect } from "react-redux";
import { StoreState } from "../../../../types";
import { GoalSelectorState } from "../../../../types/goals";
import { Dispatch } from "redux";
import GoalSelectorScroll from "./GoalSelectorScroll";

export function mapStateToProps(state: StoreState): GoalSelectorState {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
SELECT_ACTION,
GoalScrollAction,
MOUSE_ACTION,
SELECT_ACTION,
scrollSelectorIndexAction,
scrollSelectorMouseAction,
MOUSE_ACTION,
} from "../GoalSelectorAction";

const VAL = 5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { goalSelectReducer, defaultState } from "../GoalSelectorReducer";
import { StoreActions, StoreAction } from "../../../../rootActions";
import { GoalSelectorState } from "../../../../types/goals";
import {
SELECT_ACTION,
GoalScrollAction,
MOUSE_ACTION,
SELECT_ACTION,
} from "../GoalSelectorAction";
import { GoalSelectorState } from "../../../../../types/goals";
import { StoreActions, StoreAction } from "../../../../../rootActions";
import { defaultState, goalSelectReducer } from "../GoalSelectorReducer";

const VAL = 5;
const scrollAct: GoalScrollAction = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import renderer, {
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";

import { Goal, GoalName, GoalSelectorState } from "../../../../../types/goals";
import { User } from "../../../../../types/user";
import { Goal, GoalName, GoalSelectorState } from "../../../../types/goals";
import { User } from "../../../../types/user";
import GoalSelectorScroll from "../";
import {
GoalScrollAction,
Expand Down
38 changes: 0 additions & 38 deletions src/components/GoalTimeline/GoalSwitcher/GoalSwitcherComponent.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions src/components/GoalTimeline/GoalSwitcher/index.tsx

This file was deleted.

This file was deleted.

10 changes: 4 additions & 6 deletions src/components/GoalTimeline/GoalsActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { ValidateChars } from "../../goals/ValidateChars/ValidateChars";
import { ValidateStrWords } from "../../goals/ValidateStrWords/ValidateStrWords";
import history, { Path } from "../../history";
import { StoreState } from "../../types";
import { Goal, GoalType } from "../../types/goals";
import { Goal, GoalType, maxNumSteps } from "../../types/goals";
import { ActionWithPayload } from "../../types/mockAction";
import { User } from "../../types/user";
import { Edit } from "../../types/userEdit";
Expand Down Expand Up @@ -130,8 +130,8 @@ export function loadGoalData(goal: Goal) {
usedIDs.push(...groupIds);
}

// Stop the process once numSteps many groups found.
if (newGroups.length === goal.numSteps) {
// Stop the process once maxNumSteps many groups found.
if (newGroups.length === maxNumSteps(goal.goalType)) {
break;
}
}
Expand All @@ -157,9 +157,7 @@ export function loadGoalData(goal: Goal) {
export function updateStepData(goal: Goal): Goal {
switch (goal.goalType) {
case GoalType.MergeDups: {
let currentGoalData: MergeDupData = JSON.parse(
JSON.stringify(goal.data as MergeDupData)
);
const currentGoalData = goal.data as MergeDupData;
goal.steps[goal.currentStep] = {
words: currentGoalData.plannedWords[goal.currentStep],
};
Expand Down
20 changes: 13 additions & 7 deletions src/components/GoalTimeline/tests/GoalTimelineActions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import thunk from "redux-thunk";
import * as LocalStorage from "../../../backend/localStorage";
import { CreateCharInv } from "../../../goals/CreateCharInv/CreateCharInv";
import { HandleFlags } from "../../../goals/HandleFlags/HandleFlags";
import { MergeDups, MergeDupData } from "../../../goals/MergeDupGoal/MergeDups";
import {
MergeTreeActions,
MergeDupData,
MergeDups,
MergeStepData,
} from "../../../goals/MergeDupGoal/MergeDups";
import {
MergeTreeAction,
MergeTreeActions,
} from "../../../goals/MergeDupGoal/MergeDupStep/MergeDupStepActions";
import { goalDataMock } from "../../../goals/MergeDupGoal/MergeDupStep/tests/MockMergeDupData";
import { ReviewEntries } from "../../../goals/ReviewEntries/ReviewEntries";
import { Goal } from "../../../types/goals";
import { Goal, maxNumSteps } from "../../../types/goals";
import { User } from "../../../types/user";
import { UserEdit } from "../../../types/userEdit";
import { defaultState as goalsDefaultState } from "../DefaultState";
Expand Down Expand Up @@ -198,7 +202,7 @@ describe("Test GoalsActions", () => {

it("should dispatch UPDATE_GOAL and SET_DATA", async () => {
let goalToUpdate: Goal = new MergeDups();
goalToUpdate.numSteps = 8;
goalToUpdate.numSteps = maxNumSteps(goalToUpdate.goalType);
goalToUpdate.steps = [
{
words: [...goalDataMock.plannedWords[0]],
Expand Down Expand Up @@ -287,14 +291,16 @@ describe("Test GoalsActions", () => {
});

it("Should update the step data of a goal", () => {
const goal: MergeDups = new MergeDups();
const goal = new MergeDups();
goal.data = goalDataMock;
expect(goal.steps).toEqual([]);
expect(goal.currentStep).toEqual(0);

const updatedGoal: MergeDups = actions.updateStepData(goal) as MergeDups;
const updatedGoal = actions.updateStepData(goal);

expect(updatedGoal.steps[0].words).toEqual(goal.data.plannedWords[0]);
expect((updatedGoal.steps[0] as MergeStepData).words).toEqual(
(goal.data as MergeDupData).plannedWords[0]
);
expect(updatedGoal.currentStep).toEqual(0);
});

Expand Down
1 change: 0 additions & 1 deletion src/goals/MergeDupGoal/MergeDups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ export class MergeDups extends Goal {
data: MergeDupData = { plannedWords: [[]] }
) {
super(GoalType.MergeDups, GoalName.MergeDups, steps, data);
this.numSteps = 8;
}
}
2 changes: 1 addition & 1 deletion src/rootReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { localizeReducer } from "react-localize-redux";
import { combineReducers, Reducer } from "redux";

import { goalsReducer } from "./components/GoalTimeline/GoalsReducer";
import { goalSelectReducer } from "./components/GoalTimeline/GoalSwitcher/GoalSelectorScroll/GoalSelectorReducer";
import { goalSelectReducer } from "./components/GoalTimeline/GoalSelectorScroll/GoalSelectorReducer";
import { loginReducer } from "./components/Login/LoginReducer";
import { passwordResetReducer } from "./components/PasswordReset/reducer";
import { projectReducer } from "./components/Project/ProjectReducer";
Expand Down
9 changes: 9 additions & 0 deletions src/types/goals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ export enum GoalName {
ValidateStrWords = "validateStrWords",
}

export function maxNumSteps(type: GoalType) {
switch (type) {
case GoalType.MergeDups:
return 8;
default:
return 1;
}
}

export class Goal {
goalType: GoalType;
name: GoalName;
Expand Down

0 comments on commit 21c3357

Please sign in to comment.