Added delete all EMS functionality RPS-11
This commit is contained in:
@@ -2,7 +2,7 @@ const { ipcMain } = require("electron");
|
||||
const Nucleus = require("nucleus-nodejs");
|
||||
const ipcTypes = require("../../src/ipc.types");
|
||||
const { ImportJob } = require("../decoder/decoder");
|
||||
const { GetListOfEstimates } = require("./file-scan");
|
||||
const { GetListOfEstimates, DeleteAllEms } = require("./file-scan");
|
||||
|
||||
ipcMain.on(
|
||||
ipcTypes.default.fileScan.toMain.scanFilePaths,
|
||||
@@ -22,3 +22,16 @@ ipcMain.on(
|
||||
await ImportJob(filePath);
|
||||
}
|
||||
);
|
||||
|
||||
ipcMain.on(
|
||||
ipcTypes.default.fileScan.toMain.deleteAllEms,
|
||||
async (event, filePath) => {
|
||||
Nucleus.track("DELETE_ALLEMS");
|
||||
await DeleteAllEms();
|
||||
const ret = await GetListOfEstimates();
|
||||
event.reply(
|
||||
ipcTypes.default.fileScan.toRenderer.scanFilePathsResponse,
|
||||
ret
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -6,6 +6,7 @@ const fsPromises = fs.promises;
|
||||
const _ = require("lodash");
|
||||
const { DecodeEstimate } = require("../decoder/decoder");
|
||||
const Nucleus = require("nucleus-nodejs");
|
||||
const { format } = require("path");
|
||||
|
||||
async function GetListOfEstimates() {
|
||||
Nucleus.track("SCAN_ALL_ESTIMATES");
|
||||
@@ -42,4 +43,32 @@ async function GetEnvFiles() {
|
||||
return allFilePaths;
|
||||
}
|
||||
|
||||
async function DeleteAllEms() {
|
||||
try {
|
||||
const filePaths = store.get("filePaths");
|
||||
const allFilePaths = [];
|
||||
await Promise.all(
|
||||
filePaths.map(async (fp) => {
|
||||
const allFilesinDir = await fsPromises.readdir(fp);
|
||||
|
||||
allFilesinDir.map((envFileName) => {
|
||||
allFilePaths.push(path.join(fp, envFileName));
|
||||
return null;
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
allFilePaths.map(async (file) => {
|
||||
await fsPromises.unlink(file);
|
||||
})
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
exports.GetListOfEstimates = GetListOfEstimates;
|
||||
exports.DeleteAllEms = DeleteAllEms
|
||||
17
src/components/atoms/delete-all-ems/delete-all-ems.atom.jsx
Normal file
17
src/components/atoms/delete-all-ems/delete-all-ems.atom.jsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Button, Popconfirm } from "antd";
|
||||
import React from "react";
|
||||
import ipcTypes from "../../../ipc.types";
|
||||
|
||||
const { ipcRenderer } = window;
|
||||
export default function DeleteAllEmsAtom() {
|
||||
return (
|
||||
<Popconfirm
|
||||
title="Are you sure you want to delete all EMS files? This cannot be undone."
|
||||
onConfirm={() =>
|
||||
ipcRenderer.send(ipcTypes.default.fileScan.toMain.deleteAllEms)
|
||||
}
|
||||
>
|
||||
<Button>Delete All EMS</Button>
|
||||
</Popconfirm>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Button, Input, Table } from "antd";
|
||||
import { Button, Input, message, Table } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
selectScanLoading,
|
||||
} from "../../../redux/scan/scan.selectors";
|
||||
import { alphaSort } from "../../../util/sorters";
|
||||
import DeleteAllEmsAtom from "../../atoms/delete-all-ems/delete-all-ems.atom";
|
||||
import LastScannedAtom from "../../atoms/last-scanned/last-scanned.atom";
|
||||
import ScanRefreshAtom from "../../atoms/scan-refresh/scan-refresh.atom";
|
||||
|
||||
@@ -64,12 +65,13 @@ export function ScanEstimateListMolecule({ scanLoading, estimates }) {
|
||||
key: "import",
|
||||
render: (text, record) => (
|
||||
<Button
|
||||
onClick={() =>
|
||||
onClick={() => {
|
||||
message.info("Attempting to import job...");
|
||||
ipcRenderer.send(
|
||||
ipcTypes.default.fileScan.toMain.importJob,
|
||||
record.filepath
|
||||
)
|
||||
}
|
||||
);
|
||||
}}
|
||||
>
|
||||
Import
|
||||
</Button>
|
||||
@@ -96,6 +98,7 @@ export function ScanEstimateListMolecule({ scanLoading, estimates }) {
|
||||
<div className="imex-table-header">
|
||||
<ScanRefreshAtom />
|
||||
<LastScannedAtom />
|
||||
<DeleteAllEmsAtom />
|
||||
<Input.Search
|
||||
className="imex-table-header__search"
|
||||
placeholder="Search"
|
||||
|
||||
11
src/index.js
11
src/index.js
@@ -21,14 +21,3 @@ ReactDOM.render(
|
||||
</Provider>,
|
||||
document.getElementById("root")
|
||||
);
|
||||
|
||||
window.onkeydown = function (evt) {
|
||||
// disable zooming
|
||||
if (
|
||||
(evt.code === "Minus" || evt.code === "Equal") &&
|
||||
(evt.ctrlKey || evt.metaKey)
|
||||
) {
|
||||
console.log("Preventing zoom!");
|
||||
evt.preventDefault();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ exports.default = {
|
||||
toMain: {
|
||||
scanFilePaths: "fileScan__scanFilePaths",
|
||||
importJob: "fileScan__importJob",
|
||||
deleteAllEms: "filescan_deleteAllEms",
|
||||
},
|
||||
toRenderer: {
|
||||
scanFilePathsResponse: "fileScan__scanFilePathsResponse",
|
||||
|
||||
Reference in New Issue
Block a user