Skip to content

Commit

Permalink
TASK-400 Export and refresh DB from modal (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimonium-239 authored and Qwebeck committed Apr 16, 2021
1 parent 2c09f98 commit 34de886
Show file tree
Hide file tree
Showing 8 changed files with 34,907 additions and 315 deletions.
35,114 changes: 34,818 additions & 296 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@
"cypress:open": "cypress open"
},
"devDependencies": {
"@cypress/snapshot": "^2.1.7",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@cypress/snapshot": "^2.1.7",
"@types/node": "^14.14.21",
"@types/react": "^16.9.46",
"@types/react-dom": "^16.9.8",
Expand Down
20 changes: 20 additions & 0 deletions src/assets/styles/styles/custom/_export-modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,23 @@
font-weight: $font-weight-extra-bold;
line-height: $modal-title-line-height;
}

.app-error-button > .not-clicked {
color: $brand-info !important;
text-decoration: underline;
}

.app-error-button > .clicked {
color: $dark-gray !important;
text-decoration: underline;
}

.app-error-button > .not-clicked:hover {
color: $brand-primary !important;
text-decoration: underline;
cursor: pointer;
}

.error-modal-text {
margin-left: 10px;
}
14 changes: 8 additions & 6 deletions src/components/common-components/header/header.component.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/* 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 { Button as MaterialButton } from "@material-ui/core";
import AssignmentIndIcon from "@material-ui/icons/AssignmentInd";
import HelpOutlineIcon from "@material-ui/icons/HelpOutline";
import classNames from "classnames/bind";
import React, { useCallback, useContext, useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { AppConfigContext, AppConfigOptions, AppMode } from "../../../state/app-config-context";
import { ApplicationStateModel } from "../../../state/models/application-state.model";
import { MonthSwitchActionCreator } from "../../../state/reducers/month-state/schedule-data/month-switch.action-creator";
import { ScheduleMode } from "../../schedule-page/table/schedule/schedule-state.model";
import { Button } from "../button-component/button.component";
import ReportIssueModal from "../modal/report-issue-modal/report-issue-modal.component";
import { MonthSwitchComponent } from "../month-switch/month-switch.component";
import classNames from "classnames/bind";
import { Button as MaterialButton } from "@material-ui/core";
import ReportIssueModal from "../modal/report-issue-modal/report-issue-modal.component";
import SettingsIcon from "@material-ui/icons/Settings";
import HelpOutlineIcon from "@material-ui/icons/HelpOutline";
import { AppConfigContext, AppConfigOptions, AppMode } from "../../../state/app-config-context";
import { ScheduleMode } from "../../schedule-page/table/schedule/schedule-state.model";

function monthDiff(d1: Date, d2: Date): number {
let months: number;
Expand Down Expand Up @@ -90,6 +91,7 @@ export function HeaderComponent(): JSX.Element {
Zgłoś błąd
</MaterialButton>
<ReportIssueModal open={isModalOpen} setOpen={setIsModalOpen} />
<SettingsIcon className="header-icon" />
<HelpOutlineIcon className="header-icon" onClick={redirectToDocumentation} />
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* 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 React from "react";
import React, { useEffect, useState } from "react";
import { Button } from "../../button-component/button.component";
import DefaultModal from "../modal.component";
import { LocalStorageProvider } from "../../../../api/local-storage-provider.model";
import { FileHelper } from "../../../../helpers/file.helper";

interface AppErrorModalOptions {
onClick: () => void;
Expand All @@ -13,31 +15,78 @@ interface AppErrorModalOptions {

export default function AppErrorModal(options: AppErrorModalOptions): JSX.Element {
const { setOpen, open, onClick } = options;
const [openExtension, setIsOpenExtension] = useState(false);

const handleClose = (): void => {
onClick();
setIsOpenExtension(false);
setOpen(false);
};

const title = "Coś poszło nie tak :(";
useEffect(() => {
setIsOpenExtension(false);
}, [open]);

const closeAndSaveDB = async (): Promise<void> => {
await FileHelper.handleDbDump();
await new LocalStorageProvider().reloadDb();
};

const title = "Wystąpił błąd";

const body = (
<div className={"span-primary"}>
<p>Wiadomość o błędzie została wysłana do twórców.</p>
<div className={"span-primary error-modal-text"}>
<p>
Wiadomość o błędzie została wysłana do twórców.
<br />
Proszę odświeżyć aplikację
</p>
</div>
);

const footer = (
<div style={{ display: "flex", justifyContent: "center" }}>
<div style={{ display: "block" }}>
<Button
onClick={handleClose}
onClick={(): void => {
window.location.reload(false);
setIsOpenExtension(false);
handleClose();
}}
size="small"
className="submit-button"
variant="primary"
data-cy="btn-ok-app-error"
data-cy="btn-reload-app-error"
>
OK
Odśwież aplikację
</Button>
<br />
<br />
<div className={"app-error-button error-modal-text"}>
<p
className={openExtension ? "clicked" : "not-clicked"}
onClick={(): void => setIsOpenExtension(true)}
>
Dalej nie działa? Zobacz co możesz zrobić.
</p>
</div>
{openExtension && (
<>
<div className={"span-primary error-modal-text"}>
Aplikacja prawdopodbnie zawiera błędne dane.
<br />
Pobierz wszystkie grafiki i wyczyść dane aplikacji.
</div>

<Button
size="small"
className="submit-button"
variant="secondary"
onClick={closeAndSaveDB}
>
Pobierz grafik i wyczyść aplikację
</Button>
</>
)}
</div>
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/common-components/modal/modal.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface ModalOptions {

export default function DefaultModal(options: ModalOptions): JSX.Element {
const { setOpen, open, title, body, footer, closeOptions, classNames } = options;
let classes = useStyles(options.height ?? 350, options.width ?? 600);
let classes = useStyles(options.height ?? 450, options.width ?? 600);
classes = classNames ? classNames : classes;

const handleClose = (): void => {
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/file.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class FileHelper {
}
const zipFile = await zip.generateAsync({ type: "blob" });
const timestamp = new Date().toLocaleDateString("pl").replaceAll(".", "_");
this.saveFileAs(zipFile, `historia_${timestamp}`);
this.saveFileAs(zipFile, `historia_${timestamp}.zip`);
}

private static splitWorkbooksInDirs(workbooks): FilenamesToDirnameDict {
Expand Down Expand Up @@ -94,7 +94,6 @@ export class FileHelper {
const docs = await new LocalStorageProvider().getAllSchedules();

const workbooks: WorkbookToFilename = {};

Object.keys(docs)
.filter((revisionKey) => !docs[revisionKey].isAutoGenerated)
.forEach((revisionKey) => {
Expand Down
2 changes: 1 addition & 1 deletion src/logic/schedule-exporter/worker-export.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class WorkerExportLogic {
const workersInfoArray = WorkerExportLogic.createWorkersInfoSection(this.scheduleModel);

const colLens = workersInfoArray[0].map((_, colIndex) =>
Math.max(...workersInfoArray.map((row) => row[colIndex].toString().length))
Math.max(...workersInfoArray.map((row) => row[colIndex]?.toString().length ?? 0))
);

workSheet.addRows(workersInfoArray);
Expand Down

0 comments on commit 34de886

Please sign in to comment.