From b7991ea894e004bdbcd58dc2c8df47e4c3a8ea68 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Mon, 21 Jun 2021 10:46:55 +0100 Subject: [PATCH] Use action name as confirmation modal title --- .../src/components/ConfirmationDisplay.svelte | 2 +- packages/client/src/store/confirmation.js | 4 +++- packages/client/src/utils/buttonActions.js | 20 +++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/client/src/components/ConfirmationDisplay.svelte b/packages/client/src/components/ConfirmationDisplay.svelte index cfb110167f..454cf009a5 100644 --- a/packages/client/src/components/ConfirmationDisplay.svelte +++ b/packages/client/src/components/ConfirmationDisplay.svelte @@ -6,7 +6,7 @@ {#if $confirmationStore.showConfirmation} {$confirmationStore.text} diff --git a/packages/client/src/store/confirmation.js b/packages/client/src/store/confirmation.js index 5a6ec11dd4..497b021b04 100644 --- a/packages/client/src/store/confirmation.js +++ b/packages/client/src/store/confirmation.js @@ -2,6 +2,7 @@ import { writable, get } from "svelte/store" const initialState = { showConfirmation: false, + title: null, text: null, callback: null, } @@ -9,9 +10,10 @@ const initialState = { const createConfirmationStore = () => { const store = writable(initialState) - const showConfirmation = (text, callback) => { + const showConfirmation = (title, text, callback) => { store.set({ showConfirmation: true, + title, text, callback, }) diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index 9acf30b219..6a72c494f0 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -107,15 +107,19 @@ export const enrichButtonActions = (actions, context) => { if (action.parameters?.confirm) { const defaultText = confirmTextMap[action["##eventHandlerType"]] const confirmText = action.parameters?.confirmText || defaultText - confirmationStore.actions.showConfirmation(confirmText, async () => { - // When confirmed, execute this action immediately, - // then execute the rest of the actions in the chain - const result = await callback() - if (result !== false) { - const next = enrichButtonActions(actions.slice(i + 1), context) - await next() + confirmationStore.actions.showConfirmation( + action["##eventHandlerType"], + confirmText, + async () => { + // When confirmed, execute this action immediately, + // then execute the rest of the actions in the chain + const result = await callback() + if (result !== false) { + const next = enrichButtonActions(actions.slice(i + 1), context) + await next() + } } - }) + ) // Stop enriching actions when encountering a confirmable action, // as the callback continues the action chain