-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renterd): directory mode files multiselect and batch delete
- Loading branch information
1 parent
70ee5a4
commit 474ab7c
Showing
13 changed files
with
233 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
apps/renterd/components/FilesDirectory/FilesDirectoryBatchMenu/FilesDirectoryBatchDelete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { | ||
Button, | ||
Paragraph, | ||
triggerSuccessToast, | ||
triggerErrorToast, | ||
} from '@siafoundation/design-system' | ||
import { Delete16 } from '@siafoundation/react-icons' | ||
import { useCallback, useMemo } from 'react' | ||
import { useDialog } from '../../../contexts/dialog' | ||
import { useFilesDirectory } from '../../../contexts/filesDirectory' | ||
import { useObjectsRemove } from '@siafoundation/renterd-react' | ||
|
||
export function FilesDirectoryBatchDelete() { | ||
const { multiSelect } = useFilesDirectory() | ||
|
||
const filesToDelete = useMemo( | ||
() => | ||
Object.entries(multiSelect.selectionMap).map(([_, item]) => ({ | ||
bucket: item.bucket.name, | ||
prefix: item.key, | ||
})), | ||
[multiSelect.selectionMap] | ||
) | ||
const { openConfirmDialog } = useDialog() | ||
const objectsRemove = useObjectsRemove() | ||
const deleteFiles = useCallback(async () => { | ||
const totalCount = filesToDelete.length | ||
let errorCount = 0 | ||
for (const { bucket, prefix } of filesToDelete) { | ||
const response = await objectsRemove.post({ | ||
payload: { | ||
bucket, | ||
prefix, | ||
}, | ||
}) | ||
if (response.error) { | ||
errorCount++ | ||
} | ||
} | ||
if (errorCount > 0) { | ||
triggerErrorToast({ | ||
title: `${totalCount - errorCount} files deleted`, | ||
body: `Error deleting ${errorCount}/${totalCount} total files.`, | ||
}) | ||
} else { | ||
triggerSuccessToast({ title: `${totalCount} files deleted` }) | ||
} | ||
multiSelect.deselectAll() | ||
}, [multiSelect, filesToDelete, objectsRemove]) | ||
|
||
return ( | ||
<Button | ||
aria-label="delete selected files" | ||
tip="Delete selected files" | ||
onClick={() => { | ||
openConfirmDialog({ | ||
title: `Delete files`, | ||
action: 'Delete', | ||
variant: 'red', | ||
body: ( | ||
<div className="flex flex-col gap-1"> | ||
<Paragraph size="14"> | ||
Are you sure you would like to delete the{' '} | ||
{multiSelect.selectionCount.toLocaleString()} selected files? | ||
</Paragraph> | ||
</div> | ||
), | ||
onConfirm: async () => { | ||
deleteFiles() | ||
}, | ||
}) | ||
}} | ||
> | ||
<Delete16 /> | ||
</Button> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
apps/renterd/components/FilesDirectory/FilesDirectoryBatchMenu/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { MultiSelectionMenu } from '@siafoundation/design-system' | ||
import { FilesDirectoryBatchDelete } from './FilesDirectoryBatchDelete' | ||
import { useFilesDirectory } from '../../../contexts/filesDirectory' | ||
|
||
export function FilesDirectoryBatchMenu() { | ||
const { multiSelect } = useFilesDirectory() | ||
|
||
return ( | ||
<MultiSelectionMenu multiSelect={multiSelect} entityWord="file"> | ||
<FilesDirectoryBatchDelete /> | ||
</MultiSelectionMenu> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.