From 7aa31e54188af51a14ec193c4f88839946061315 Mon Sep 17 00:00:00 2001 From: e-salad Date: Sat, 23 Nov 2024 00:47:15 -0600 Subject: [PATCH] improve script selection functionality - Improve validation for configuration import - Refactor SaveSelectionButton.vue implementation - Add floppy-disk-gear icon for SaveSelectionButton --- .../Dialog/Browser/FileSaverDialog.ts | 2 + .../assets/icons/floppy-disk-gear.svg | 4 ++ .../CodeButtons/Save/SaveSelectionButton.vue | 30 +++++--- .../TheRecommendationSelector.vue | 70 ++++++++++++++++--- .../components/Shared/Icon/IconName.ts | 1 + 5 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 src/presentation/assets/icons/floppy-disk-gear.svg diff --git a/src/infrastructure/Dialog/Browser/FileSaverDialog.ts b/src/infrastructure/Dialog/Browser/FileSaverDialog.ts index b29e565d3..4d77961c5 100644 --- a/src/infrastructure/Dialog/Browser/FileSaverDialog.ts +++ b/src/infrastructure/Dialog/Browser/FileSaverDialog.ts @@ -39,4 +39,6 @@ const MimeTypes: Record = { // otherwise they ignore extension and save the file as text. [FileType.BatchFile]: 'application/bat', // https://en.wikipedia.org/wiki/Batch_file [FileType.ShellScript]: 'text/x-shellscript', // https://de.wikipedia.org/wiki/Shellskript#MIME-Typ + [FileType.Json]: 'application/json', // https://en.wikipedia.org/wiki/JSON + } as const; diff --git a/src/presentation/assets/icons/floppy-disk-gear.svg b/src/presentation/assets/icons/floppy-disk-gear.svg new file mode 100644 index 000000000..3f5b8e793 --- /dev/null +++ b/src/presentation/assets/icons/floppy-disk-gear.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/presentation/components/Code/CodeButtons/Save/SaveSelectionButton.vue b/src/presentation/components/Code/CodeButtons/Save/SaveSelectionButton.vue index 624bdc7fb..32bb205e7 100644 --- a/src/presentation/components/Code/CodeButtons/Save/SaveSelectionButton.vue +++ b/src/presentation/components/Code/CodeButtons/Save/SaveSelectionButton.vue @@ -1,7 +1,7 @@ @@ -11,6 +11,13 @@ import { defineComponent } from 'vue'; import { injectKey } from '@/presentation/injectionSymbols'; import { FileType } from '@/presentation/common/Dialog'; import IconButton from '../IconButton.vue'; +import { createScriptErrorDialog } from '../ScriptErrorDialog'; + +interface SelectionConfig { + version: string; + timestamp: string; + selectedScripts: string[]; +} export default defineComponent({ components: { @@ -20,25 +27,28 @@ export default defineComponent({ const { currentSelection } = injectKey((keys) => keys.useUserSelectionState); const { dialog } = injectKey((keys) => keys.useDialog); const { projectDetails } = injectKey((keys) => keys.useApplication); + const { scriptDiagnosticsCollector } = injectKey((keys) => keys.useScriptDiagnosticsCollector); async function saveSelection() { - // Create a config object with the current selection state - const config = { - version: projectDetails.version, - selectedScripts: currentSelection.value.scripts.selectedScripts.map((script) => script.id), + const config: SelectionConfig = { + version: projectDetails.version.toString(), timestamp: new Date().toISOString(), + selectedScripts: currentSelection.value.scripts.selectedScripts.map((script) => script.id), }; - const configJson = JSON.stringify(config, null, 2); - const { success, error } = await dialog.saveFile( - configJson, + JSON.stringify(config, null, 2), 'privacy-selection.json', FileType.Json, ); - if (!success && error) { - console.error('Failed to save selection:', error); + if (!success) { + dialog.showError(...(await createScriptErrorDialog({ + errorContext: 'save', + errorType: error.type, + errorMessage: error.message, + isFileReadbackError: error.type === 'FileReadbackVerificationError', + }, scriptDiagnosticsCollector))); } } diff --git a/src/presentation/components/Scripts/Menu/Recommendation/TheRecommendationSelector.vue b/src/presentation/components/Scripts/Menu/Recommendation/TheRecommendationSelector.vue index d5d165109..c2fcb3209 100644 --- a/src/presentation/components/Scripts/Menu/Recommendation/TheRecommendationSelector.vue +++ b/src/presentation/components/Scripts/Menu/Recommendation/TheRecommendationSelector.vue @@ -86,7 +86,7 @@ @@ -102,7 +106,7 @@