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

Revert "TASK-308 Evaluate working time issues on frontend (#233)" #240

Merged
merged 1 commit into from
Feb 26, 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
14 changes: 2 additions & 12 deletions src/api/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* 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 axios, { AxiosInstance } from "axios";
import { v4 as uuidv4 } from "uuid";
import { ScheduleDataModel } from "../common-models/schedule-data.model";
import { AlgorithmErrorCode, ScheduleError } from "../common-models/schedule-error.model";
import { ScheduleError } from "../common-models/schedule-error.model";
import { SHIFTS } from "../common-models/shift-info.model";
import { v4 as uuidv4 } from "uuid";

interface BackendErrorObject extends Omit<ScheduleError, "kind"> {
code: string;
Expand All @@ -21,13 +21,6 @@ function escapeJuliaIndexes(error: ScheduleError): ScheduleError {
return error;
}

function isUnderTimeAndOvertimeErrors(error: ScheduleError): boolean {
return (
error.kind === AlgorithmErrorCode.WorkerOvertime ||
error.kind === AlgorithmErrorCode.WorkerUnderTime
);
}

type NameUuidMapper = {
[name: string]: string;
};
Expand Down Expand Up @@ -82,9 +75,6 @@ class Backend {
.then((resp) => resp.data.map((el: BackendErrorObject) => ({ ...el, kind: el.code })))
.then((errors) => errors.map(escapeJuliaIndexes))
.then((errors) => errors.map(this.remapUsernames))
.then((errors: ScheduleError[]) =>
errors.filter((err) => !isUnderTimeAndOvertimeErrors(err))
)
);
}

Expand Down
1 change: 0 additions & 1 deletion src/common-models/schedule-data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export function extendMonthDMToScheduleDM(
shifts[key] = extendSchedule("shifts", key, ShiftCode.W);
});

