Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 42 additions & 9 deletions e2e/storage/connections-management.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test, expect, type Page } from '../support/fixtures.js';
import { test, expect, type Locator, type Page } from '../support/fixtures.js';
import {
createGarageBucketCredentials,
hasGarageAdmin,
Expand All @@ -21,6 +21,29 @@ async function openFirstConnectionEditPage(page: Page) {
await waitForHydration(page);
}

/**
* Asserts that an open dropdown menu sits right below its trigger, aligned to its end. Up to 8 px
* gap for the scripted fallback in browsers without CSS anchor positioning; a few px for the
* popover's padding and border around the menu.
*/
async function expectMenuBelow(trigger: Locator, menu: Locator) {
await expect(menu).toBeVisible();
// Let DaisyUI's scale-in animation finish before measuring.
await menu.evaluate((el) =>
Promise.all(
el
.closest('[popover]')!
.getAnimations()
.map((a) => a.finished)
)
);
const t = (await trigger.boundingBox())!;
const m = (await menu.boundingBox())!;
expect(m.y).toBeGreaterThanOrEqual(t.y + t.height - 1);
expect(m.y).toBeLessThan(t.y + t.height + 14);
expect(Math.abs(m.x + m.width - (t.x + t.width))).toBeLessThan(14);
}

test.describe('Storage — Connections management', () => {
test.use({ locale: 'en-US' });

Expand Down Expand Up @@ -184,10 +207,11 @@ test.describe('Storage — Connections management', () => {
const dataRows = page.locator('table tbody tr');
const initialItems = await dataRows.count();

await page
.getByRole('button', { name: /Options for/i })
.first()
.click({ force: true });
// Opened from the keyboard, which used to put the menu at the viewport's top-left corner.
const trigger = page.getByRole('button', { name: /Options for/i }).first();
await trigger.focus();
await page.keyboard.press('Enter');
await expectMenuBelow(trigger, page.getByRole('menu', { name: /Options for/i }));
await page.getByRole('menuitem', { name: 'Delete' }).click();

// Confirm deletion in the modal
Expand All @@ -204,12 +228,18 @@ test.describe('Storage — Connections management', () => {
await page.getByRole('dialog').getByRole('button', { name: 'Disconnect' }).click();
await expect(page.getByRole('heading', { name: 'Connect to storage' })).toBeVisible();
const savedList = page.getByRole('list', { name: 'Saved connections' });
await savedList.getByRole('button', { name: 'More options' }).first().click({ force: true });
await savedList
.getByRole('button', { name: /Options for/ })
.first()
.click({ force: true });
await page.getByRole('menuitem', { name: 'Edit', exact: true }).click();
await waitForHydration(page);
await expect(page.getByRole('heading', { name: 'Edit connection' })).toBeVisible();

await savedList.getByRole('button', { name: 'More options' }).first().click({ force: true });
const trigger = savedList.getByRole('button', { name: /Options for/ }).first();
await trigger.focus();
await page.keyboard.press('Enter');
await expectMenuBelow(trigger, page.getByRole('menu', { name: /Options for/ }));
await page.getByRole('menuitem', { name: 'Delete', exact: true }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Delete', exact: true }).click();

Expand Down Expand Up @@ -377,7 +407,10 @@ test.describe('Storage — Connection edit sidebar', () => {
await expect(page.getByRole('heading', { name: 'Connect to storage' })).toBeVisible();
const savedList = page.getByRole('list', { name: 'Saved connections' });
await expect(savedList.getByRole('listitem')).toHaveCount(2);
await savedList.getByRole('button', { name: 'More options' }).first().click({ force: true });
await savedList
.getByRole('button', { name: /Options for/ })
.first()
.click({ force: true });
await page.getByRole('menuitem', { name: 'Edit', exact: true }).click();
await waitForHydration(page);
await expect(page.getByRole('heading', { name: 'Edit connection' })).toBeVisible();
Expand All @@ -398,7 +431,7 @@ test.describe('Storage — Connection edit sidebar', () => {
async function deleteFromSidebar(page: Page, index: number) {
await page
.getByRole('list', { name: 'Saved connections' })
.getByRole('button', { name: 'More options' })
.getByRole('button', { name: /Options for/ })
.nth(index)
.click({ force: true });
await page.getByRole('menuitem', { name: 'Delete', exact: true }).click();
Expand Down
31 changes: 0 additions & 31 deletions e2e/storage/context-menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,37 +99,6 @@ test.describe('Storage S3 — Context Menu', () => {
}
});

test('unpins a pinned location from its sidebar menu', async ({ page }, testInfo) => {
const credentials = requireGarageCredentials();
const client = createS3Client(credentials);
const prefix = uniquePrefix(testInfo, 'ctx-unpin');
const cleanupKeys = [`${prefix}file.txt`];

try {
await putTextObject(client, credentials.bucket, cleanupKeys[0], 'x');
await connectAndOpenPrefix(page, credentials, prefix);

const breadcrumb = page.getByRole('navigation', { name: 'Breadcrumb' });
await breadcrumb.getByText(credentials.bucket).hover();
await page
.getByRole('button', { name: 'Pin this location' })
.filter({ visible: true })
.first()
.click();
const sidebar = page.getByRole('navigation', { name: 'Buckets' });
await expect(sidebar.getByText('Pinned Access')).toBeVisible();

await sidebar.getByRole('button', { name: 'More options' }).click({ force: true });
const menu = page.getByRole('menu', { name: 'Actions' });
await menu.getByRole('menuitem', { name: 'Unpin' }).click();

await expect(menu).toHaveCount(0);
await expect(sidebar.getByText('Pinned Access')).toHaveCount(0);
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
}
});

test('deletes a single file via context menu', async ({ page }, testInfo) => {
const credentials = requireGarageCredentials();
const client = createS3Client(credentials);
Expand Down
48 changes: 48 additions & 0 deletions e2e/storage/pinning.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { test, expect } from '../support/fixtures.js';
import {
createS3Client,
hasGarageCredentials,
requireGarageCredentials
} from '../support/garage.js';
import { connectAndOpenPrefix, deleteKnownKeys, putTextObject, uniquePrefix } from './helpers.js';

test.describe('Storage S3 — Pinned locations', () => {
test.use({ locale: 'en-US' });

test.beforeEach(() => {
test.skip(
!hasGarageCredentials(),
'Skipped: no s3-config.json found (requires a running Garage instance)'
);
});

test('unpins a pinned location with its sidebar button', async ({ page }, testInfo) => {
const credentials = requireGarageCredentials();
const client = createS3Client(credentials);
const prefix = uniquePrefix(testInfo, 'unpin');
const cleanupKeys = [`${prefix}file.txt`];

try {
await putTextObject(client, credentials.bucket, cleanupKeys[0], 'x');
await connectAndOpenPrefix(page, credentials, prefix);

const breadcrumb = page.getByRole('navigation', { name: 'Breadcrumb' });
await breadcrumb.getByText(credentials.bucket).hover();
await page
.getByRole('button', { name: 'Pin this location' })
.filter({ visible: true })
.first()
.click();
const sidebar = page.getByRole('navigation', { name: 'Buckets' });
await expect(sidebar.getByText('Pinned Access')).toBeVisible();

await sidebar.getByRole('button', { name: `Unpin ${credentials.bucket}` }).click({
force: true
});

await expect(sidebar.getByText('Pinned Access')).toHaveCount(0);
} finally {
await deleteKnownKeys(client, credentials.bucket, cleanupKeys);
}
});
});
2 changes: 1 addition & 1 deletion messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
"storage_action_pin": "Ort anheften",
"storage_action_details": "Details",
"storage_action_unpin": "Loslösen",
"storage_unpin_location": "{label} lösen",
"storage_action_copy_filename": "Dateiname kopieren",
"storage_action_copy_filename_success": "Dateiname in die Zwischenablage kopiert.",
"storage_action_copy_filename_error": "Dateiname konnte nicht in die Zwischenablage kopiert werden.",
Expand All @@ -333,7 +334,6 @@
"storage_action_copy_path_success": "Pfad in die Zwischenablage kopiert.",
"storage_action_copy_path_error": "Pfad konnte nicht in die Zwischenablage kopiert werden.",
"storage_pinned_label": "Angeheftete Orte",
"storage_more_options": "Weitere Optionen",
"storage_recent_files": "Zuletzt geöffnete Dateien",
"storage_recent_locations": "Zuletzt besuchte Orte",
"storage_recent_empty_files": "Keine zuletzt geöffneten Dateien.",
Expand Down
2 changes: 1 addition & 1 deletion messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
"storage_action_pin": "Pin this location",
"storage_action_details": "Details",
"storage_action_unpin": "Unpin",
"storage_unpin_location": "Unpin {label}",
"storage_action_copy_filename": "Copy filename",
"storage_action_copy_filename_success": "Filename copied to clipboard.",
"storage_action_copy_filename_error": "Could not copy filename to clipboard.",
Expand All @@ -333,7 +334,6 @@
"storage_action_copy_path_success": "Path copied to clipboard.",
"storage_action_copy_path_error": "Could not copy path to clipboard.",
"storage_pinned_label": "Pinned Access",
"storage_more_options": "More options",
"storage_recent_files": "Recent Files",
"storage_recent_locations": "Recent Locations",
"storage_recent_empty_files": "No recently accessed files.",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/DateTimePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
positionPopoverRelativeToTrigger,
supportsAnchorPositioning,
trackPopover
} from '$lib/components/popover-position.js';
} from '$lib/components/ui/popover-position.js';
import IconCalendar from 'virtual:icons/material-symbols/calendar-today';
import IconChevronLeft from 'virtual:icons/material-symbols/chevron-left';
import IconChevronRight from 'virtual:icons/material-symbols/chevron-right';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/storage/BucketSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import * as m from '$lib/paraglide/messages.js';
import { supportsAnchorPositioning, trackPopover } from '$lib/components/popover-position.js';
import { supportsAnchorPositioning, trackPopover } from '$lib/components/ui/popover-position.js';
import type { SearchSession, StorageSearchState } from '$lib/storage/search.svelte.js';
import IconArrowDropDown from 'virtual:icons/material-symbols/arrow-drop-down';
import IconArrowDropUp from 'virtual:icons/material-symbols/arrow-drop-up';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ vi.mock('$lib/paraglide/messages.js', () => ({
storage_connect_secret_key_required: () => 'Secret key is required',
storage_connect_manage: () => 'Manage connections',
storage_connect_edit: () => 'Edit',
storage_more_options: () => 'More options',
storage_connections_options: ({ label }: { label: string }) => `Options for ${label}`,
storage_sidebar_resize_handle: () => 'Resize sidebar',
storage_connections_delete_confirm: ({ label }: { label: string }) =>
`Delete connection to ${label}?`,
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('StorageConnectForm', () => {
makeConnection({ id: 'conn-1', name: 'Test S3', endpoint: 'https://s3.test.io' })
]);

await page.getByRole('button', { name: 'More options' }).click();
await page.getByRole('button', { name: 'Options for Test S3' }).click();
await expect.element(page.getByRole('menuitem', { name: 'Forget' })).toBeVisible();
});

Expand Down
52 changes: 20 additions & 32 deletions src/lib/components/storage/sidebar/BucketList.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<script lang="ts">
import { tick } from 'svelte';
import { resolve } from '$app/paths';
import { beforeNavigate } from '$app/navigation';
import IconMoreHoriz from 'virtual:icons/material-symbols/more-horiz';
import IconPushPinOutline from 'virtual:icons/material-symbols/push-pin-outline';
import IconInfo from 'virtual:icons/material-symbols/info';
import IconBucket from '../shared/BucketIcon.svelte';
Expand All @@ -13,7 +12,7 @@
import * as m from '$lib/paraglide/messages.js';
import { getStorageState } from '$lib/storage/context.js';
import ContextMenu from '$lib/components/ui/ContextMenu.svelte';
import type { PinnedLocation, StorageLocation } from '$lib/storage/types.js';
import type { PinnedLocation } from '$lib/storage/types.js';
import { parseStorageDrop, canStorageDrop } from '$lib/storage/drag-handlers.js';
import { locationLabel, locationHref } from '$lib/storage/display-helpers.js';
import { createResizablePanel } from './resizable-panel.svelte.js';
Expand Down Expand Up @@ -46,17 +45,17 @@
return activeBucket === pin.bucket && activePrefix === pin.prefix;
}

// ── Unpin context menu ────────────────────────────────────────────────────
let unpinCtx = $state<({ x: number; y: number } & StorageLocation) | null>(null);
function openUnpinMenuFromButton(e: MouseEvent, pin: PinnedLocation) {
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
unpinCtx = { x: rect.right, y: rect.bottom, bucket: pin.bucket, prefix: pin.prefix };
}
// ── Unpin ───────────────────────────────────────────────────────────────
let pinnedListEl = $state<HTMLUListElement>();
let allBucketsLink = $state<HTMLAnchorElement>();

function closeUnpinMenu() {
unpinCtx = null;
/** Unpins and moves focus to the next unpin button, as the clicked one disappears with its row. */
async function unpin(pin: PinnedLocation, index: number) {
storage.bookmarks.unpin(pin.bucket, pin.prefix);
await tick();
const buttons = pinnedListEl?.querySelectorAll<HTMLElement>('[data-unpin]') ?? [];
(buttons[Math.min(index, buttons.length - 1)] ?? allBucketsLink)?.focus();
}
beforeNavigate(closeUnpinMenu);

// ── Bucket details context menu ───────────────────────────────────────────
let bucketCtx = $state<{ x: number; y: number; bucket: string } | null>(null);
Expand All @@ -74,10 +73,6 @@
if (bucketCtx) storage.openModal('details', { type: 'bucket', bucket: bucketCtx.bucket });
}

function handleUnpin() {
if (unpinCtx) storage.bookmarks.unpin(unpinCtx.bucket, unpinCtx.prefix);
}

// ── Drag-drop targets for sidebar items ────────────────────────────────
let dropSidebarTarget = $state<string | null>(null);

Expand All @@ -103,16 +98,6 @@
}
</script>

<ContextMenu
x={unpinCtx?.x ?? 0}
y={unpinCtx?.y ?? 0}
open={unpinCtx !== null}
onclose={closeUnpinMenu}
onaction={handleUnpin}
actions={[{ key: 'unpin', icon: IconPushPinOutline, label: m.storage_action_unpin() }]}
title={m.storage_context_menu_actions()}
/>

<nav
class="
border-base-300 bg-base-100 relative flex shrink-0 flex-col
Expand All @@ -134,8 +119,8 @@
{m.storage_pinned_label()}
</span>
</div>
<ul class="py-1" role="list">
{#each storage.bookmarks.pinnedLocations as pin (pin.bucket + '::' + pin.prefix)}
<ul bind:this={pinnedListEl} class="py-1" role="list">
{#each storage.bookmarks.pinnedLocations as pin, index (pin.bucket + '::' + pin.prefix)}
{@const active = isPinnedActive(pin)}
<li class="group relative">
<TooltipTrigger text={locationLabel(pin)} orientation="right">
Expand All @@ -160,17 +145,19 @@
<span class="truncate">{locationLabel(pin)}</span>
</a>
</TooltipTrigger>
<TooltipTrigger text={m.storage_more_options()} orientation="right">
<TooltipTrigger text={m.storage_action_unpin()} orientation="right">
<button
type="button"
class="
btn btn-ghost btn-xs absolute top-1/2 right-1 z-150 -translate-y-1/2
p-0 opacity-0 transition-opacity
group-hover:opacity-100 focus:opacity-100
"
onclick={(e) => openUnpinMenuFromButton(e, pin)}
aria-label={m.storage_more_options()}
data-unpin
onclick={() => unpin(pin, index)}
aria-label={m.storage_unpin_location({ label: locationLabel(pin) })}
>
<IconMoreHoriz class="size-3.5" aria-hidden="true" />
<IconPushPinOutline class="size-3.5" aria-hidden="true" />
</button>
</TooltipTrigger>
</li>
Expand All @@ -192,6 +179,7 @@
{m.storage_buckets_label()}
</span>
<a
bind:this={allBucketsLink}
href={resolve('/storage')}
data-sveltekit-preload-data="off"
class="btn btn-ghost btn-xs group tooltip tooltip-right z-150 before:z-200"
Expand Down
Loading