Displaying confirmation modal when deleting tagged files, rather than just refusing to delete them.

This commit is contained in:
Roland 2026-04-14 10:40:24 -06:00
parent 4380cab88c
commit 8fb9e35aef
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
7 changed files with 133 additions and 55 deletions

View file

@ -1386,10 +1386,18 @@ export async function getFile(path, skipTracking = false) {
}
}
export async function deleteFile(paths) {
let body = {paths: paths};
export async function deleteFile(paths, force = false) {
let body = {paths: paths, force: force};
const response = await apiPost(`${API_URI}/files/delete`, body);
if (!response.ok) {
try {
const json = await response.clone().json();
if (json.code === 'FILE_GROUP_IS_TAGGED' && json.file_groups) {
return {tagged: true, file_groups: json.file_groups};
}
} catch (e) {
// Not JSON, fall through to generic error.
}
const message = await getErrorMessage(response, 'Failed to delete file. See server logs.');
toast({
type: 'error',

View file

@ -212,6 +212,8 @@ export function FileBrowser() {
const [isDirectoryIgnored, setIsDirectoryIgnored] = React.useState(false);
// Tracks folder that was opened while selected - its children will be auto-selected when they load
const pendingAutoSelectRef = React.useRef(null);
// Tagged file groups that would be deleted - shown in confirmation modal
const [taggedFileGroups, setTaggedFileGroups] = React.useState(null);
const {settings, fetchSettings} = React.useContext(SettingsContext);
const {inverted} = React.useContext(ThemeContext);
@ -294,8 +296,7 @@ export function FileBrowser() {
await fetchSettings();
}
const onDelete = async () => {
await deleteFile(selectedPaths);
const handleDeleteComplete = async () => {
// Remove deleted directories from openFolders to prevent fetching non-existent directories
const deletedDirs = selectedPaths.filter(p => p.endsWith('/'));
if (deletedDirs.length > 0 && openFolders && openFolders.length > 0) {
@ -307,6 +308,24 @@ export function FileBrowser() {
await reset();
};
const onDelete = async () => {
const result = await deleteFile(selectedPaths);
if (result && result.tagged) {
// Show modal with tagged file groups for user to confirm.
setTaggedFileGroups(result.file_groups);
return;
}
await handleDeleteComplete();
};
const onForceDelete = async () => {
setTaggedFileGroups(null);
const result = await deleteFile(selectedPaths, true);
if (result && result.tagged) return; // unexpected tagged response
if (result && !result.ok) return; // error already toasted
await handleDeleteComplete();
};
const handleMakeDirectory = async () => {
setMakeDirectoryOpen(false);
await reset();
@ -412,6 +431,38 @@ export function FileBrowser() {
paths={selectedPaths}
onComplete={reset}
/>
<Modal
open={taggedFileGroups !== null}
onClose={() => setTaggedFileGroups(null)}
closeIcon
>
<Modal.Header><Icon name='warning sign'/> Tagged Files Will Be Deleted</Modal.Header>
<Modal.Content>
<p>The following tagged files will be deleted:</p>
<Table>
<TableHeader>
<TableRow>
<TableHeaderCell>File</TableHeaderCell>
<TableHeaderCell>Tags</TableHeaderCell>
</TableRow>
</TableHeader>
<TableBody>
{taggedFileGroups && taggedFileGroups.map((fg, idx) => (
<TableRow key={idx}>
<TableCell>{fg.primary_path || fg.name}</TableCell>
<TableCell>{(fg.tags || []).join(', ')}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Modal.Content>
<Modal.Actions>
<Button onClick={() => setTaggedFileGroups(null)}>Cancel</Button>
<Button color='red' onClick={onForceDelete}>
<Icon name='trash'/> Delete
</Button>
</Modal.Actions>
</Modal>
</div>;
const onFolderClick = async (folder) => {