Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## unreleased

- The new [`status_bar` component](https://sql-page.com/component.sql?component=status_bar) displays short status messages and links along the bottom of the screen or inline with page content.
- A file input with `multiple` now keeps every selected file, instead of only the last one. The new [`sqlpage.persist_uploaded_files`](https://sql-page.com/functions.sql?function=persist_uploaded_files) function saves them all and returns a JSON array with the `path`, original `name`, `mime_type` and `size` of each file.
- Set `wrap` on a `big_number` component to show long titles and descriptions across multiple lines.

Expand Down
23 changes: 23 additions & 0 deletions examples/official-site/sqlpage/migrations/80_status_bar.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
INSERT INTO component(name, icon, description, introduced_in_version) VALUES
('status_bar', 'layout-bottombar',
'Display short status messages and links in a single horizontal bar. Each row adds one segment. When there are several segments, the last one aligns to the far edge. If the segments do not all fit, scroll the bar horizontally to see the rest.',
'0.49.0');

INSERT INTO parameter(component, name, description, type, top_level, optional)
SELECT 'status_bar', * FROM (VALUES
('fixed', 'Keep the bar at the bottom of the screen while the page scrolls. Defaults to true. A fixed bar overlays page content, so leave space below your last item if needed. Set to false to place the bar in the page where the SQL appears.', 'BOOLEAN', TRUE, TRUE),
('label', 'Accessible name for the bar. Defaults to "Status bar".', 'TEXT', TRUE, TRUE),
('title', 'Text displayed in the segment.', 'TEXT', FALSE, TRUE),
('icon', 'Icon displayed before the text.', 'ICON', FALSE, TRUE),
('color', 'Color of the segment text and icon.', 'COLOR', FALSE, TRUE),
('tooltip', 'Text shown when hovering over the segment or focusing its link. For an icon without a title, supply a tooltip to give the segment an accessible name.', 'TEXT', FALSE, TRUE),
('link', 'URL to open when the segment is clicked.', 'URL', FALSE, TRUE)
) p;

INSERT INTO example(component, description, properties) VALUES
('status_bar', 'A query workspace shows the database connection, row count, and a link to the function reference. Omit `fixed` to pin this bar to the bottom of the screen.', json('[
{"component":"status_bar","label":"Query status","fixed":false},
{"title":"Connected","icon":"database","color":"green","tooltip":"Connected to the reporting database"},
{"title":"24 rows"},
{"title":"SQL functions","icon":"book","link":"/functions.sql"}
]'));
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ FROM (VALUES
('list', TRUE),
('list', FALSE),
('map', TRUE),
('status_bar', TRUE),
('tab', TRUE),
('tab', FALSE),
('table', TRUE),
Expand Down Expand Up @@ -69,6 +70,8 @@ FROM (VALUES
('list', TRUE),
('list', FALSE),
('map', TRUE),
('status_bar', TRUE),
('status_bar', FALSE),
('tab', TRUE),
('tab', FALSE),
('table', TRUE),
Expand Down
29 changes: 29 additions & 0 deletions sqlpage/templates/status_bar.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<style nonce="{{@csp_nonce}}">
/* Tabler's boxed page normally contains fixed elements. Let the bar use the viewport. */
:is(.layout-boxed, html[data-bs-layout="boxed"] body) > .page:has(.status-bar.fixed-bottom) {
contain: none;

/* Keep the boxed menu anchored to the page. */
> #sqlpage_header > .fixed-top {
position: absolute;
}
}
.status-bar > * + :last-child {
margin-inline-start: auto;
}
.status-bar > a:focus-visible {
outline-offset: -2px;
}
</style>
<div role="status" aria-label="{{default label 'Status bar'}}"
{{#if id}}id="{{id}}"{{/if}}
class="status-bar d-flex divide-x overflow-x-auto bg-surface fs-5 {{#if (default fixed true)}}fixed-bottom border-top{{else}}my-2 border rounded{{/if}} {{class}}">
{{#each_row}}
{{#if link}}<a href="{{link}}"{{else}}<span{{/if}}
class="d-flex flex-shrink-0 align-items-center gap-1 text-nowrap px-3 py-1 {{#if color}}text-{{color}}{{/if}} {{class}}"
{{#if tooltip}}data-bs-toggle="tooltip" title="{{tooltip}}"{{/if}}>
{{#if icon}}<span aria-hidden="true">{{~icon_img icon 16~}}</span>{{/if}}
{{#if title includeZero=true}}{{title}}{{else}}<span class="visually-hidden">{{tooltip}}</span>{{/if}}
{{#if link}}</a>{{else}}</span>{{/if}}
{{/each_row}}
</div>
2 changes: 2 additions & 0 deletions tests/end-to-end/fixtures/status-bar/fragment.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT 'status_bar' AS component, 'Sync status' AS label;
SELECT 'Synced' AS title;
20 changes: 20 additions & 0 deletions tests/end-to-end/fixtures/status-bar/index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
SELECT 'shell' AS component, 'Builds' AS title, 'boxed' AS layout, TRUE AS fixed_top_menu
WHERE $boxed IS NOT NULL;

SELECT 'status_bar' AS component, 'repository' AS id, 'project-status' AS class,
'Repository status' AS label, FALSE AS fixed;
SELECT 'Build passed' AS title, 'circle-check' AS icon, 'green' AS color,
'All checks passed' AS tooltip, '#activity' AS link, 'build-result' AS class;
SELECT 'Branch: feature/improve-search-index' AS title;
SELECT '12 pending changes' AS title;
SELECT 'View history' AS title, '#history' AS link;

SELECT 'list' AS component, 'Recent activity' AS title, 'activity' AS id,
'min-vh-100' AS class;
SELECT 'Search index updated' AS title;

SELECT 'title' AS component, 'Build history' AS contents, 'history' AS id;

SELECT 'status_bar' AS component;
SELECT 'Connected' AS title;
SELECT 'history' AS icon, 'Open build history' AS tooltip, '#history' AS link;
94 changes: 94 additions & 0 deletions tests/end-to-end/fixtures/status-bar/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { expect, loadFragment, test } from "../../fixture.ts";

test("rows render in order with icons, tooltips and links", async ({
page,
}) => {
const bar = page.getByRole("status", { name: "Repository status" });
await expect(bar).toHaveAttribute("id", "repository");
await expect(bar).toContainClass("project-status");
await expect(bar).toHaveText(
/Build passed\s*Branch: feature\/improve-search-index\s*12 pending changes\s*View history/,
);

const build = bar.getByRole("link", { name: "Build passed", exact: true });
const history = bar.getByRole("link", { name: "View history" });
await expect(bar.locator(".build-result")).toContainClass("text-green");
await expect(build.locator("svg")).toBeVisible();
const barRight = await bar.evaluate((el) => el.getBoundingClientRect().right);
const textRight = await history.evaluate((el) => {
const text = document.createRange();
text.selectNodeContents(el);
return text.getBoundingClientRect().right;
});
expect(barRight - textRight).toBeLessThan(32);
await build.hover();
await expect(page.getByRole("tooltip")).toHaveText("All checks passed");
await history.click();
await expect(page).toHaveURL(/#history$/);
await expect(
page.getByRole("heading", { name: "Build history" }),
).toBeInViewport();
});

test.describe("without JavaScript", () => {
test.use({ javaScriptEnabled: false });

test("the status bar stays at the viewport bottom and the fixed menu fits the boxed shell", async ({
page,
}) => {
await page.goto("/status-bar/?boxed=1");
const fixed = page.getByRole("status", { name: "Status bar", exact: true });
const inline = page.getByRole("status", { name: "Repository status" });
const bottomGap = () =>
fixed.evaluate((bar) => innerHeight - bar.getBoundingClientRect().bottom);

const header = await page.getByRole("banner").evaluate((el) => {
const { x, width } = el.getBoundingClientRect();
return { x, width };
});
expect(header.x).toBeGreaterThan(0);
expect(await page.getByRole("navigation").boundingBox()).toMatchObject(
header,
);
await expect(fixed.getByText("Connected", { exact: true })).toBeVisible();
await expect(
fixed.getByRole("link", { name: "Open build history" }),
).toBeVisible();
await expect(inline).toBeInViewport();
expect(await bottomGap()).toBeCloseTo(0);
await page
.getByRole("heading", { name: "Build history" })
.scrollIntoViewIfNeeded();
await expect(inline).not.toBeInViewport();
expect(await bottomGap()).toBeCloseTo(0);
});
});

test("a narrow bar scrolls to the next focused link without widening the page", async ({
page,
}) => {
await page.setViewportSize({ width: 320, height: 640 });
const bar = page.getByRole("status", { name: "Repository status" });
const history = bar.getByRole("link", { name: "View history" });
await expect(history).not.toBeInViewport();
await bar.getByRole("link", { name: "Build passed" }).focus();
await page.keyboard.press("Tab");
await expect(history).toBeFocused();
await expect(history).toBeInViewport({ ratio: 0.99 });
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBe(
320,
);
});

test("a fixed bar disappears with its embedded fragment", async ({ page }) => {
await loadFragment(
page,
"/status-bar/fragment.sql",
"#activity",
"#activity",
);
const bar = page.getByRole("status", { name: "Sync status" });
await expect(bar).toHaveText("Synced");
await page.locator("#activity").evaluate((el) => el.remove());
await expect(bar).toHaveCount(0);
});
Loading