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

Task 178 next month switch #143

Merged
merged 9 commits into from
Jan 6, 2021
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
1 change: 1 addition & 0 deletions cypress/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixtures/grafik.xlsx
Binary file modified cypress/fixtures/grafik.xlsx
Binary file not shown.
3 changes: 3 additions & 0 deletions cypress/integration/e2e/table/range-selection-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ const foundationTestCases: FoundationTestCase[] = [
},
];

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function validateHorizontalShifts(
workerType: WorkerType,
workerIdx: number,
Expand All @@ -164,6 +165,7 @@ function validateHorizontalShifts(
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function validateVerticalShifts(
workerType: WorkerType,
shiftIdx: number,
Expand All @@ -181,6 +183,7 @@ function validateVerticalShifts(
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function validateChange({ startShiftCell, endShiftCell, desiredShiftCode }: WorkerTestCase) {
const {
workerType: startWorkerType,
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/e2e/table/undo-redo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const testCases: TestCase[] = [
},
];

function performShiftChanges(testCase) {
function performShiftChanges(testCase: TestCase): void {
cy.changeWorkerShift({ ...testCase.testedShiftCell, newShiftCode: testCase.firstShift });
cy.changeWorkerShift({ ...testCase.testedShiftCell, newShiftCode: testCase.secondShift });
}
Expand Down
Empty file.
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"@types/lodash": "^4.14.167",
"@types/pouchdb": "^6.4.0",
"axios": "^0.20.0",
"classnames": "^2.2.6",
Expand Down
17 changes: 10 additions & 7 deletions src/components/common-components/month-switch/use-actual-month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ import { useSelector } from "react-redux";
import { StringHelper } from "../../../helpers/string.helper";
import { ApplicationStateModel } from "../../../state/models/application-state.model";
import { TranslationHelper } from "../../../helpers/translations.helper";
import { useEffect, useState } from "react";

export function useActualMonth(): string {
/* eslint-disable @typescript-eslint/camelcase */
const { month_number, year } = useSelector(
(state: ApplicationStateModel) => state.actualState.temporarySchedule.present.schedule_info
);

let actualMonth = "";
if (month_number && year) {
actualMonth = StringHelper.capitalize(
`${TranslationHelper.polishMonths[month_number]} ${year}`
);
}
const [actualMonth, setActualMonth] = useState<string>("");
useEffect(() => {
if (month_number && year) {
const month = StringHelper.capitalize(
`${TranslationHelper.polishMonths[month_number]} ${year}`
);
setActualMonth(month);
}
}, [month_number, year]);
return actualMonth;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import UndoIcon from "@material-ui/icons/Undo";
import RedoIcon from "@material-ui/icons/Redo";
import { ScheduleLogicContext } from "../table/schedule/use-schedule-state";
import { UndoActionCreator } from "../../../state/reducers/undoable.action-creator";
import { TEMPORARY_SCHEDULE_UNDOABLE_CONFIG } from "../../../state/reducers/month-state/schedule-data/temporary-schedule.reducer";
import { TEMPORARY_SCHEDULE_UNDOABLE_CONFIG } from "../../../state/reducers/month-state/schedule-data/schedule.actions";

interface EditPageToolbarOptions {
closeEdit: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ScheduleComponent } from "../table/schedule/schedule.component";
import { ScheduleLogicContext, useScheduleState } from "../table/schedule/use-schedule-state";
import { EditPageToolbar } from "./edit-page-toolbar.component";
import { UndoableHotkeys } from "../../common-components";
import { TEMPORARY_SCHEDULE_UNDOABLE_CONFIG } from "../../../state/reducers/month-state/schedule-data/temporary-schedule.reducer";
import { TEMPORARY_SCHEDULE_UNDOABLE_CONFIG } from "../../../state/reducers/month-state/schedule-data/schedule.actions";

interface ScheduleEditPageOptions {
closeEdit: () => void;
Expand Down
12 changes: 11 additions & 1 deletion src/components/schedule-page/new-month-page.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import React from "react";
import { useDispatch } from "react-redux";
import { ScheduleDataActionCreator } from "../../state/reducers/month-state/schedule-data/schedule-data.action-creator";
import { Button } from "../common-components";
import { useActualMonth } from "../common-components/month-switch/use-actual-month";

export function NewMonthPlanComponent(): JSX.Element {
const actualMonth = useActualMonth();
const dispatch = useDispatch();
return (
<>
<div className={"newMonthComponents"}>
Expand All @@ -16,7 +19,14 @@ export function NewMonthPlanComponent(): JSX.Element {
/>
<p>Nie masz planu na ten miesiąc</p>
<div className={"newPageButtonsPane"}>
<Button size="small" className="submit-button" variant="outlined">
<Button
onClick={(): void => {
dispatch(ScheduleDataActionCreator.copyPreviousMonth());
}}
size="small"
className="submit-button"
variant="outlined"
>
Kopiuj plan z {actualMonth}
</Button>
<Button size="small" className="submit-button" variant="primary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ScheduleComponent } from "../table/schedule/schedule.component";
import { ScheduleLogicContext, useScheduleState } from "../table/schedule/use-schedule-state";
import { ViewOnlyToolbar } from "./view-only-toolbar";
import { UndoableHotkeys } from "../../common-components";
import { PERSISTENT_SCHEDULE_UNDOABLE_CONFIG } from "../../../state/reducers/month-state/schedule-data/persistent-schedule.reducer";
import { PERSISTENT_SCHEDULE_UNDOABLE_CONFIG } from "../../../state/reducers/month-state/schedule-data/schedule.actions";

interface ScheduleViewOnlyPageOptions {
openEdit: () => void;
Expand Down
6 changes: 2 additions & 4 deletions src/logic/schedule-logic/schedule.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import { SelectionMatrix } from "../../components/schedule-page/table/schedule/s
import { ShiftHelper } from "../../helpers/shifts.helper";
import { StringHelper } from "../../helpers/string.helper";
import { ApplicationStateModel } from "../../state/models/application-state.model";
import {
ScheduleActionModel,
ScheduleDataActionCreator,
} from "../../state/reducers/month-state/schedule-data/schedule-data.action-creator";
import { ScheduleDataActionCreator } from "../../state/reducers/month-state/schedule-data/schedule-data.action-creator";
import { ScheduleActionModel } from "../../state/reducers/month-state/schedule-data/schedule.actions";
import { FoundationInfoOptions } from "../providers/foundation-info-provider.model";
import { Schedule, ScheduleProvider, Sections } from "../providers/schedule-provider.model";
import { ChildrenSectionKey, ExtraWorkersSectionKey } from "../section.model";
Expand Down
23 changes: 13 additions & 10 deletions src/state/app.reducer.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { combineReducers } from "redux";
import { ActionModel } from "./models/action.model";
import { ApplicationStateModel, MonthStateModel } from "./models/application-state.model";
import { scheduleErrorsReducer } from "./reducers/month-state/schedule-errors.reducer";
import undoable from "redux-undo";
import { ActionModel } from "./models/action.model";
import { MonthStateModel, ApplicationStateModel } from "./models/application-state.model";
import { historyReducer } from "./reducers/history.reducer";
import {
persistentScheduleReducer,
PERSISTENT_SCHEDULE_UNDOABLE_CONFIG,
} from "./reducers/month-state/schedule-data/persistent-schedule.reducer";
import {
temporaryScheduleReducer,
TEMPORARY_SCHEDULE_UNDOABLE_CONFIG,
} from "./reducers/month-state/schedule-data/temporary-schedule.reducer";
} from "./reducers/month-state/schedule-data/schedule.actions";
import { scheduleReducerF } from "./reducers/month-state/schedule-data/schedule.reducer";
import { scheduleErrorsReducer } from "./reducers/month-state/schedule-errors.reducer";

export type CombinedReducers<StateModel> = {
[key in keyof StateModel]: <T, U>(state: T, action: ActionModel<U>) => T;
};

export const PERSISTENT_SCHEDULE_NAME: ScheduleActionDestination = "PERSISTENT";
export const TEMPORARY_SCHEDULE_NAME: ScheduleActionDestination = "TEMPORARY";

export type ScheduleActionDestination = "PERSISTENT" | "TEMPORARY";

const monthStateReducer = combineReducers({
persistentSchedule: undoable(persistentScheduleReducer, {
persistentSchedule: undoable(scheduleReducerF(PERSISTENT_SCHEDULE_NAME), {
limit: 50,
...PERSISTENT_SCHEDULE_UNDOABLE_CONFIG,
}),
temporarySchedule: undoable(temporaryScheduleReducer, {
temporarySchedule: undoable(scheduleReducerF(TEMPORARY_SCHEDULE_NAME), {
limit: 50,
...TEMPORARY_SCHEDULE_UNDOABLE_CONFIG,
}),
Expand Down
38 changes: 22 additions & 16 deletions src/state/reducers/month-state/employee-info.reducer.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { WorkersInfoModel } from "../../../common-models/worker-info.model";
import { scheduleDataInitialState } from "./schedule-data/schedule-data-initial-state";
import { ScheduleActionModel } from "./schedule-data/schedule-data.action-creator";
import { TemporaryScheduleActionType } from "./schedule-data/temporary-schedule.reducer";
import {
ScheduleActionModel,
createActionName,
ScheduleActionType,
} from "./schedule-data/schedule.actions";

/* eslint-disable @typescript-eslint/camelcase */
export function employeeInfoReducer(
state: WorkersInfoModel = scheduleDataInitialState.employee_info,
action: ScheduleActionModel
): WorkersInfoModel {
const data = action.payload?.employee_info;
if (!data) return state;
switch (action.type) {
case TemporaryScheduleActionType.ADD_NEW:
return { ...data };
case TemporaryScheduleActionType.UPDATE:
return { ...state, ...data };
default:
return state;
}
export function employeeInfoReducerF(name: string) {
return (
state: WorkersInfoModel = scheduleDataInitialState.employee_info,
action: ScheduleActionModel
): WorkersInfoModel => {
const data = action.payload?.employee_info;
if (!data) return state;
switch (action.type) {
case createActionName(name, ScheduleActionType.ADD_NEW):
return { ...data };
case createActionName(name, ScheduleActionType.UPDATE):
return { ...state, ...data };
default:
return state;
}
};
}
53 changes: 33 additions & 20 deletions src/state/reducers/month-state/month-info.reducer.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,40 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import { ScheduleKey } from "../../../api/persistance-store.model";
import { MonthInfoModel } from "../../../common-models/month-info.model";
import { ActionModel } from "../../models/action.model";
import { copyMonthInfo } from "./schedule-data/common-reducers";
import { scheduleDataInitialState } from "./schedule-data/schedule-data-initial-state";
import { ScheduleActionModel } from "./schedule-data/schedule-data.action-creator";
import { TemporaryScheduleActionType } from "./schedule-data/temporary-schedule.reducer";
import {
ScheduleActionModel,
createActionName,
ScheduleActionType,
isScheduleAction,
} from "./schedule-data/schedule.actions";

/* eslint-disable @typescript-eslint/camelcase */
export function monthInfoReducer(
state: MonthInfoModel = scheduleDataInitialState.month_info,
action: ScheduleActionModel
): MonthInfoModel {
const data = action.payload?.month_info;
if (!data) {
return state;
}
switch (action.type) {
case TemporaryScheduleActionType.ADD_NEW:
return { ...data };
case TemporaryScheduleActionType.UPDATE:
return { ...state, ...data };
default:
return state;
}
export function monthInfoReducerF(name: string) {
return (
state: MonthInfoModel = scheduleDataInitialState.month_info,
action: ScheduleActionModel | ActionModel<ScheduleKey>
): MonthInfoModel => {
switch (action.type) {
case createActionName(name, ScheduleActionType.ADD_NEW):
case createActionName(name, ScheduleActionType.UPDATE):
if (!isScheduleAction(action)) {
return state;
}
const data = action.payload?.month_info;
if (!data) {
return state;
}
return { ...data };
case createActionName(name, ScheduleActionType.COPY_TO_MONTH):
const { month, year } = action.payload as ScheduleKey;
return copyMonthInfo(month, year, state);
default:
return state;
}
};
}
/* eslint-enable @typescript-eslint/camelcase */
46 changes: 46 additions & 0 deletions src/state/reducers/month-state/schedule-data/common-reducers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable @typescript-eslint/camelcase */
import _ from "lodash";
import { MonthInfoModel } from "../../../../common-models/month-info.model";
import { ShiftCode, ShiftInfoModel } from "../../../../common-models/shift-info.model";

export function daysInMonth(month = 0, year = 0): number[] {
Qwebeck marked this conversation as resolved.
Show resolved Hide resolved
let day = 1;
const result = [day];
let date = new Date(year, month, day);
while (month === date.getMonth()) {
day++;
date = new Date(year, month, day);
result.push(day);
}
return result;
}
export function copyShiftstoMonth(
Qwebeck marked this conversation as resolved.
Show resolved Hide resolved
month: number,
year: number,
shifts: ShiftInfoModel
): ShiftInfoModel {
const days = daysInMonth(month, year).length;
const copiedShifts = _.cloneDeep(shifts);
Object.keys(copiedShifts).forEach((key) => {
const values = copiedShifts[key].slice(0, days);
copiedShifts[key] = values.map((shift) =>
[ShiftCode.L4, ShiftCode.U, ShiftCode.K].includes(shift) ? ShiftCode.W : shift
);
});
return copiedShifts;
}

export function copyMonthInfo(
month: number,
year: number,
monthInfo: MonthInfoModel
): MonthInfoModel {
const days = daysInMonth(month, year);
const copiedInfo: MonthInfoModel = {
children_number: monthInfo.children_number?.slice(0, days.length),
extra_workers: monthInfo.extra_workers?.slice(0, days.length),
dates: days,
frozen_shifts: [],
};
return copiedInfo;
}
Loading