Search and paging on lists, Settings in tabs, pinned sidebar (1.3.0)
- Installs, Customers, Alerts and the audit log get a search box and 25-per-page paging (Installs also a health filter); install History pages too. - Settings is split into Releases and alerts / Email / Login and security / Audit log tabs, remembered in the URL hash. - The side navigation is sticky at window height, so Sign out no longer scrolls off long pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
|
||||
/** True when every word of the query appears in one of the fields (case-insensitive). */
|
||||
export function matches(query: string, ...fields: (string | number | null | undefined)[]) {
|
||||
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
||||
if (!words.length) return true;
|
||||
const hay = fields.filter(f => f != null).join(" ").toLowerCase();
|
||||
return words.every(w => hay.includes(w));
|
||||
}
|
||||
|
||||
/**
|
||||
* One page of a list. Goes back to the first page when `resetKey` changes (the search or filter),
|
||||
* but not when the same list is reloaded.
|
||||
*/
|
||||
export function usePaged<T>(items: T[], resetKey: unknown, pageSize = 25) {
|
||||
const [page, setPage] = useState(1);
|
||||
const pages = Math.max(1, Math.ceil(items.length / pageSize));
|
||||
useEffect(() => { setPage(1); }, [resetKey]);
|
||||
const current = Math.min(page, pages);
|
||||
const rows = useMemo(() => items.slice((current - 1) * pageSize, current * pageSize), [items, current, pageSize]);
|
||||
return { rows, page: current, pages, setPage, total: items.length, pageSize };
|
||||
}
|
||||
Reference in New Issue
Block a user