Skip to content
Open
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
12 changes: 12 additions & 0 deletions e2e/blocked-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,23 @@ test.describe('Blocked site data', () => {
await expect(html).not.toHaveAttribute('data-theme', initialTheme ?? '');
});

test('theme is set before hydration', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'dark' });
// Without the app's JavaScript only the inline script in app.html can set the theme. The
// aborted scripts fail SvelteKit's start-up import, so page errors are expected here.
page.removeAllListeners('pageerror');
await page.route('**/_app/immutable/**/*.js', (route) => route.abort());
await page.goto('/');
await expect(page.locator('html')).toHaveAttribute('data-theme', 'dark');
});

test('Trino page hydrates and warns that tabs are not saved', async ({ page }) => {
test.slow();
await page.goto('/trino');
await waitForHydration(page);

// The catalog browser falls back to its default (open on desktop).
await expect(page.getByRole('navigation', { name: 'Catalog browser' })).toBeVisible();
await expect(page.getByRole('tab')).toHaveCount(1);
await page.getByRole('button', { name: 'New Tab' }).click();
await expect(page.getByRole('tab')).toHaveCount(2);
Expand Down
31 changes: 31 additions & 0 deletions e2e/storage/sidebar-resize.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { test, expect } from '../support/fixtures.js';
import { hasGarageCredentials, requireGarageCredentials } from '../support/garage.js';
import { connectToStorage } from './helpers.js';

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

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

test('bucket list width is restored before hydration', async ({ page }) => {
await connectToStorage(page, requireGarageCredentials());
const buckets = page.getByRole('navigation', { name: 'Buckets' });
const width = async () => (await buckets.boundingBox())?.width;
await expect.poll(width).toBe(192);

await buckets.getByRole('separator', { name: 'Resize sidebar' }).focus();
await page.keyboard.press('Shift+ArrowRight'); // +20px
await page.keyboard.press('Shift+ArrowRight');
await expect.poll(width).toBe(232);

// Without the app's JavaScript only the inline script in app.html can restore the width.
await page.route('**/_app/immutable/**/*.js', (route) => route.abort());
await page.reload();
expect(await width()).toBe(232);
});
});
22 changes: 17 additions & 5 deletions e2e/trino/catalog-browser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,29 @@ test.describe('Catalog browser', () => {

await expect(handle).toHaveAttribute('aria-valuenow', String(before + 20));

const stored = await page.evaluate(() => localStorage.getItem('trino_catalog_browser_width'));
const stored = await page.evaluate(() =>
localStorage.getItem('panel_width:trino-catalog-browser')
);
expect(Number(stored)).toBe(before + 20);

// Width persists across reload.
await page.reload();
await waitForHydration(page);
await ensureCatalogBrowserOpen(page);
await expect(page.getByRole('separator', { name: 'Resize catalog browser' })).toHaveAttribute(
'aria-valuenow',
String(before + 20)
);
const restored = page.getByRole('separator', { name: 'Resize catalog browser' });
await expect(restored).toHaveAttribute('aria-valuenow', String(before + 20));
// The handle sits next to the aside; wait for the open transition to finish.
const aside = restored.locator('..').locator('aside');
await expect.poll(async () => (await aside.boundingBox())?.width).toBe(before + 20);
});

test('catalog browser is rendered open before hydration', async ({ page }) => {
// Without the app's JavaScript the page shows what the server rendered.
await page.route('**/_app/immutable/**/*.js', (route) => route.abort());
await page.reload();
const handle = page.getByRole('separator', { name: 'Resize catalog browser' });
const aside = handle.locator('..').locator('aside');
expect((await aside.boundingBox())?.width).toBe(288);
});

