From 5deab931623ec1d542c46a1213f0baa79847cc87 Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Wed, 19 Jul 2023 21:07:50 +0200 Subject: [PATCH] Find view: confirm deletion (fixes #58) --- frontend/src/lib/dialogs.js | 7 +++++- .../connection/collection/find.svelte | 5 ++++ frontend/wailsjs/go/app/App.d.ts | 2 ++ frontend/wailsjs/go/app/App.js | 4 +++ internal/app/app.go | 25 +++++++++++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/dialogs.js b/frontend/src/lib/dialogs.js index 5b4bf17..fcceb5e 100644 --- a/frontend/src/lib/dialogs.js +++ b/frontend/src/lib/dialogs.js @@ -1,3 +1,4 @@ +import { AskConfirmation } from '$wails/go/app/App'; import InputDialog from '../dialogs/input.svelte'; function newDialog(dialogComponent, data = {}) { @@ -29,6 +30,10 @@ function enterText(title = '', description = '', value = '') { }); } -const dialogs = { new: newDialog, enterText }; +function confirm(message = '') { + return AskConfirmation(message); +} + +const dialogs = { new: newDialog, enterText, confirm }; export default dialogs; diff --git a/frontend/src/organisms/connection/collection/find.svelte b/frontend/src/organisms/connection/collection/find.svelte index 2b7e6ec..2df4e68 100644 --- a/frontend/src/organisms/connection/collection/find.svelte +++ b/frontend/src/organisms/connection/collection/find.svelte @@ -4,6 +4,7 @@ import ObjectGrid from '$components/objectgrid.svelte'; import ObjectViewer from '$components/objectviewer.svelte'; import input from '$lib/actions/input'; + import dialogs from '$lib/dialogs'; import { deepClone } from '$lib/objects'; import { startProgress } from '$lib/progress'; import applicationSettings from '$lib/stores/settings'; @@ -119,6 +120,10 @@ if (!activePath[0]) { return; } + const sure = await dialogs.confirm('Are you sure you wish to delete this item?'); + if (!sure) { + return; + } const ok = await RemoveItemById(collection.hostKey, collection.dbKey, collection.key, activePath[0]); if (ok) { await submitQuery(); diff --git a/frontend/wailsjs/go/app/App.d.ts b/frontend/wailsjs/go/app/App.d.ts index bc85840..f6d9fd5 100755 --- a/frontend/wailsjs/go/app/App.d.ts +++ b/frontend/wailsjs/go/app/App.d.ts @@ -10,6 +10,8 @@ export function AddHost(arg1:string):Promise; export function Aggregate(arg1:string,arg2:string,arg3:string,arg4:string,arg5:string):Promise; +export function AskConfirmation(arg1:string):Promise; + export function CreateIndex(arg1:string,arg2:string,arg3:string,arg4:string):Promise; export function DropCollection(arg1:string,arg2:string,arg3:string):Promise; diff --git a/frontend/wailsjs/go/app/App.js b/frontend/wailsjs/go/app/App.js index 581ca98..281e574 100755 --- a/frontend/wailsjs/go/app/App.js +++ b/frontend/wailsjs/go/app/App.js @@ -10,6 +10,10 @@ export function Aggregate(arg1, arg2, arg3, arg4, arg5) { return window['go']['app']['App']['Aggregate'](arg1, arg2, arg3, arg4, arg5); } +export function AskConfirmation(arg1) { + return window['go']['app']['App']['AskConfirmation'](arg1); +} + export function CreateIndex(arg1, arg2, arg3, arg4) { return window['go']['app']['App']['CreateIndex'](arg1, arg2, arg3, arg4); } diff --git a/internal/app/app.go b/internal/app/app.go index 096b039..c681104 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -141,3 +141,28 @@ func (a *App) ReportSharedStateVariable(key, value string) { a.State.Store(key, value) wailsRuntime.LogDebug(a.ctx, fmt.Sprintf("State: %s=\"%s\"", key, value)) } + +func (a *App) AskConfirmation(message string) bool { + var title string = "" + if runtime.GOOS == "darwin" { + title = message + message = "" + } else { + title = "Confirm" + } + + button, err := wailsRuntime.MessageDialog(a.ctx, wailsRuntime.MessageDialogOptions{ + Type: wailsRuntime.QuestionDialog, + Title: title, + Message: message, + Buttons: []string{"Yes", "No"}, + DefaultButton: "Yes", + CancelButton: "No", + }) + + if err == nil { + return button == "Yes" + } else { + return false + } +}