From e6985415ef4cd98c1e8a3ddad2356416de44fb80 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Fri, 30 Sep 2022 15:04:57 +0200 Subject: [PATCH] feat(front): Confirmation modal when deleting a resource or a variable (#648) * feat(front): add confirmation modal when deleting a resource or a variable * feat(front): add shift bypass * feat(front): clear callbacks * feat(front): Add alert to inform user can confirmation modals can be bypassed --- frontend/src/lib/components/Dropdown.svelte | 4 +- .../RemoveStepConfirmationModal.svelte | 2 +- frontend/src/lib/utils.ts | 2 +- frontend/src/routes/resources.svelte | 43 ++++++++++++++++-- frontend/src/routes/variables.svelte | 44 +++++++++++++++++-- 5 files changed, 85 insertions(+), 10 deletions(-) diff --git a/frontend/src/lib/components/Dropdown.svelte b/frontend/src/lib/components/Dropdown.svelte index f9aa585695..d684abcdb7 100644 --- a/frontend/src/lib/components/Dropdown.svelte +++ b/frontend/src/lib/components/Dropdown.svelte @@ -55,10 +55,10 @@ {#each dropdownItems as item, i} {#if item.action} {/if} - + + + { + deleteConfirmedCallback = undefined + }} + on:confirmed={() => { + if (deleteConfirmedCallback) { + deleteConfirmedCallback() + } + deleteConfirmedCallback = undefined + }} > +
+ Are you sure you want to remove this resource? + +
+ You can press + SHIFT + while removing a resource to bypass confirmation. +
+
+
+
diff --git a/frontend/src/routes/variables.svelte b/frontend/src/routes/variables.svelte index 64570c38c2..86a1ef986e 100644 --- a/frontend/src/routes/variables.svelte +++ b/frontend/src/routes/variables.svelte @@ -21,6 +21,9 @@ import CenteredPage from '$lib/components/CenteredPage.svelte' import Icon from 'svelte-awesome' import { faPlus, faCircle } from '@fortawesome/free-solid-svg-icons' + import ConfirmationModal from '$lib/components/common/confirmationModal/ConfirmationModal.svelte' + import Alert from '$lib/components/common/alert/Alert.svelte' + import Badge from '$lib/components/common/badge/Badge.svelte' type ListableVariableW = ListableVariable & { canWrite: boolean } @@ -30,6 +33,9 @@ let shareModal: ShareModal let variableEditor: VariableEditor + let deleteConfirmedCallback: (() => void) | undefined = undefined + $: open = Boolean(deleteConfirmedCallback) + // If relative, the dropdown is positioned relative to its button async function loadVariables(): Promise { variables = (await VariableService.listVariable({ workspace: $workspaceStore! })).map((x) => { @@ -119,7 +125,16 @@ }, { displayName: 'Delete', - action: () => deleteVariable(path, account), + + action: (event) => { + if (event?.shiftKey) { + deleteVariable(path, account) + } else { + deleteConfirmedCallback = () => { + deleteVariable(path, account) + } + } + }, disabled: !canWrite }, { @@ -182,5 +197,28 @@ /> - + { + deleteConfirmedCallback = undefined + }} + on:confirmed={() => { + if (deleteConfirmedCallback) { + deleteConfirmedCallback() + } + deleteConfirmedCallback = undefined + }} +> +
+ Are you sure you want to remove this variable? + +
+ You can press + SHIFT + while removing a variable to bypass confirmation. +
+
+
+