test('browser is hidden by default on mobile', async ({ page }) => {
Expand Down
19 changes: 11 additions & 8 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
(function () {
// localStorage throws when site data is blocked; fall back to the defaults then.
var savedTheme = null;
var savedWidth = null;
try {
savedTheme = localStorage.getItem('theme');
savedWidth = localStorage.getItem('storage_sidebar_width');
} catch (e) {}

var theme =
savedTheme ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.setAttribute('data-theme', theme);

if (savedWidth) {
var w = parseInt(savedWidth, 10);
if (!isNaN(w) && w >= 120 && w <= 480) {
document.documentElement.style.setProperty('--storage-sidebar-width', w + 'px');
// Restore resizable panel widths before first paint (see resizable-panel.svelte.ts).
// Each panel clamps its variable to its own limits in CSS.
try {
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i);
var match = key && /^panel_width:([A-Za-z0-9-]+)$/.exec(key);
var w = match && parseInt(localStorage.getItem(key), 10);
if (w > 0) {
document.documentElement.style.setProperty('--panel-width-' + match[1], w + 'px');
}
}
}
} catch (e) {}
})();
</script>
%sveltekit.head%
Expand Down
10 changes: 5 additions & 5 deletions src/lib/components/storage/sidebar/BucketList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import type { PinnedLocation, StorageLocation } 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';
import ResizeHandle from './ResizeHandle.svelte';
import { createResizablePanel } from '$lib/components/ui/resizable-panel.svelte.js';
import ResizeHandle from '$lib/components/ui/ResizeHandle.svelte';

const storage = getStorageState();

const resize = createResizablePanel({
storageKey: 'storage_sidebar_width',
id: 'storage-buckets',
defaultWidth: 192,
minWidth: 120,
maxWidth: 480
Expand Down Expand Up @@ -118,7 +118,7 @@
border-base-300 bg-base-100 relative flex shrink-0 flex-col
rounded-lg border
"
style="width: var(--storage-sidebar-width, {resize.width}px)"
style="width: {resize.cssWidth}"
aria-label={m.storage_buckets_label()}
>
{#if !storage.connected || !storage.connectionHostname}
Expand Down Expand Up @@ -290,5 +290,5 @@
</Modal>
{/if}

<ResizeHandle panel={resize} />
<ResizeHandle panel={resize} label={m.storage_sidebar_resize_handle()} />
</nav>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import IconClose from 'virtual:icons/material-symbols/close';
import TooltipTrigger from '$lib/components/ui/TooltipTrigger.svelte';
import ContextMenu, { type ContextMenuAction } from '$lib/components/ui/ContextMenu.svelte';
import { createResizablePanel } from './resizable-panel.svelte.js';
import ResizeHandle from './ResizeHandle.svelte';
import { createResizablePanel } from '$lib/components/ui/resizable-panel.svelte.js';
import ResizeHandle from '$lib/components/ui/ResizeHandle.svelte';
import { enhance } from '$app/forms';
import { resolve } from '$app/paths';
import type { SubmitFunction } from '@sveltejs/kit';
Expand Down Expand Up @@ -40,7 +40,7 @@
let { connections, activeId, onselect, onbeforedelete, ondeletesettled }: Props = $props();

const resize = createResizablePanel({
storageKey: 'storage_connect_sidebar_width',
id: 'storage-connections',
defaultWidth: 224,
minWidth: 140,
maxWidth: 400
Expand Down Expand Up @@ -245,7 +245,7 @@
border-base-300 bg-base-100 sticky top-0
hidden h-[calc(100dvh-7rem)] shrink-0 flex-col rounded-lg border md:flex
"
style="width: {resize.width}px; min-width: {resize.minWidth}px"
style="width: {resize.cssWidth}"
aria-label={m.storage_connect_saved()}
>
<div class="border-base-300 border-b px-3 py-2">
Expand Down Expand Up @@ -344,5 +344,5 @@
</a>
</div>

<ResizeHandle panel={resize} />
<ResizeHandle panel={resize} label={m.storage_sidebar_resize_handle()} />
</aside>
98 changes: 0 additions & 98 deletions src/lib/components/storage/sidebar/resizable-panel.svelte.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<script lang="ts">
import * as m from '$lib/paraglide/messages.js';
import type { ResizablePanel } from './resizable-panel.svelte.js';

interface Props {
panel: ResizablePanel;
/** Accessible label for the handle. Defaults to the storage-sidebar label. */
label?: string;
/** Accessible label for the handle. */
label: string;
}

let { panel, label }: Props = $props();
Expand All @@ -16,7 +15,7 @@
<div
role="separator"
aria-orientation="vertical"
aria-label={label ?? m.storage_sidebar_resize_handle()}
aria-label={label}
aria-valuenow={panel.width}
aria-valuemin={panel.minWidth}
aria-valuemax={panel.maxWidth}
Expand Down
Loading