diff --git a/packages/frontend/src/lib/Modal.svelte b/packages/frontend/src/lib/Modal.svelte new file mode 100644 index 000000000..16c169244 --- /dev/null +++ b/packages/frontend/src/lib/Modal.svelte @@ -0,0 +1,62 @@ + + + + + + + + + diff --git a/packages/frontend/src/lib/dialog-utils.ts b/packages/frontend/src/lib/dialog-utils.ts new file mode 100644 index 000000000..cb97d595d --- /dev/null +++ b/packages/frontend/src/lib/dialog-utils.ts @@ -0,0 +1,32 @@ +/********************************************************************** + * Copyright (C) 2023 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +export function tabWithinParent(e: KeyboardEvent, parent: HTMLDivElement): void { + // trap focus within parent element + const nodes = parent.querySelectorAll('*'); + const tabbable = Array.from(nodes).filter(n => n.tabIndex >= 0); + + let index = tabbable.indexOf(document.activeElement as HTMLElement); + if (index === -1 && e.shiftKey) index = 0; + + index += tabbable.length + (e.shiftKey ? -1 : 1); + index %= tabbable.length; + + tabbable[index].focus(); + e.preventDefault(); +} diff --git a/packages/frontend/src/lib/table/model/ModelColumnActions.svelte b/packages/frontend/src/lib/table/model/ModelColumnActions.svelte index 629f6b0d7..6c596c721 100644 --- a/packages/frontend/src/lib/table/model/ModelColumnActions.svelte +++ b/packages/frontend/src/lib/table/model/ModelColumnActions.svelte @@ -3,11 +3,19 @@ import type { ModelInfo } from "@shared/src/models/IModelInfo"; import { faTrash } from "@fortawesome/free-solid-svg-icons"; import ListItemButtonIcon from "../../button/ListItemButtonIcon.svelte"; import { studioClient } from "/@/utils/client"; +import Modal from "../../Modal.svelte"; + import Button from "../../button/Button.svelte"; export let object: ModelInfo; +let deleteConfirmVisible: boolean = false; + function deleteModel() { - console.log('delete model', object.id); - studioClient.deleteLocalModel(object.id); + deleteConfirmVisible= true; +} + +async function goDeleteModel() { + await studioClient.deleteLocalModel(object.id); + deleteConfirmVisible= false; } @@ -17,3 +25,29 @@ function deleteModel() { title="Delete Model" enabled={!object.state} /> + +{#if deleteConfirmVisible} + +
+

Delete a model

+ + +
+
+ The folder on disk containing the model will be deleted, it contains: +
    +
  • {object.file?.file}
  • +
+ +
+ + +
+
+
+{/if}