debugger;
const monthInfoModel: MonthInfoModel = {
children_number: extendSchedule("month_info", "children_number", 0),
extra_workers: extendSchedule("month_info", "extra_workers", 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export function ErrorTooltipProvider({
placement: "right-start",
}
);
const { mode } = useSelector((state: ApplicationStateModel) => state.actualState);

const [isFixed, setIsFixed] = useState(false);

Expand All @@ -76,13 +75,13 @@ export function ErrorTooltipProvider({
hideErrorTooltip(true);
}
}
// TODO refactor

return (
<>
<Popper
ref={tooltipRef}
className="errorTooltip"
isOpen={isToolTipOpen && mode === "edit"}
isOpen={isToolTipOpen}
{...attributes.popper}
style={{
...(isToolTipOpen && errors.length !== 0 ? styles.popper : {}),
Expand Down Expand Up @@ -111,14 +110,14 @@ export function ErrorTooltipProvider({
onMouseEnter={showErrorTooltip}
onMouseLeave={(): void => hideErrorTooltip(false)}
>
{mode === "edit" && errors.length !== 0 && triangleStyle === "single" && (
{errors.length !== 0 && triangleStyle === "single" && (
<span
ref={errorTriangle}
className={classNames("error-triangle", tooltipClassname)}
onClick={handleTriangleClick}
/>
)}
{mode === "edit" && errors.length !== 0 && triangleStyle === "right" && (
{errors.length !== 0 && triangleStyle === "right" && (
<div>
<span
ref={errorTriangle}
Expand All @@ -132,21 +131,21 @@ export function ErrorTooltipProvider({
/>
</div>
)}
{mode === "edit" && errors.length > 1 && (
{errors.length > 1 && (
<span
ref={errorTriangle}
className={classNames("error-triangle", tooltipClassname)}
onClick={handleTriangleClick}
/>
)}
{mode === "edit" && errors.length !== 0 && triangleStyle === "middle" && (
{errors.length !== 0 && triangleStyle === "middle" && (
<span
ref={errorTriangle}
className={classNames("error-triangle line", tooltipClassname)}
onClick={handleTriangleClick}
/>
)}
{mode === "edit" && errors.length !== 0 && triangleStyle === "left" && (
{errors.length !== 0 && triangleStyle === "left" && (
<div>
<span
ref={errorTriangle}
Expand Down
32 changes: 8 additions & 24 deletions src/components/summarytable/summarytable-section.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +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, { useContext } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useSelector } from "react-redux";
import { WorkerType } from "../../common-models/worker-info.model";
import { ShiftHelper } from "../../helpers/shifts.helper";
import { DataRow } from "../../logic/schedule-logic/data-row";
import {
ApplicationStateModel,
ScheduleStateModel,
} from "../../state/models/application-state.model";
import { ScheduleErrorActionCreator } from "../../state/schedule-error.action-creator";
import { ScheduleLogicContext } from "../schedule-page/table/schedule/use-schedule-state";
import { SummaryTableRow } from "./summarytable-row.component";

Expand Down Expand Up @@ -43,27 +42,6 @@ export function SummaryTableSection({
(state: ApplicationStateModel) => state.actualState[scheduleKey].present.month_info
);

const dispatch = useDispatch();

function calculateSummaryTableInfo(workerName: string): number[] {
const hoursInfo = ShiftHelper.caclulateWorkHoursInfoForDates(
shifts[workerName],
time[workerName],
currentMonth,
year,
dates
);
const [, , overtime] = hoursInfo;
if (overtime !== 0) {
const updateWorkerTimeInfo = ScheduleErrorActionCreator.addUndertimeOrOvertimeError(
overtime,
workerName
);
dispatch(updateWorkerTimeInfo);
}
return hoursInfo;
}

return (
<>
<table
Expand All @@ -77,7 +55,13 @@ export function SummaryTableSection({
<SummaryTableRow
key={`${scheduleLogic?.uuid ?? 0}_${dataRow.rowKey}`}
uuid={scheduleLogic?.uuid ?? "0"}
data={calculateSummaryTableInfo(dataRow.rowKey)}
data={ShiftHelper.caclulateWorkHoursInfoForDates(
shifts[dataRow.rowKey],
time[dataRow.rowKey],
currentMonth,
year,
dates
)}
rowIndex={rowIndex}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/helpers/array.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class ArrayHelper {
} else {
updateElements = baseArr.slice(baseArr.length - numerOfElement);
}

return ArrayHelper.replace(updatedArr, updateElements, updatePosition);
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/shifts.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ShiftHelper {
const dates = VerboseDateHelper.generateVerboseDatesForMonth(month, year);
return Math.round(this.calculateRequiredHoursFromVerboseDates(dates));
}
s;

public static calculateRequiredHoursFromVerboseDates(
verboseDates: Pick<VerboseDate, "isPublicHoliday" | "dayOfWeek">[]
): number {
Expand Down
58 changes: 4 additions & 54 deletions src/state/reducers/month-state/schedule-errors.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,27 @@
* 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 _ from "lodash";
import {
AlgorithmErrorCode,
GroupedScheduleErrors,
ScheduleError,
} from "../../../common-models/schedule-error.model";
import { PERSISTENT_SCHEDULE_NAME } from "../../app.reducer";
import { GroupedScheduleErrors, ScheduleError } from "../../../common-models/schedule-error.model";
import { ActionModel } from "../../models/action.model";
import {
RemoveWorkerErrorUpdateOvertimOrUndertimePayload,
ScheduleErrorUpdateOvertimOrUndertimePayload,
} from "../../schedule-error.action-creator";
import { createActionName, ScheduleActionType } from "./schedule-data/schedule.actions";
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ScheduleActionType } from "./schedule-data/schedule.actions";

export enum ScheduleErrorActionType {
UPDATE = "updateScheduleError",
REMOVE_WORKER_OVERTIME_ERROR = "REMOVE_WORKER_OVERTIME_ERROR",
ADD_OVERTIME_OR_UNDERTIME = "ADD_OVERTIME_OR_UNDERTIME",
}

export function scheduleErrorsReducer(
state: GroupedScheduleErrors = {},
action:
| ActionModel<ScheduleError[]>
| ActionModel<ScheduleErrorUpdateOvertimOrUndertimePayload>
| ActionModel<RemoveWorkerErrorUpdateOvertimOrUndertimePayload>
action: ActionModel<ScheduleError[]>
): GroupedScheduleErrors {
switch (action.type) {
case ScheduleErrorActionType.UPDATE:
if (!action.payload) action.payload = [];
const errors = _.groupBy(action.payload as ScheduleError[], (item) => item.kind);
const errors = _.groupBy(action.payload, (item) => item.kind);
return errors;

case createActionName(PERSISTENT_SCHEDULE_NAME, ScheduleActionType.ADD_NEW):
case ScheduleActionType.CLEAN_ERRORS:
// In case if new schedule is added we should remove errors, that previously existed
return {};

case ScheduleErrorActionType.REMOVE_WORKER_OVERTIME_ERROR:
const { workerName } = action.payload as RemoveWorkerErrorUpdateOvertimOrUndertimePayload;
const removeFromState = (
code: AlgorithmErrorCode.WorkerOvertime | AlgorithmErrorCode.WorkerUnderTime
): void => {
const matchingIndex = state[code]?.findIndex((p) => p.worker === workerName);
if (!_.isNil(matchingIndex) && matchingIndex !== -1) {
delete state[code]?.[matchingIndex];
state[code] = (state[code] as any[]).filter((el) => !!el);
}
};
removeFromState(AlgorithmErrorCode.WorkerOvertime);
removeFromState(AlgorithmErrorCode.WorkerUnderTime);
return _.cloneDeep(state);

case ScheduleErrorActionType.ADD_OVERTIME_OR_UNDERTIME:
const {
kind,
hours,
worker,
} = action.payload as ScheduleErrorUpdateOvertimOrUndertimePayload;
if (state[kind] === undefined) {
state[kind] = [];
}
const error = {
kind,
hours,
worker,
};
state[kind]!.push(error as any);

return _.cloneDeep(state);

default:
return state;
}
Expand Down
53 changes: 0 additions & 53 deletions src/state/schedule-error.action-creator.ts

This file was deleted.