Add saved filter views, a customisable dashboard, server comparison, row keyboard navigation and share links
- Table search, status, tag and sort live in the address; Save view pins one as a favourite. - Dashboard cards can be moved and hidden per user (users.dashboard_layout, migration 0022). - Compare two to four servers' load, memory or disk on one chart. - j/k move through table rows that open a detail panel. - Share links open a read-only wall without signing in, numbers only or with names (share_links, migration 0023); the wall is split into a shared view over two data sources. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
906220040e
commit
44e393f172
50 files changed
+6114
-258
No files matched your search
@@ -13,7 +13,7 @@ function isTyping(target: EventTarget | null): boolean {
|
||||
|
||||
/**
|
||||
* Page shortcuts for anyone signed in: "g" then a letter goes to a page they are allowed to see, "/" jumps to the table's
|
||||
* search box, "?" shows the list. Ignored while typing, while a dialog is open, and with Ctrl/Alt/Cmd held (those are the
|
||||
* search box, "j" and "k" move down and up the table's rows (Enter then opens the one you are on), "?" shows the list. Ignored while typing, while a dialog is open, and with Ctrl/Alt/Cmd held (those are the
|
||||
* browser's and the command palette's).
|
||||
*/
|
||||
export function useShortcuts(user: CurrentUser): void {
|
||||
@@ -47,7 +47,16 @@ export function useShortcuts(user: CurrentUser): void {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (e.key === "g") {
|
||||
if (e.key === "j" || e.key === "k") {
|
||||
const rows = [...document.querySelectorAll<HTMLElement>("tr.row-clickable")].filter((r) => r.offsetParent !== null);
|
||||
if (rows.length === 0) return;
|
||||
const current = (document.activeElement as HTMLElement | null)?.closest<HTMLElement>("tr.row-clickable") ?? null;
|
||||
const at = current ? rows.indexOf(current) : -1;
|
||||
const next = e.key === "j" ? rows[Math.min(at + 1, rows.length - 1)] : rows[Math.max(at - 1, 0)];
|
||||
e.preventDefault();
|
||||
next.focus();
|
||||
next.scrollIntoView({ block: "nearest" });
|
||||
} else if (e.key === "g") {
|
||||
waitingForSecondKey = true;
|
||||
timer = setTimeout(reset, 1200);
|
||||
} else if (e.key === "[") {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
export type SortDirection = "asc" | "desc";
|
||||
|
||||
@@ -28,18 +29,42 @@ export function sortItems<T>(items: T[], sortKey: keyof T | undefined, sortDir:
|
||||
* render it — so a formatted "1.2 GB" column still sorts by its raw byte
|
||||
* count, and a "5d 15h 2m" column sorts by its raw timestamp/seconds field.
|
||||
* Nulls/undefined always sort to the end regardless of direction.
|
||||
*
|
||||
* With `{ url: true }` the chosen column and direction live in the address (`?sort=name&dir=desc`) instead of in memory, so the
|
||||
* order survives a reload and goes into a saved view. Meant for the page's main table; the default order leaves the address clean.
|
||||
*/
|
||||
export function useSortable<T>(items: T[] | null | undefined, initialKey?: keyof T, initialDir: SortDirection = "asc") {
|
||||
const [sortKey, setSortKey] = useState<keyof T | undefined>(initialKey);
|
||||
const [sortDir, setSortDir] = useState<SortDirection>(initialDir);
|
||||
export function useSortable<T>(items: T[] | null | undefined, initialKey?: keyof T, initialDir: SortDirection = "asc", options?: { url?: boolean }) {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const [localKey, setLocalKey] = useState<keyof T | undefined>(initialKey);
|
||||
const [localDir, setLocalDir] = useState<SortDirection>(initialDir);
|
||||
|
||||
const useUrl = options?.url === true;
|
||||
const urlKey = params.get("sort");
|
||||
const fromUrl = useUrl && urlKey !== null && /^[A-Za-z0-9_.]{1,40}$/.test(urlKey);
|
||||
const sortKey: keyof T | undefined = fromUrl ? (urlKey as keyof T) : useUrl ? initialKey : localKey;
|
||||
const sortDir: SortDirection = fromUrl ? (params.get("dir") === "desc" ? "desc" : "asc") : useUrl ? initialDir : localDir;
|
||||
|
||||
function requestSort(key: keyof T) {
|
||||
if (sortKey === key) {
|
||||
setSortDir((d) => (d === "asc" ? "desc" : "asc"));
|
||||
} else {
|
||||
setSortKey(key);
|
||||
setSortDir("asc");
|
||||
const nextDir: SortDirection = sortKey === key ? (sortDir === "asc" ? "desc" : "asc") : "asc";
|
||||
if (!useUrl) {
|
||||
setLocalKey(key);
|
||||
setLocalDir(nextDir);
|
||||
return;
|
||||
}
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
if (key === initialKey && nextDir === initialDir) {
|
||||
next.delete("sort");
|
||||
next.delete("dir");
|
||||
} else {
|
||||
next.set("sort", String(key));
|
||||
next.set("dir", nextDir);
|
||||
}
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
}
|
||||
|
||||
const sorted = useMemo(() => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
const haystacks = new WeakMap<object, string>();
|
||||
|
||||
@@ -24,9 +25,26 @@ function haystackOf(row: unknown): string {
|
||||
/**
|
||||
* Text search over a table's rows. Several words must all appear (in any column, in any order), so "elsa running" finds a running
|
||||
* container on elsa. Returns the rows unchanged while the box is empty, and `null`/`undefined` as they came while loading.
|
||||
*
|
||||
* The words live in the address (`?q=elsa running`), so a search survives a reload, can be bookmarked or sent on, and can be pinned as
|
||||
* a saved view. A page has one searchable table, so one `q`; other things in the address are left alone.
|
||||
*/
|
||||
export function useTableSearch<T>(items: T[] | null | undefined) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [params, setParams] = useSearchParams();
|
||||
const query = params.get("q") ?? "";
|
||||
const setQuery = useCallback(
|
||||
(value: string) =>
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
if (value) next.set("q", value);
|
||||
else next.delete("q");
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
),
|
||||
[setParams],
|
||||
);
|
||||
const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
||||
const key = terms.join(" ");
|
||||
|
||||
|
||||
Reference in new issue
Block a user