Skip to content

Commit

Permalink
Merge pull request #347 from NeurodataWithoutBorders/delete-records-o…
Browse files Browse the repository at this point in the history
…n-project-deletion

Remove all internal files / folders related to a conversion
  • Loading branch information
CodyCBakerPhD authored Sep 8, 2023
2 parents 4ca74cc + 888a9df commit aaf537f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/renderer/src/dependencies/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ export const homeDirectory = app?.getPath("home") ?? "";
export const appDirectory = homeDirectory ? joinPath(homeDirectory, paths.root) : "";
export const guidedProgressFilePath = homeDirectory ? joinPath(appDirectory, ...paths.subfolders.progress) : "";

export const stubSaveFolderPath = homeDirectory
? joinPath(homeDirectory, paths["root"], ...paths.subfolders.stubs)
: "";
export const conversionSaveFolderPath = homeDirectory
? joinPath(homeDirectory, paths["root"], ...paths.subfolders.conversions)
: "";

export const isStorybook = window.location.href.includes("iframe.html");
25 changes: 20 additions & 5 deletions src/renderer/src/progress/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import Swal from "sweetalert2";

import { guidedProgressFilePath, reloadPageToHome, isStorybook, appDirectory } from "../dependencies/simple.js";
import {
guidedProgressFilePath,
reloadPageToHome,
isStorybook,
appDirectory,
stubSaveFolderPath,
conversionSaveFolderPath,
} from "../dependencies/simple.js";
import { fs } from "../electron/index.js";
import { joinPath, runOnLoad } from "../globals.js";
import { merge } from "../stories/pages/utils.js";
Expand Down Expand Up @@ -102,14 +109,14 @@ export function resume(name) {

export const remove = async (name) => {
const result = await Swal.fire({
title: `Are you sure you would like to delete NWB GUIDE progress made on the dataset: ${name}?`,
text: "Your progress file will be deleted permanently, and all existing progress will be lost.",
title: `Are you sure you would like to delete this conversion pipeline?`,
html: `All related files will be deleted permanently, and existing progress will be lost.`,
icon: "warning",
heightAuto: false,
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Delete progress file",
confirmButtonText: `Delete ${name}`,
cancelButtonText: "Cancel",
focusCancel: true,
});
Expand All @@ -119,9 +126,17 @@ export const remove = async (name) => {
const progressFilePathToDelete = joinPath(guidedProgressFilePath, name + ".json");

//delete the progress file
if (fs) fs.unlinkSync(progressFilePathToDelete, (err) => console.log(err));
if (fs) fs.unlinkSync(progressFilePathToDelete);
else localStorage.removeItem(progressFilePathToDelete);

if (fs) {
// delete default stub location
fs.rmSync(joinPath(stubSaveFolderPath, name), { recursive: true, force: true });

// delete default conversion location
fs.rmSync(joinPath(conversionSaveFolderPath, name), { recursive: true, force: true });
}

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/stories/pages/guided-mode/ProgressCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ProgressCard extends LitElement {
@click=${(ev) => progress.deleteProgressCard(ev.target)}
>
<i class="fas fa-trash mr-sm-1"></i>
Delete progress file
Delete pipeline
</h2>
</div>
</div>
Expand Down

0 comments on commit aaf537f

Please sign in to comment.