Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
feat: add shift-select ranges to selectable tables (#3943)
Kyle Mendell472b01f5855c
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-checkbox.svelte b/frontend/src/lib/components/arcane-table/arcane-table-checkbox.svelteindex e41bb6fc5..3cec3a654 100644--- a/frontend/src/lib/components/arcane-table/arcane-table-checkbox.svelte+++ b/frontend/src/lib/components/arcane-table/arcane-table-checkbox.svelte@@ -1,8 +1,37 @@<script lang="ts">import { Checkbox } from '#lib/components/ui/checkbox/index.js';import type { ComponentProps } from 'svelte';+ import type { SelectionModifiers } from './arcane-table.types.svelte';- let { checked = false, onCheckedChange, ...restProps }: ComponentProps<typeof Checkbox> = $props();+ let {+ checked = false,+ onCheckedChange,+ onclick,+ onkeydown,+ ...restProps+ }: Omit<ComponentProps<typeof Checkbox>, 'onCheckedChange'> & {+ onCheckedChange?: (checked: boolean, modifiers: SelectionModifiers) => void;+ } = $props();++ let shiftKey = false;++ function handleCheckedChange(value: boolean) {+ const modifiers = { shiftKey };+ shiftKey = false;+ onCheckedChange?.(value, modifiers);+ }</script>-<Checkbox {checked} {onCheckedChange} {...restProps} />+<Checkbox+ {checked}+ onCheckedChange={handleCheckedChange}+ onclick={(event) => {+ shiftKey = event.shiftKey;+ onclick?.(event);+ }}+ onkeydown={(event) => {+ shiftKey = event.key === ' ' && event.shiftKey;+ onkeydown?.(event);+ }}+ {...restProps}+/>diff --git a/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte b/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelteindex 6c72116e4..c96ef36cf 100644--- a/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte+++ b/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte@@ -12,7 +12,8 @@type ColumnWidth,type ColumnAlign,type GroupedData,- type GroupSelectionState+ type GroupSelectionState,+ type SelectionModifiers} from './arcane-table.types.svelte';import TableCheckbox from './arcane-table-checkbox.svelte';import TableEmpty from './table-empty.svelte';@@ -57,7 +58,7 @@onGroupToggle?: (groupName: string) => void;getGroupSelectionState?: (groupItems: TData[]) => GroupSelectionState;onToggleGroupSelection?: (groupItems: TData[]) => void;- onToggleRowSelection?: (id: string, selected: boolean) => void;+ onToggleRowSelection?: (id: string, selected: boolean, modifiers?: SelectionModifiers) => void;unstyled?: boolean;expandedRowContent?: Snippet<[{ row: ArcaneRow<TData>; item: TData }]>;expandedRows?: Set<string>;@@ -105,7 +106,11 @@}if (selectionDisabled) return;const isSelected = selectedIdSet.has(rowId);- onToggleRowSelection?.(rowId, !isSelected);+ onToggleRowSelection?.(rowId, !isSelected, { shiftKey: event.shiftKey });+ }++ function handleRowMouseDown(event: MouseEvent) {+ if (event.shiftKey && !hasExpand && !selectionDisabled && !shouldIgnoreTableRowClick(event)) event.preventDefault();}// Get cell classes based on column metadata@@ -254,6 +259,7 @@data-state={selectedIdSet.has(rowId) && 'selected'}data-expanded={isExpanded ? true : undefined}onclick={(event) => handleRowClick(event, rowId)}+ onmousedown={handleRowMouseDown}class={cn('isolate', hasExpand && 'cursor-pointer', isExpanded && 'bg-muted/30')}>{#if hasExpand}diff --git a/frontend/src/lib/components/arcane-table/arcane-table.svelte b/frontend/src/lib/components/arcane-table/arcane-table.svelteindex 6acb9aa69..32283b546 100644--- a/frontend/src/lib/components/arcane-table/arcane-table.svelte+++ b/frontend/src/lib/components/arcane-table/arcane-table.svelte@@ -16,6 +16,7 @@type FieldSpec,type GroupedData,type GroupSelectionState,+ type SelectionModifiers,type SortState,encodeHidden,applyHiddenPatch,@@ -26,7 +27,13 @@type BulkAction} from './arcane-table.types.svelte';import type { Component } from 'svelte';- import { extractPersistedPreferences, fromFilterMap, restoreTableRequestOptions, toFilterMap } from './arcane-table.utils';+ import {+ extractPersistedPreferences,+ fromFilterMap,+ getTableRowsForItems,+ restoreTableRequestOptions,+ toFilterMap+ } from './arcane-table.utils';import ArcaneTablePagination from './arcane-table-pagination.svelte';import ArcaneTableHeader from './arcane-table-header.svelte';import ArcaneTableCell from './arcane-table-cell.svelte';@@ -306,12 +313,25 @@}}- function onToggleRow(checked: boolean, id: string) {+ // Shift-select anchor; valid only against the row order and selection array it was recorded with.+ let rangeAnchor: { id: string; orderKey: string; selection: string[] | undefined } | null = null;++ function onToggleRow(checked: boolean, id: string, modifiers?: SelectionModifiers) {+ const ids = orderedRowIds;+ const orderKey = ids.join('\0');+ const anchor =+ modifiers?.shiftKey && rangeAnchor?.orderKey === orderKey && rangeAnchor.selection === selectedIds ? rangeAnchor : null;+ const anchorIndex = anchor ? ids.indexOf(anchor.id) : -1;+ const targetIndex = anchor ? ids.indexOf(id) : -1;+ const useRange = anchorIndex >= 0 && targetIndex >= 0;+ const rangeIds = useRange ? ids.slice(Math.min(anchorIndex, targetIndex), Math.max(anchorIndex, targetIndex) + 1) : [id];if (checked) {- if (!selectedIds?.includes(id)) selectedIds = [...(selectedIds ?? []), id];+ selectedIds = Array.from(new Set([...(selectedIds ?? []), ...rangeIds]));} else {- selectedIds = (selectedIds ?? []).filter((x) => x !== id);+ const remove = new Set(rangeIds);+ selectedIds = (selectedIds ?? []).filter((x) => !remove.has(x));}+ rangeAnchor = { id: useRange && anchor ? anchor.id : id, orderKey, selection: selectedIds };}function buildColumns(specs: ColumnSpec<TData>[], isSelectionDisabled: boolean): ArcaneColumnDef<TData>[] {@@ -339,7 +359,7 @@const id = (row.original as TData).id;return renderComponent(TableCheckbox, {checked: (selectedIds ?? []).includes(id),- onCheckedChange: (value) => onToggleRow(!!value, id),+ onCheckedChange: (value, modifiers) => onToggleRow(!!value, id, modifiers),'aria-label': m.common_select_row()});},@@ -616,6 +636,15 @@}));});+ // Row ids in display order (flat model, or expanded groups in group order), matching the desktop view.+ const orderedRowIds = $derived.by((): string[] => {+ const groups = effectiveGroupedRows;+ if (!groups || groups.length === 0) return table.getRowModel().rows.map((row) => row.id);+ return groups.flatMap((group) =>+ (groupCollapsedState[group.groupName] ?? true) ? [] : getTableRowsForItems(rowIndex, group.items).map((row) => row.id)+ );+ });+// Get selection state for a groupfunction getGroupSelectionState(groupItems: TData[]): GroupSelectionState {const groupIds = groupItems.map((item) => item.id);@@ -741,7 +770,7 @@onGroupToggle={handleGroupToggle}{getGroupSelectionState}{onToggleGroupSelection}- onToggleRowSelection={(id, selected) => onToggleRow(selected, id)}+ onToggleRowSelection={(id, selected, modifiers) => onToggleRow(selected, id, modifiers)}{unstyled}{expandedRowContent}{expandedRows}diff --git a/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts b/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.tsindex 59f4a17e6..6beaa133b 100644--- a/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts+++ b/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts@@ -166,6 +166,8 @@ export type GroupedData<T> = {export type GroupSelectionState = 'none' | 'some' | 'all';+export type SelectionModifiers = { shiftKey: boolean };+export function shouldIgnoreTableRowClick(event: MouseEvent): boolean {const target = event.target as HTMLElement | null;return !!target?.closest('a, button, input, [role="checkbox"], [data-slot="checkbox"], [data-row-select-ignore]');diff --git a/tests/spec/container-grouped-pagination.spec.ts b/tests/spec/container-grouped-pagination.spec.tsindex ad284cc99..3a403ff4a 100644--- a/tests/spec/container-grouped-pagination.spec.ts+++ b/tests/spec/container-grouped-pagination.spec.ts@@ -1,4 +1,4 @@-import { expect, test } from '../fixtures/test.fixture';+import { expect, test, type Page } from '../fixtures/test.fixture';type MockContainer = {id: string;@@ -184,3 +184,160 @@ test('grouped containers do not split the same project across pages', async ({ pawait expect(page.getByRole('link', { name: 'immich-redis', exact: true })).toBeVisible();await expect(page.getByRole('link', { name: 'immich-postgres', exact: true })).toBeVisible();});++type MockGroup = { groupName: string; items: MockContainer[] };++async function mockGroupedContainers(page: Page, groups: MockGroup[]) {+ const allContainers = groups.flatMap((group) => group.items);+ await page.context().route('**/containers**', async (route) => {+ const url = new URL(route.request().url());+ if (+ route.request().method() !== 'GET' ||+ !/^\/api\/environments\/[^/]+\/containers$/.test(url.pathname)+ ) {+ await route.continue();+ return;+ }+ const response = buildContainersResponse(allContainers, 0, -1);+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify(+ url.searchParams.get('groupBy') === 'project' ? { ...response, groups } : response+ )+ });+ });+}++function containerRow(page: Page, name: string) {+ return page.getByRole('row').filter({ has: page.getByRole('link', { name, exact: true }) });+}++function groupRow(page: Page, groupName: string) {+ return page.locator('table tbody tr').filter({ has: page.getByText(groupName, { exact: true }) });+}++async function expectContainersSelected(page: Page, names: string[], selected: boolean) {+ for (const name of names) {+ await expect(containerRow(page, name).getByRole('checkbox')).toHaveAttribute(+ 'aria-checked',+ selected ? 'true' : 'false'+ );+ }+}++async function openGroupedContainers(page: Page, collapsed: Record<string, boolean>) {+ await page.addInitScript((collapsedState) => {+ localStorage.removeItem('selectedEnvironmentId');+ localStorage.removeItem('arcane-container-table');+ localStorage.setItem('container-groups-collapsed', JSON.stringify(collapsedState));+ localStorage.removeItem('collapsible-cards-expanded');+ }, collapsed);++ const groups: MockGroup[] = [+ {+ groupName: 'immich',+ items: [+ createContainer('immich-1', 'immich-server', 'immich', 900),+ createContainer('immich-2', 'immich-machine-learning', 'immich', 899),+ createContainer('immich-3', 'immich-redis', 'immich', 898),+ createContainer('immich-4', 'immich-postgres', 'immich', 897)+ ]+ },+ { groupName: 'alpha', items: [createContainer('alpha-1', 'alpha-service', 'alpha', 800)] },+ {+ groupName: 'beta',+ items: [+ createContainer('beta-1', 'beta-web', 'beta', 700),+ createContainer('beta-2', 'beta-db', 'beta', 699)+ ]+ },+ { groupName: 'gamma', items: [createContainer('gamma-1', 'gamma-service', 'gamma', 600)] }+ ];+ await mockGroupedContainers(page, groups);+ await page.setViewportSize({ width: 1440, height: 900 });+ await page.goto('/containers');+ await page.waitForLoadState('load');+ await page.getByRole('button', { name: 'View' }).click();+ await page.getByRole('menuitemcheckbox', { name: 'Group by Project' }).click();+ await page.keyboard.press('Escape');+ await expect(groupRow(page, 'immich')).toContainText('(4)');+ await expect(page.getByRole('link', { name: 'immich-server', exact: true })).toBeVisible();+}++test.describe('grouped shift-select', () => {+ test('ranges follow group order and skip collapsed groups', async ({ page }) => {+ await openGroupedContainers(page, { immich: false, alpha: false, gamma: false });+ await expect(page.getByRole('link', { name: 'beta-web', exact: true })).toHaveCount(0);++ await containerRow(page, 'immich-machine-learning').getByRole('checkbox').click();+ await containerRow(page, 'gamma-service')+ .getByRole('checkbox')+ .click({ modifiers: ['Shift'] });++ await expectContainersSelected(+ page,+ [+ 'immich-machine-learning',+ 'immich-redis',+ 'immich-postgres',+ 'alpha-service',+ 'gamma-service'+ ],+ true+ );+ await expectContainersSelected(page, ['immich-server'], false);+ await expect(groupRow(page, 'beta').getByRole('checkbox')).toHaveAttribute(+ 'aria-checked',+ 'false'+ );+ await expect(groupRow(page, 'alpha').getByRole('checkbox')).toHaveAttribute(+ 'aria-checked',+ 'true'+ );+ await expect(groupRow(page, 'immich').getByRole('checkbox')).toHaveAttribute(+ 'aria-checked',+ 'mixed'+ );+ await expect(page.getByRole('button', { name: 'Stop (5)', exact: true })).toBeVisible();++ await groupRow(page, 'beta').click();+ await expect(page.getByRole('link', { name: 'beta-web', exact: true })).toBeVisible();+ await expectContainersSelected(page, ['beta-web', 'beta-db'], false);+ });++ test('expanded groups are included and group or collapse changes reset the anchor', async ({+ page+ }) => {+ await openGroupedContainers(page, { immich: false, alpha: false, beta: false });++ await containerRow(page, 'immich-postgres').getByRole('checkbox').click();+ await containerRow(page, 'beta-db')+ .getByRole('checkbox')+ .click({ modifiers: ['Shift'] });+ await expectContainersSelected(+ page,+ ['immich-postgres', 'alpha-service', 'beta-web', 'beta-db'],+ true+ );+ await expectContainersSelected(page, ['immich-server', 'immich-redis'], false);++ await groupRow(page, 'alpha').getByRole('checkbox').click();+ await expectContainersSelected(page, ['alpha-service'], false);+ await containerRow(page, 'immich-server')+ .getByRole('checkbox')+ .click({ modifiers: ['Shift'] });+ await expectContainersSelected(page, ['immich-server'], true);+ await expectContainersSelected(page, ['immich-machine-learning', 'immich-redis'], false);++ await containerRow(page, 'immich-machine-learning').getByRole('checkbox').click();+ await groupRow(page, 'alpha').click();+ await expect(page.getByRole('link', { name: 'alpha-service', exact: true })).toHaveCount(0);+ await containerRow(page, 'beta-db')+ .getByRole('checkbox')+ .click({ modifiers: ['Shift'] });+ await expectContainersSelected(page, ['immich-machine-learning', 'beta-web'], true);+ await expectContainersSelected(page, ['immich-redis', 'beta-db'], false);+ await expect(page.getByRole('button', { name: 'Stop (4)', exact: true })).toBeVisible();+ });+});diff --git a/tests/spec/volumes.spec.ts b/tests/spec/volumes.spec.tsindex 56092ada8..07a1d5e08 100644--- a/tests/spec/volumes.spec.ts+++ b/tests/spec/volumes.spec.ts@@ -317,3 +317,362 @@ test.describe('Volumes Page', () => {}});});++type MockVolume = {+ id: string;+ name: string;+ driver: string;+ mountpoint: string;+ scope: string;+ options: null;+ labels: Record<string, string>;+ createdAt: string;+ inUse: boolean;+ size: number;+};++function mockVolume(index: number): MockVolume {+ const name = `shift-vol-${String(index).padStart(3, '0')}`;+ return {+ id: name,+ name,+ driver: 'local',+ mountpoint: `/var/lib/docker/volumes/${name}/_data`,+ scope: 'local',+ options: null,+ labels: {},+ createdAt: new Date(1_700_000_000_000 + index * 60_000).toISOString(),+ inUse: index % 2 === 0,+ size: index+ };+}++function volumesPage(volumes: MockVolume[], url: URL) {+ const search = (url.searchParams.get('search') ?? '').toLowerCase();+ const sort = url.searchParams.get('sort') ?? 'name';+ const order = url.searchParams.get('order') ?? 'asc';+ const start = Number(url.searchParams.get('start') ?? '0');+ const limit = Number(url.searchParams.get('limit') ?? '20');+ const filtered = volumes.filter((volume) => volume.name.toLowerCase().includes(search));+ const sorted = [...filtered].sort((a, b) => {+ const av = a[sort as keyof MockVolume];+ const bv = b[sort as keyof MockVolume];+ const cmp =+ typeof av === 'number' && typeof bv === 'number'+ ? av - bv+ : String(av).localeCompare(String(bv));+ return order === 'desc' ? -cmp : cmp;+ });+ const data = limit === -1 ? sorted : sorted.slice(start, start + limit);+ const inuse = volumes.filter((volume) => volume.inUse).length;+ return {+ success: true,+ data,+ counts: { inuse, unused: volumes.length - inuse, total: volumes.length },+ pagination: {+ totalPages: limit === -1 ? 1 : Math.max(1, Math.ceil(sorted.length / limit)),+ totalItems: sorted.length,+ currentPage: limit === -1 ? 1 : Math.floor(start / limit) + 1,+ itemsPerPage: limit === -1 ? sorted.length : limit,+ grandTotalItems: volumes.length+ }+ };+}++async function mockVolumeList(page: Page, volumesByEnv: Record<string, MockVolume[]>) {+ await page.context().route(/\/api\/environments\/[^/]+\/volumes(?:\?.*)?$/, async (route) => {+ const request = route.request();+ const url = new URL(request.url());+ const envId = url.pathname.split('/')[3];+ const volumes = volumesByEnv[envId];+ if (request.method() !== 'GET' || !volumes) {+ await route.continue();+ return;+ }+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify(volumesPage(volumes, url))+ });+ });+ await page.context().route(/\/api\/environments\/[^/]+\/volumes\/sizes$/, async (route) => {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({ success: true, data: [] })+ });+ });+}++function volumeRow(page: Page, index: number) {+ const name = mockVolume(index).name;+ return page.getByRole('row').filter({ has: page.getByRole('link', { name, exact: true }) });+}++function rowCheckbox(page: Page, index: number) {+ return volumeRow(page, index).getByRole('checkbox');+}++async function expectSelected(page: Page, indexes: number[], selected: boolean) {+ for (const index of indexes) {+ await expect(rowCheckbox(page, index)).toHaveAttribute(+ 'aria-checked',+ selected ? 'true' : 'false'+ );+ if (selected) await expect(volumeRow(page, index)).toHaveAttribute('data-state', 'selected');+ else await expect(volumeRow(page, index)).not.toHaveAttribute('data-state', 'selected');+ }+}++function removeSelectedButton(page: Page, count: number) {+ return page.getByRole('button', { name: `Remove Selected (${count})`, exact: true });+}++async function openShiftSelectVolumes(page: Page, count = 12) {+ const volumes = Array.from({ length: count }, (_, index) => mockVolume(index + 1));+ await page.addInitScript(() => {+ localStorage.removeItem('selectedEnvironmentId');+ localStorage.removeItem('arcane-volumes-table');+ });+ await mockVolumeList(page, { '0': volumes });+ await page.goto('/volumes');+ await expect(page.getByRole('link', { name: volumes[0].name, exact: true })).toBeVisible();+ return volumes;+}++test.describe('Volumes shift-select', () => {+ test('shift-click selects the range between anchor and target', async ({ page }) => {+ await openShiftSelectVolumes(page);++ await rowCheckbox(page, 2).click();+ await rowCheckbox(page, 6).click({ modifiers: ['Shift'] });++ await expectSelected(page, [2, 3, 4, 5, 6], true);+ await expectSelected(page, [1, 7, 8], false);+ await expect(removeSelectedButton(page, 5)).toBeVisible();+ });++ test('reverse range via row clicks keeps selections outside the range', async ({ page }) => {+ await openShiftSelectVolumes(page);++ await rowCheckbox(page, 1).click();+ await volumeRow(page, 9).getByRole('cell').nth(3).click();+ await volumeRow(page, 5)+ .getByRole('cell')+ .nth(3)+ .click({ modifiers: ['Shift'] });++ await expectSelected(page, [1, 5, 6, 7, 8, 9], true);+ await expectSelected(page, [2, 3, 4, 10], false);+ await expect(removeSelectedButton(page, 6)).toBeVisible();+ });++ test('shift-click deselects a range when the target is being unchecked', async ({ page }) => {+ await openShiftSelectVolumes(page);++ await rowCheckbox(page, 1).click();+ await rowCheckbox(page, 8).click({ modifiers: ['Shift'] });+ await expect(removeSelectedButton(page, 8)).toBeVisible();++ await rowCheckbox(page, 3).click();+ await rowCheckbox(page, 6).click({ modifiers: ['Shift'] });++ await expectSelected(page, [3, 4, 5, 6], false);+ await expectSelected(page, [1, 2, 7, 8], true);+ await expect(removeSelectedButton(page, 4)).toBeVisible();+ });++ test('repeated shift-clicks keep the original anchor', async ({ page }) => {+ await openShiftSelectVolumes(page);++ await rowCheckbox(page, 3).click();+ await rowCheckbox(page, 5).click({ modifiers: ['Shift'] });+ await rowCheckbox(page, 8).click({ modifiers: ['Shift'] });++ await expectSelected(page, [3, 4, 5, 6, 7, 8], true);+ await expectSelected(page, [1, 2, 9], false);++ await rowCheckbox(page, 1).click({ modifiers: ['Shift'] });+ await expectSelected(page, [1, 2, 3], true);+ await expect(removeSelectedButton(page, 8)).toBeVisible();+ });++ test('shift-click without an anchor behaves like a normal click', async ({ page }) => {+ await openShiftSelectVolumes(page);++ await rowCheckbox(page, 4).click({ modifiers: ['Shift'] });++ await expectSelected(page, [4], true);+ await expectSelected(page, [1, 2, 3, 5], false);+ await expect(removeSelectedButton(page, 1)).toBeVisible();+ });++ test('Shift+Space selects a range while Space toggles a single row', async ({ page }) => {+ await openShiftSelectVolumes(page);++ await rowCheckbox(page, 2).click();+ await rowCheckbox(page, 5).focus();+ await page.keyboard.press('Shift+Space');++ await expectSelected(page, [2, 3, 4, 5], true);+ await expectSelected(page, [1, 6], false);++ await rowCheckbox(page, 7).focus();+ await page.keyboard.press('Space');+ await expectSelected(page, [7], true);+ await expectSelected(page, [6], false);+ await expect(removeSelectedButton(page, 5)).toBeVisible();+ });++ test('header selection reflects ranges and resets the anchor', async ({ page }) => {+ await openShiftSelectVolumes(page);+ const headerCheckbox = page.getByRole('checkbox', { name: 'Select all' });++ await rowCheckbox(page, 2).click();+ await rowCheckbox(page, 3).click({ modifiers: ['Shift'] });+ await expect(headerCheckbox).toHaveAttribute('aria-checked', 'mixed');++ await headerCheckbox.click();+ await expect(headerCheckbox).toHaveAttribute('aria-checked', 'true');+ await expect(removeSelectedButton(page, 12)).toBeVisible();++ await headerCheckbox.click();+ await expect(headerCheckbox).toHaveAttribute('aria-checked', 'false');+ await expect(removeSelectedButton(page, 12)).toHaveCount(0);++ await rowCheckbox(page, 6).click({ modifiers: ['Shift'] });+ await expectSelected(page, [6], true);+ await expectSelected(page, [2, 3, 4, 5], false);+ });++ test('page, sort, and search changes reset the anchor', async ({ page }) => {+ await openShiftSelectVolumes(page, 30);++ await rowCheckbox(page, 2).click();+ await page.getByRole('button', { name: 'Go to next page' }).click();+ await expect(page.getByRole('link', { name: mockVolume(21).name, exact: true })).toBeVisible();+ await rowCheckbox(page, 25).click({ modifiers: ['Shift'] });+ await expectSelected(page, [25], true);+ await expectSelected(page, [21, 22, 23, 24], false);+ await expect(removeSelectedButton(page, 2)).toBeVisible();++ await page.getByRole('button', { name: 'Go to first page' }).click();+ await expect(page.getByRole('link', { name: mockVolume(1).name, exact: true })).toBeVisible();+ await rowCheckbox(page, 4).click();+ await page.getByRole('button', { name: 'Name', exact: true }).click();+ await page.getByRole('menuitem', { name: 'Desc' }).click();+ await expect(page.getByRole('link', { name: mockVolume(30).name, exact: true })).toBeVisible();+ await rowCheckbox(page, 12).click({ modifiers: ['Shift'] });+ await expectSelected(page, [12], true);+ await expectSelected(page, [11, 13], false);+ await expect(removeSelectedButton(page, 4)).toBeVisible();++ await page.getByPlaceholder('Search…').fill('shift-vol-01');+ await expect(page.getByRole('link', { name: mockVolume(30).name, exact: true })).toHaveCount(0);+ await rowCheckbox(page, 15).click({ modifiers: ['Shift'] });+ await expectSelected(page, [15], true);+ await expectSelected(page, [13, 14, 16], false);+ await expect(removeSelectedButton(page, 5)).toBeVisible();+ });++ test('switching environments resets the anchor', async ({ page }) => {+ const localEnvironment = {+ id: '0',+ name: 'Local Test',+ apiUrl: 'unix:///var/run/docker.sock',+ status: 'online',+ enabled: true,+ isEdge: false+ };+ const remoteEnvironment = {+ id: 'remote-shift-test',+ name: 'Remote Test',+ apiUrl: 'https://remote.example.invalid',+ status: 'online',+ enabled: true,+ isEdge: false+ };+ const environments = [localEnvironment, remoteEnvironment];+ await page.context().route(/\/api\/environments(?:\?.*)?$/, async (route) => {+ await route.fulfill({+ status: 200,+ contentType: 'application/json',+ body: JSON.stringify({+ success: true,+ data: environments,+ pagination: {+ totalPages: 1,+ totalItems: 2,+ currentPage: 1,+ itemsPerPage: 20,+ grandTotalItems: 2+ }+ })+ });+ });+ await page.context().route(/\/api\/stream(?:\?.*)?$/, async (route) => {+ const channels =+ new URL(route.request().url()).searchParams.get('channels')?.split(',') ?? [];+ const timestamp = new Date().toISOString();+ await route.fulfill({+ status: 200,+ contentType: 'application/x-json-stream',+ body: channels.includes('environments')+ ? `${JSON.stringify({ channel: 'environments', environment: { type: 'snapshot', environments, timestamp }, timestamp })}\n`+ : ''+ });+ });+ await page+ .context()+ .route(/\/api\/environments\/remote-shift-test\/settings$/, async (route) => {+ await route.fulfill({ status: 200, contentType: 'application/json', body: '{}' });+ });+ const remoteVolumes = Array.from({ length: 8 }, (_, index) => mockVolume(index + 101));+ await page.addInitScript(() => {+ localStorage.removeItem('selectedEnvironmentId');+ localStorage.removeItem('arcane-volumes-table');+ });+ await mockVolumeList(page, {+ '0': Array.from({ length: 12 }, (_, index) => mockVolume(index + 1)),+ 'remote-shift-test': remoteVolumes+ });+ await page.goto('/volumes');+ await expect(page.getByRole('link', { name: mockVolume(1).name, exact: true })).toBeVisible();++ await rowCheckbox(page, 2).click();+ await page.getByRole('button').filter({ hasText: localEnvironment.name }).first().click();+ const dialog = page.getByRole('dialog', { name: 'Select Environment' });+ await expect(dialog).toBeVisible();+ await dialog.getByRole('button').filter({ hasText: remoteEnvironment.name }).first().click();+ await expect(page.getByRole('link', { name: mockVolume(101).name, exact: true })).toBeVisible();+ await expect(page.getByRole('link', { name: mockVolume(1).name, exact: true })).toHaveCount(0);++ await rowCheckbox(page, 105).click({ modifiers: ['Shift'] });+ await expectSelected(page, [105], true);+ await expectSelected(page, [101, 102, 103, 104], false);+ await expect(removeSelectedButton(page, 1)).toBeVisible();+ });++ test('ranges span a virtualized list larger than 100 rows', async ({ page }) => {+ const volumes = Array.from({ length: 150 }, (_, index) => mockVolume(index + 1));+ await page.addInitScript(() => {+ localStorage.removeItem('selectedEnvironmentId');+ localStorage.setItem('arcane-volumes-table', JSON.stringify({ v: [], f: [], g: '', l: -1 }));+ });+ await mockVolumeList(page, { '0': volumes });+ await page.goto('/volumes');+ await expect(page.getByRole('link', { name: mockVolume(1).name, exact: true })).toBeVisible();+ await expect(page.locator('table tbody tr[data-index]').first()).toBeAttached();++ await rowCheckbox(page, 1).click();+ await rowCheckbox(page, 140).scrollIntoViewIfNeeded();+ await rowCheckbox(page, 140).click({ modifiers: ['Shift'] });++ await expect(removeSelectedButton(page, 140)).toBeVisible();+ await expectSelected(page, [140], true);+ await expectSelected(page, [141, 150], false);++ await rowCheckbox(page, 1).scrollIntoViewIfNeeded();+ await expectSelected(page, [1, 2, 3, 70], true);+ });+});