Skip to content

Commit

Permalink
Merge branch 'develop' into TASK-163
Browse files Browse the repository at this point in the history
  • Loading branch information
prenc authored Dec 18, 2020
2 parents ea7fd34 + 05a3b10 commit adc69e0
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint-disable @typescript-eslint/camelcase */
/// <reference types="cypress" />
import { ScheduleParser } from "../../../../../src/logic/schedule-parser/schedule.parser";
import { ScheduleDataModel } from "../../../../../src/common-models/schedule-data.model";
import { ShiftCode, ShiftInfoModel } from "../../../../../src/common-models/shift-info.model";
import { WorkersInfoModel, WorkerType } from "../../../../../src/common-models/worker-info.model";

function fillWorkerInfo(
shifts: ShiftInfoModel,
employeeInfo: WorkersInfoModel,
section: string[][],
sectionType: WorkerType
): void {
section.forEach((element) => {
shifts[element[0]] = element.slice(1).map((x) => ShiftCode[x] ?? ShiftCode.W);
employeeInfo.type[element[0]] = sectionType;
employeeInfo.time[element[0]] = 1;
});
}

//#region data declaration
const emptyRow = [""];
const dates = [28, 29, 30, 31, 1, 2, 3, 4, 5, 6];
const nurseSection = [
["pielęgniarka 1", "DN", " ", " ", " ", "U", "U", "U", "U", "U", "D"],
["pielęgniarka 2", "DN", "DN", "U", "W", "U", "U", "U", "U", "U", "D"],
["pielęgniarka 3", "N", " ", "L4", "D", "U", "U", "U", "U", "U", "D"],
["pielęgniarka 4", "U", "U", "U", "U", "D", "D", "DN", "L4", "DN", "U"],
["pielęgniarka 5", "DN", "L4", "L4", "W", "L4", "L4", "L4", "L4", "L4", "L4"],
];

const babysitterSection = [
["opiekunka 1", "L4", "L4", "L4", "L4", "L4", "D", "N", "L4", "L4", "L4"],
["opiekunka 2", "L4", "L4", "L4", "L4", "L4", "L4", "L4", "L4", "L4", "D"],
];

const exampleData = [
["Grafik ", "miesiąc listopad", "rok 2020", "ilość godz 0"],
["Dni miesiąca", ...dates.map((x) => x.toString())],
emptyRow,
["Dzieci", ...dates.map((x) => "1")],
emptyRow,
...nurseSection,
emptyRow,
...babysitterSection,
];

const shifts: ShiftInfoModel = {};
const employee_info: WorkersInfoModel = { type: {}, time: {} };

fillWorkerInfo(shifts, employee_info, nurseSection, WorkerType.NURSE);
fillWorkerInfo(shifts, employee_info, babysitterSection, WorkerType.OTHER);

const expectedSchedule: ScheduleDataModel = {
schedule_info: { month_number: 10, year: 2020, daysFromPreviousMonthExists: true },
shifts: shifts,
month_info: {
frozen_shifts: [],
children_number: dates.map((x) => 1),
dates: dates,
},
employee_info: employee_info,
};

//#endregion

describe("Schedule parser", () => {
const scheduleParser = new ScheduleParser(exampleData);
const result = scheduleParser.schedule.getDataModel();
it("check if workerType was parsed correctly ", () => {
for (const [key, value] of Object.entries(result.employee_info.type)) {
expect(expectedSchedule.employee_info.type[key]).to.equal(value);
}
});
it("length of days must be equal to length of shifts", () => {
for (const [, value] of Object.entries(result.shifts)) {
expect(value).to.have.lengthOf(result.month_info.dates.length);
}
});

it("should check if input and output shifts are equal", () => {
for (const [key, value] of Object.entries(result.shifts)) {
expect(value).to.eql(expectedSchedule.shifts[key]);
}
});
it("all babysitter and nurses are in employee_info ", () => {
expect(result.employee_info).to.have.keys(Object.keys(expectedSchedule.employee_info));
});
});
1 change: 1 addition & 0 deletions src/assets/styles/styles-all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@
@import "styles/custom/variables.module";
@import "styles/custom/workers_page";
@import "styles/custom/error-list-item";
@import "styles/custom/worker-info-drawer.scss";
1 change: 1 addition & 0 deletions src/assets/styles/styles/custom/_nametable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

color: $primary;
border-bottom: 1px solid $table-border-color-grey;
cursor: pointer;
}

.nametableRow:last-child {
Expand Down
3 changes: 3 additions & 0 deletions src/assets/styles/styles/custom/_worker-info-drawer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.worker-info > p {
margin-bottom: 0;
}
2 changes: 2 additions & 0 deletions src/common-models/worker-info.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export interface WorkerInfoModel {
name: string;
time: number;
type?: WorkerType;
requiredHours?: number;
overtime?: number;
}
53 changes: 50 additions & 3 deletions src/components/namestable/nametable-section.component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import React from "react";
import React, { useContext, useState } from "react";
import { DataRow } from "../../logic/schedule-logic/data-row";
import { WorkerInfoModel, WorkerType } from "../../common-models/worker-info.model";
import { Sections } from "../../logic/providers/schedule-provider.model";
import { ScheduleLogicContext } from "../schedule-page/table/schedule/use-schedule-state";
import { ShiftsInfoLogic } from "../../logic/schedule-logic/shifts-info.logic";
import WorkerDrawerComponent, {
WorkerDrawerMode,
} from "../workers-page/workers-tab/worker-drawer.component";

export interface NameTableCellOptions {
dataRow: DataRow[];
workerType?: WorkerType;
}

export function NameTableSection({ dataRow }: NameTableCellOptions): JSX.Element {
let workerInfo: WorkerInfoModel = { name: "", time: 0 };

export function NameTableSection({ dataRow, workerType }: NameTableCellOptions): JSX.Element {
const mode = WorkerDrawerMode.INFO;
const [open, setIsOpen] = useState(false);

const scheduleLogic = useContext(ScheduleLogicContext);
const sectionKey: keyof Sections =
workerType === WorkerType.NURSE ? "NurseInfo" : "BabysitterInfo";
const shiftLogic = scheduleLogic?.getSection<ShiftsInfoLogic>(sectionKey);

function toggleDrawer(open: boolean, name: string): void {
if (workerType) {
setIsOpen(open);
if (open) {
const [requiredHours, actualHours, overtime] =
shiftLogic?.calculateWorkerHourInfo(name) ?? [];

workerInfo = {
name: name,
time: actualHours,
type: workerType,
requiredHours,
overtime,
};
}
}
}

function getNames(): string[] {
return dataRow.map((a) => a.rowKey);
}
Expand All @@ -18,7 +54,11 @@ export function NameTableSection({ dataRow }: NameTableCellOptions): JSX.Element
<tbody>
{data.map((cellData) => {
return (
<tr key={cellData} className="nametableRow">
<tr
key={cellData}
onClick={(): void => toggleDrawer(true, cellData)}
className="nametableRow"
>
<td>
<span>{cellData}</span>
<span className="underline"></span>
Expand All @@ -28,6 +68,13 @@ export function NameTableSection({ dataRow }: NameTableCellOptions): JSX.Element
})}
</tbody>
</table>
<WorkerDrawerComponent
open={open}
onClose={(): void => toggleDrawer(false, "")}
mode={mode}
worker={workerInfo}
setOpen={setIsOpen}
/>
</React.Fragment>
);
}
11 changes: 8 additions & 3 deletions src/components/namestable/nametable.component.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import React from "react";
import { NameTableSection } from "./nametable-section.component";
import { BaseSectionOptions } from "../schedule-page/table/schedule/sections/base-section/base-section.component";
import { WorkerType } from "../../common-models/worker-info.model";

export function NameTableComponent(options: Partial<BaseSectionOptions>): JSX.Element {
const { data = [] } = options;
interface NameSectionOptions extends Partial<BaseSectionOptions> {
workerType?: WorkerType;
}

export function NameTableComponent(options: NameSectionOptions): JSX.Element {
const { data = [], workerType } = options;

return (
<div>
<NameTableSection dataRow={data} />
<NameTableSection dataRow={data} workerType={workerType} />
</div>
);
}
32 changes: 32 additions & 0 deletions src/components/namestable/worker-info.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from "react";
import {
WorkerInfoModel,
WorkerType,
WorkerTypeHelper,
} from "../../common-models/worker-info.model";
import { StringHelper } from "../../helpers/string.helper";
import classNames from "classnames/bind";
import { Button } from "../common-components";

export function WorkerInfoComponent(info: WorkerInfoModel): JSX.Element {
return (
<>
<div className={"span-errors"}>
<div className={"workers-table"}>
<span
className={classNames("worker-label", `${info.type?.toString().toLowerCase()}-label`)}
>
{StringHelper.capitalize(WorkerTypeHelper.translate(info.type ?? WorkerType.OTHER))}
</span>
</div>
<br />
<div className={"worker-info"}>
<p>Typ umowy:</p>
<p>Ilość godzin: {info.requiredHours}</p>
<p>Ilość nadgodzin: {info.overtime}</p>
<p>Suma godzin: {info.time}</p>
</div>
</div>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function ScheduleComponent(): JSX.Element {
<td>
<NameTableComponent
uuid={scheduleLocalState.uuid}
workerType={WorkerType.NURSE}
data={scheduleLocalState.nurseShiftsSection}
/>
</td>
Expand Down Expand Up @@ -94,6 +95,7 @@ export function ScheduleComponent(): JSX.Element {
<td>
<NameTableComponent
uuid={scheduleLocalState.uuid}
workerType={WorkerType.OTHER}
data={scheduleLocalState.babysitterShiftsSection}
/>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
import React from "react";
import Drawer, { DrawerOptions } from "../../common-components/drawer/drawer.component";
import { WorkerInfoModel } from "../../../common-models/worker-info.model";
import { WorkerInfoComponent } from "../../namestable/worker-info.component";

export enum WorkerDrawerMode {
EDIT,
ADD_NEW,
INFO,
}

interface WorkerDrawerOptions extends Omit<DrawerOptions, "title"> {
mode: WorkerDrawerMode;
worker?: WorkerInfoModel;
}

function getTitle(mode: WorkerDrawerMode): string {
switch (mode) {
case WorkerDrawerMode.EDIT:
return "Edycja pracownika";
case WorkerDrawerMode.ADD_NEW:
return "Dodaj pracownika";
case WorkerDrawerMode.INFO:
return "Pracownik";
}
}

export default function WorkerDrawerComponent(options: WorkerDrawerOptions): JSX.Element {
const { mode, worker, setOpen, ...otherOptions } = options;
const title = mode === WorkerDrawerMode.ADD_NEW ? "Dodaj pracownika" : "Edycja pracownika";

const title = getTitle(mode);
const isInfo = mode === WorkerDrawerMode.INFO;
return (
<Drawer setOpen={setOpen} title={title} {...otherOptions}>
{worker && <h1>{worker.name}</h1>}

{isInfo && WorkerInfoComponent(worker ?? { name: "", time: 0 })}
</Drawer>
);
}

0 comments on commit adc69e0

Please sign in to comment.