Skip to content

Confirmation before deleting in the Dashboard #13035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import { Text } from '#/components/AriaComponents'
import * as object from '#/utilities/object'

const ASSET_TYPE_TO_TEXT_ID: Readonly<Record<backendModule.AssetType, text.TextId>> = {
export const ASSET_TYPE_TO_TEXT_ID: Readonly<Record<backendModule.AssetType, text.TextId>> = {

Check failure on line 22 in app/gui/src/dashboard/components/dashboard/Permission.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/components/dashboard/Permission.tsx#L22

[react-refresh/only-export-components] Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.

Check failure on line 22 in app/gui/src/dashboard/components/dashboard/Permission.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/components/dashboard/Permission.tsx#L22

[react-refresh/only-export-components] Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.

Check failure on line 22 in app/gui/src/dashboard/components/dashboard/Permission.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/components/dashboard/Permission.tsx#L22

[react-refresh/only-export-components] Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.

Check failure on line 22 in app/gui/src/dashboard/components/dashboard/Permission.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/components/dashboard/Permission.tsx#L22

[react-refresh/only-export-components] Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.
[backendModule.AssetType.directory]: 'directoryAssetType',
[backendModule.AssetType.project]: 'projectAssetType',
[backendModule.AssetType.file]: 'fileAssetType',
Expand Down
39 changes: 14 additions & 25 deletions app/gui/src/dashboard/layouts/AssetContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import * as backendModule from '#/services/Backend'

import { ASSET_TYPE_TO_TEXT_ID } from '#/components/dashboard/Permission'
import { ContextMenuEntry as PaywallContextMenuEntry } from '#/components/Paywall'
import {
copyAssetsMutationOptions,
Expand Down Expand Up @@ -337,31 +338,19 @@
action="delete"
label={isCloud ? getText('moveToTrashShortcut') : getText('deleteShortcut')}
doAction={() => {
if (isCloud) {
if (asset.type === backendModule.AssetType.directory) {
setModal(
<ConfirmDeleteModal
defaultOpen
actionText={getText('trashTheAssetTypeTitle', asset.type, asset.title)}
onConfirm={async () => {
await deleteAssetsMutation([[asset.id], false])
}}
/>,
)
} else {
void deleteAssetsMutation([[asset.id], false])
}
} else {
setModal(
<ConfirmDeleteModal
defaultOpen
actionText={getText('deleteTheAssetTypeTitle', asset.type, asset.title)}
onConfirm={async () => {
await deleteAssetsMutation([[asset.id], false])
}}
/>,
)
}
setModal(
<ConfirmDeleteModal
defaultOpen
actionText={getText(
isCloud ? 'trashTheAssetTypeTitle' : 'deleteTheAssetTypeTitle',

Check failure on line 345 in app/gui/src/dashboard/layouts/AssetContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetContextMenu.tsx#L345

[no-restricted-syntax] Use a `getText()` from `useText` instead of a literal string

Check failure on line 345 in app/gui/src/dashboard/layouts/AssetContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetContextMenu.tsx#L345

[no-restricted-syntax] Use a `getText()` from `useText` instead of a literal string

Check failure on line 345 in app/gui/src/dashboard/layouts/AssetContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetContextMenu.tsx#L345

[no-restricted-syntax] Use a `getText()` from `useText` instead of a literal string

Check failure on line 345 in app/gui/src/dashboard/layouts/AssetContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetContextMenu.tsx#L345

[no-restricted-syntax] Use a `getText()` from `useText` instead of a literal string
getText(ASSET_TYPE_TO_TEXT_ID[asset.type]),
asset.title,
)}
onConfirm={async () => {
await deleteAssetsMutation([[asset.id], false])
}}
/>,
)
}}
/>
)}
Expand Down
35 changes: 14 additions & 21 deletions app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
})

// This is not a React component even though it contains JSX.
const doDeleteAll = useEventCallback(async () => {

Check failure on line 131 in app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx#L131

[@typescript-eslint/require-await] Async arrow function has no 'await' expression.

Check failure on line 131 in app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx#L131

[@typescript-eslint/require-await] Async arrow function has no 'await' expression.

Check failure on line 131 in app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx#L131

[@typescript-eslint/require-await] Async arrow function has no 'await' expression.

Check failure on line 131 in app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx

View workflow job for this annotation

GitHub Actions / 🧹 GUI Lint Results

app/gui/src/dashboard/layouts/AssetsTableContextMenu.tsx#L131

[@typescript-eslint/require-await] Async arrow function has no 'await' expression.
const selectedIds = selectedAssets.map((asset) => asset.id)
const deleteAll = async () => {
unsetModal()
Expand All @@ -136,27 +136,20 @@

await deleteAssetsMutation.mutateAsync([selectedIds, false])
}
if (
isCloud &&
selectedIds.every((key) => getAsset(key)?.type !== backendModule.AssetType.directory)
) {
await deleteAll()
} else {
const firstKey = selectedIds[0]
const soleAssetName =
firstKey != null ? (getAsset(firstKey)?.title ?? '(unknown)') : '(unknown)'
setModal(
<ConfirmDeleteModal
defaultOpen
actionText={
selectedIds.length === 1 ?
getText('deleteSelectedAssetActionText', soleAssetName)
: getText('deleteSelectedAssetsActionText', selectedIds.length)
}
onConfirm={deleteAll}
/>,
)
}
const firstKey = selectedIds[0]
const soleAssetName =
firstKey != null ? (getAsset(firstKey)?.title ?? '(unknown)') : '(unknown)'
setModal(
<ConfirmDeleteModal
defaultOpen
actionText={
selectedIds.length === 1 ?
getText('deleteSelectedAssetActionText', soleAssetName)
: getText('deleteSelectedAssetsActionText', selectedIds.length)
}
onConfirm={deleteAll}
/>,
)
})

const copyIdsMenuEntry = showDeveloperIds && (
Expand Down
Loading