Add initial selection, and deselection functionality
This commit is contained in:
parent
02934e0426
commit
0d13eb20e0
1 changed files with 26 additions and 10 deletions
|
|
@ -106,20 +106,36 @@ export const SnapshotsTable = ({ snapshots, repositoryId, backups, listSnapshots
|
||||||
const isShiftClick = event && "shiftKey" in event && event.shiftKey;
|
const isShiftClick = event && "shiftKey" in event && event.shiftKey;
|
||||||
|
|
||||||
// Attempt range selection first
|
// Attempt range selection first
|
||||||
if (isShiftClick && lastSelectedId) {
|
if (isShiftClick && snapshots.length > 0) {
|
||||||
const lastIndex = snapshots.findIndex((s) => s.short_id === lastSelectedId);
|
|
||||||
const currentIndex = snapshots.findIndex((s) => s.short_id === snapshotId);
|
const currentIndex = snapshots.findIndex((s) => s.short_id === snapshotId);
|
||||||
|
|
||||||
if (lastIndex !== -1 && currentIndex !== -1) {
|
if (currentIndex !== -1) {
|
||||||
// Valid range selection
|
// If lastSelectedId exists, use it; otherwise start from the first item (index 0)
|
||||||
const start = Math.min(lastIndex, currentIndex);
|
let startIndex: number;
|
||||||
const end = Math.max(lastIndex, currentIndex);
|
if (lastSelectedId) {
|
||||||
|
startIndex = snapshots.findIndex((s) => s.short_id === lastSelectedId);
|
||||||
|
// If lastSelectedId no longer exists in snapshots (stale reference), fall back to single selection
|
||||||
|
if (startIndex === -1) {
|
||||||
|
const newSelected = new Set(selectedIds);
|
||||||
|
if (newSelected.has(snapshotId)) {
|
||||||
|
newSelected.delete(snapshotId);
|
||||||
|
} else {
|
||||||
|
newSelected.add(snapshotId);
|
||||||
|
}
|
||||||
|
setSelectedIds(newSelected);
|
||||||
|
setLastSelectedId(snapshotId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
startIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid range selection - replace the entire selection with the new range
|
||||||
|
const start = Math.min(startIndex, currentIndex);
|
||||||
|
const end = Math.max(startIndex, currentIndex);
|
||||||
const rangeIds = new Set(snapshots.slice(start, end + 1).map((s) => s.short_id));
|
const rangeIds = new Set(snapshots.slice(start, end + 1).map((s) => s.short_id));
|
||||||
|
|
||||||
// Add selected range to existing selection
|
setSelectedIds(rangeIds);
|
||||||
const newSelected = new Set(selectedIds);
|
|
||||||
rangeIds.forEach((id) => newSelected.add(id));
|
|
||||||
setSelectedIds(newSelected);
|
|
||||||
setLastSelectedId(snapshotId);
|
setLastSelectedId(snapshotId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue