From b3e2318422dc7e1abb93979a02492dc5e21be279 Mon Sep 17 00:00:00 2001 From: Garrett Michael Flynn Date: Mon, 29 Jan 2024 11:24:34 -0800 Subject: [PATCH] Remove regenerated pipeline files (#572) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Cody Baker <51133164+CodyCBakerPhD@users.noreply.github.com> --- src/renderer/src/progress/index.js | 28 ++++++++++--------- src/renderer/src/progress/operations.js | 7 +++-- .../stories/pages/settings/SettingsPage.js | 8 ++++-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/renderer/src/progress/index.js b/src/renderer/src/progress/index.js index 652d60c49..de410b5d6 100644 --- a/src/renderer/src/progress/index.js +++ b/src/renderer/src/progress/index.js @@ -193,19 +193,21 @@ export function resume(name) { return commandToResume; } -export const remove = async (name) => { - const result = await Swal.fire({ - 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 ${name}`, - cancelButtonText: "Cancel", - focusCancel: true, - }); +export const remove = async (name, force = false) => { + const result = force + ? { isConfirmed: true } + : await Swal.fire({ + 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 ${name}`, + cancelButtonText: "Cancel", + focusCancel: true, + }); if (result.isConfirmed) return operations.remove(name); diff --git a/src/renderer/src/progress/operations.js b/src/renderer/src/progress/operations.js index 3e0e70fa4..10e25e533 100644 --- a/src/renderer/src/progress/operations.js +++ b/src/renderer/src/progress/operations.js @@ -7,10 +7,13 @@ export const remove = (name) => { const progressFilePathToDelete = joinPath(guidedProgressFilePath, name + ".json"); //delete the progress file - if (fs) fs.unlinkSync(progressFilePathToDelete); - else localStorage.removeItem(progressFilePathToDelete); + if (fs) { + if (fs.existsSync(progressFilePathToDelete)) fs.unlinkSync(progressFilePathToDelete); + } else localStorage.removeItem(progressFilePathToDelete); if (fs) { + console.log(previewSaveFolderPath, conversionSaveFolderPath, name); + // delete default preview location fs.rmSync(joinPath(previewSaveFolderPath, name), { recursive: true, force: true }); diff --git a/src/renderer/src/stories/pages/settings/SettingsPage.js b/src/renderer/src/stories/pages/settings/SettingsPage.js index a601e2abe..4bc7354c9 100644 --- a/src/renderer/src/stories/pages/settings/SettingsPage.js +++ b/src/renderer/src/stories/pages/settings/SettingsPage.js @@ -9,7 +9,7 @@ import developerGlobalSchema from "../../../../../../schemas/json/developer/glob import { validateDANDIApiKey } from "../../../validation/dandi"; import { Button } from "../../Button.js"; -import { global, save } from "../../../progress/index.js"; +import { global, remove, save } from "../../../progress/index.js"; import { merge, setUndefinedIfNotDeclared } from "../utils.js"; import { notyf } from "../../../dependencies/globals.js"; @@ -34,11 +34,15 @@ function saveNewPipelineFromYaml(name, sourceData, rootFolder) { }); }); + const updatedName = header(name); + + remove(updatedName, true); + save({ info: { globalState: { project: { - name: header(name), + name: updatedName, initialized: true, },