Compare commits
12 Commits
fe448034ac
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 97c63ac25b | |||
| 62c569741f | |||
| 3ad0e56ecd | |||
| ada5d06dad | |||
| 3a57c0a77c | |||
| 9a896bb5f6 | |||
| 78f5afad35 | |||
| 27205c65ef | |||
| 091a1a651d | |||
| ec11c9dc76 | |||
| 1d19ddfd96 | |||
| 79a6567530 |
@@ -3,6 +3,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="color-scheme" content="light dark" />
|
||||||
|
<meta name="theme-color" content="#ffffff" />
|
||||||
<title>Collection</title>
|
<title>Collection</title>
|
||||||
<script>
|
<script>
|
||||||
try {
|
try {
|
||||||
@@ -12,6 +14,9 @@
|
|||||||
(t === "system" &&
|
(t === "system" &&
|
||||||
window.matchMedia("(prefers-color-scheme: dark)").matches);
|
window.matchMedia("(prefers-color-scheme: dark)").matches);
|
||||||
document.documentElement.classList.toggle("dark", dark);
|
document.documentElement.classList.toggle("dark", dark);
|
||||||
|
// Keep in sync with THEME_COLORS in src/theme/theme.ts.
|
||||||
|
var meta = document.querySelector('meta[name="theme-color"]');
|
||||||
|
if (meta) meta.setAttribute("content", dark ? "#0a0a0a" : "#ffffff");
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { join, relative } from "node:path";
|
|||||||
const root = "src";
|
const root = "src";
|
||||||
const excludeDir = join("src", "components", "ui");
|
const excludeDir = join("src", "components", "ui");
|
||||||
const RAW_COLOR =
|
const RAW_COLOR =
|
||||||
/(?:text|bg|border|ring|fill|stroke|from|to|via|decoration|outline|divide|placeholder)-(?:neutral|gray|slate|zinc|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950)\b/;
|
/(?:text|bg|border|ring|fill|stroke|from|to|via|decoration|outline|divide|placeholder)-(?:(?:neutral|gray|slate|zinc|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(?:50|100|200|300|400|500|600|700|800|900|950)|white|black)\b/;
|
||||||
|
|
||||||
function walk(dir) {
|
function walk(dir) {
|
||||||
const files = [];
|
const files = [];
|
||||||
|
|||||||
+1
-1
@@ -72,7 +72,7 @@ const router = createBrowserRouter(
|
|||||||
<Route path="/authorities" element={<Navigate to="/authorities/person" replace />} />
|
<Route path="/authorities" element={<Navigate to="/authorities/person" replace />} />
|
||||||
<Route path="/authorities/:kind" element={<AuthoritiesPage />} />
|
<Route path="/authorities/:kind" element={<AuthoritiesPage />} />
|
||||||
<Route
|
<Route
|
||||||
path="/fields"
|
path="/fields/:key?"
|
||||||
element={
|
element={
|
||||||
<Suspense fallback={<ListSkeleton />}>
|
<Suspense fallback={<ListSkeleton />}>
|
||||||
<FieldsPage />
|
<FieldsPage />
|
||||||
|
|||||||
@@ -57,6 +57,31 @@ test("rejects an off-site from and falls back to /objects", async () => {
|
|||||||
expect(await screen.findByText("objects landing")).toBeInTheDocument();
|
expect(await screen.findByText("objects landing")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("shows Signing in… and disables the button while pending", async () => {
|
||||||
|
let release!: () => void;
|
||||||
|
const gate = new Promise<void>((r) => {
|
||||||
|
release = r;
|
||||||
|
});
|
||||||
|
|
||||||
|
server.use(
|
||||||
|
http.post("/api/admin/login", async () => {
|
||||||
|
await gate;
|
||||||
|
return new HttpResponse(null, { status: 204 });
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
renderApp(tree(), { route: "/login" });
|
||||||
|
await userEvent.type(screen.getByLabelText(/email/i), "editor@example.com");
|
||||||
|
await userEvent.type(screen.getByLabelText(/password/i), "pw-editor-123");
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: /sign in/i }));
|
||||||
|
|
||||||
|
const pending = await screen.findByRole("button", { name: /signing in/i });
|
||||||
|
expect(pending).toBeDisabled();
|
||||||
|
|
||||||
|
release();
|
||||||
|
expect(await screen.findByText("objects landing")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
test("disables submit until both fields are filled", async () => {
|
test("disables submit until both fields are filled", async () => {
|
||||||
renderApp(tree(), { route: "/login" });
|
renderApp(tree(), { route: "/login" });
|
||||||
const button = screen.getByRole("button", { name: /sign in/i });
|
const button = screen.getByRole("button", { name: /sign in/i });
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export function LoginPage() {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<Button type="submit" className="w-full" disabled={login.isPending || !email.trim() || !password}>
|
<Button type="submit" className="w-full" disabled={login.isPending || !email.trim() || !password}>
|
||||||
{t("auth.signIn")}
|
{login.isPending ? t("auth.signingIn") : t("auth.signIn")}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -20,6 +20,31 @@ test("delete-in-use shows the in-use count and keeps the dialog open", async ()
|
|||||||
expect(dialog.getByText("Delete this term?")).toBeInTheDocument();
|
expect(dialog.getByText("Delete this term?")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("confirm is disabled and labelled Deleting… while pending", async () => {
|
||||||
|
let resolve!: () => void;
|
||||||
|
const onConfirm = vi.fn(
|
||||||
|
() =>
|
||||||
|
new Promise<void>((r) => {
|
||||||
|
resolve = r;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
renderApp(<DeleteConfirmDialog description="Delete this term?" onConfirm={onConfirm} />);
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: /delete/i }));
|
||||||
|
|
||||||
|
const dialog = within(document.body);
|
||||||
|
const buttons = await dialog.findAllByRole("button", { name: /delete/i });
|
||||||
|
await userEvent.click(buttons[buttons.length - 1]);
|
||||||
|
|
||||||
|
const pending = await dialog.findByRole("button", { name: /deleting/i });
|
||||||
|
expect(pending).toBeDisabled();
|
||||||
|
expect(dialog.getByRole("button", { name: /cancel/i })).toBeDisabled();
|
||||||
|
expect(onConfirm).toHaveBeenCalledTimes(1);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
await waitFor(() => expect(dialog.queryByText("Delete this term?")).toBeNull());
|
||||||
|
});
|
||||||
|
|
||||||
test("a clean confirm closes the dialog", async () => {
|
test("a clean confirm closes the dialog", async () => {
|
||||||
const onConfirm = vi.fn(() => Promise.resolve());
|
const onConfirm = vi.fn(() => Promise.resolve());
|
||||||
renderApp(<DeleteConfirmDialog description="Delete this term?" onConfirm={onConfirm} />);
|
renderApp(<DeleteConfirmDialog description="Delete this term?" onConfirm={onConfirm} />);
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ export function DeleteConfirmDialog({
|
|||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
const [pending, setPending] = useState(false);
|
||||||
const [message, setMessage] = useState<string | null>(null);
|
const [message, setMessage] = useState<string | null>(null);
|
||||||
|
|
||||||
const confirm = async () => {
|
const confirm = async () => {
|
||||||
setMessage(null);
|
setMessage(null);
|
||||||
|
setPending(true);
|
||||||
try {
|
try {
|
||||||
await onConfirm();
|
await onConfirm();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -40,6 +42,8 @@ export function DeleteConfirmDialog({
|
|||||||
const { key, opts } = errorMessageKey(err);
|
const { key, opts } = errorMessageKey(err);
|
||||||
setMessage(t(key, opts));
|
setMessage(t(key, opts));
|
||||||
return;
|
return;
|
||||||
|
} finally {
|
||||||
|
setPending(false);
|
||||||
}
|
}
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
@@ -62,8 +66,10 @@ export function DeleteConfirmDialog({
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
<AlertDialogCancel>{t("form.cancel")}</AlertDialogCancel>
|
<AlertDialogCancel disabled={pending}>{t("form.cancel")}</AlertDialogCancel>
|
||||||
<AlertDialogAction onClick={confirm}>{t("actions.delete")}</AlertDialogAction>
|
<AlertDialogAction disabled={pending} onClick={confirm}>
|
||||||
|
{pending ? t("actions.deleting") : t("actions.delete")}
|
||||||
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
</AlertDialog>
|
</AlertDialog>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
|
import { focusRing } from "../lib/focus-ring";
|
||||||
|
|
||||||
export function ExternalUriLink({ uri }: { uri: string }) {
|
export function ExternalUriLink({ uri }: { uri: string }) {
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
href={uri}
|
href={uri}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="block truncate text-xs text-muted-foreground hover:text-foreground"
|
className={`block truncate rounded-sm text-xs text-muted-foreground hover:text-foreground ${focusRing}`}
|
||||||
>
|
>
|
||||||
{uri}
|
{uri}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ function AlertDialogContent({
|
|||||||
data-slot="alert-dialog-content"
|
data-slot="alert-dialog-content"
|
||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
"group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 overscroll-y-contain rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ function ComboboxInput({ className, ...props }: ComboboxPrimitive.Input.Props) {
|
|||||||
return (
|
return (
|
||||||
<ComboboxPrimitive.Input
|
<ComboboxPrimitive.Input
|
||||||
data-slot="combobox-input"
|
data-slot="combobox-input"
|
||||||
className={cn("w-full rounded border px-2 py-1 pr-12 text-sm", className)}
|
className={cn(
|
||||||
|
"w-full rounded border px-2 py-1 pr-12 text-sm transition-colors outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -31,7 +34,7 @@ function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {
|
|||||||
<ComboboxPrimitive.Clear
|
<ComboboxPrimitive.Clear
|
||||||
data-slot="combobox-clear"
|
data-slot="combobox-clear"
|
||||||
className={cn(
|
className={cn(
|
||||||
"absolute right-6 text-neutral-400 hover:text-neutral-700",
|
"absolute right-6 rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -43,7 +46,10 @@ function ComboboxTrigger({ className, ...props }: ComboboxPrimitive.Trigger.Prop
|
|||||||
return (
|
return (
|
||||||
<ComboboxPrimitive.Trigger
|
<ComboboxPrimitive.Trigger
|
||||||
data-slot="combobox-trigger"
|
data-slot="combobox-trigger"
|
||||||
className={cn("absolute right-1 text-neutral-500", className)}
|
className={cn(
|
||||||
|
"absolute right-1 rounded-sm text-muted-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50",
|
||||||
|
className,
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -56,7 +62,7 @@ function ComboboxPopup({ className, ...props }: ComboboxPrimitive.Popup.Props) {
|
|||||||
<ComboboxPrimitive.Popup
|
<ComboboxPrimitive.Popup
|
||||||
data-slot="combobox-popup"
|
data-slot="combobox-popup"
|
||||||
className={cn(
|
className={cn(
|
||||||
"max-h-64 min-w-48 overflow-auto rounded border bg-white p-1 text-sm shadow-md",
|
"max-h-64 min-w-48 overflow-auto overscroll-y-contain rounded border bg-popover p-1 text-sm text-popover-foreground shadow-md",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -81,7 +87,7 @@ function ComboboxItem({ className, ...props }: ComboboxPrimitive.Item.Props) {
|
|||||||
<ComboboxPrimitive.Item
|
<ComboboxPrimitive.Item
|
||||||
data-slot="combobox-item"
|
data-slot="combobox-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex cursor-default items-center gap-2 rounded px-2 py-1 data-[highlighted]:bg-indigo-50",
|
"flex cursor-default items-center gap-2 rounded px-2 py-1 data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -103,7 +109,7 @@ function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {
|
|||||||
return (
|
return (
|
||||||
<ComboboxPrimitive.Empty
|
<ComboboxPrimitive.Empty
|
||||||
data-slot="combobox-empty"
|
data-slot="combobox-empty"
|
||||||
className={cn("px-2 py-1 text-neutral-500", className)}
|
className={cn("px-2 py-1 text-muted-foreground", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ function DrawerContent({ className, children, ...props }: DrawerPrimitive.Popup.
|
|||||||
<DrawerPrimitive.Popup
|
<DrawerPrimitive.Popup
|
||||||
data-slot="drawer-content"
|
data-slot="drawer-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"fixed inset-y-0 right-0 flex w-full max-w-md flex-col overflow-y-auto bg-background shadow-xl outline-none duration-200 data-open:animate-in data-open:slide-in-from-right data-closed:animate-out data-closed:slide-out-to-right",
|
"fixed inset-y-0 right-0 flex w-full max-w-md flex-col overflow-y-auto overscroll-y-contain bg-background shadow-xl outline-none duration-200 data-open:animate-in data-open:slide-in-from-right data-closed:animate-out data-closed:slide-out-to-right",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export function PageTitle({ className, ...props }: ComponentProps<"h1">) {
|
|||||||
return (
|
return (
|
||||||
<h1
|
<h1
|
||||||
data-slot="page-title"
|
data-slot="page-title"
|
||||||
className={cn("text-2xl font-semibold tracking-tight", className)}
|
className={cn("text-2xl font-semibold tracking-tight text-balance", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ function SelectContent({
|
|||||||
<SelectPrimitive.Popup
|
<SelectPrimitive.Popup
|
||||||
data-slot="select-content"
|
data-slot="select-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
"max-h-[min(24rem,var(--available-height))] min-w-[var(--anchor-width)] overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md outline-none",
|
"max-h-[min(24rem,var(--available-height))] min-w-[var(--anchor-width)] overflow-y-auto overscroll-y-contain rounded-md border bg-popover p-1 text-popover-foreground shadow-md outline-none",
|
||||||
"data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
"data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type * as React from "react";
|
import type * as React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Toast as ToastPrimitive } from "@base-ui/react/toast";
|
import { Toast as ToastPrimitive } from "@base-ui/react/toast";
|
||||||
|
import { X } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { toastManager } from "@/toast/toast-manager";
|
import { toastManager } from "@/toast/toast-manager";
|
||||||
@@ -14,9 +15,9 @@ function ToastList() {
|
|||||||
toast={toast}
|
toast={toast}
|
||||||
data-slot="toast"
|
data-slot="toast"
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-start gap-2 rounded-md border bg-white p-3 text-sm shadow-md",
|
"flex items-start gap-2 rounded-md border bg-popover p-3 text-sm text-popover-foreground shadow-md",
|
||||||
toast.type === "error" && "border-red-300",
|
toast.type === "error" && "border-destructive",
|
||||||
toast.type === "success" && "border-green-300",
|
toast.type === "success" && "border-success",
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
@@ -28,15 +29,15 @@ function ToastList() {
|
|||||||
)}
|
)}
|
||||||
<ToastPrimitive.Description
|
<ToastPrimitive.Description
|
||||||
data-slot="toast-description"
|
data-slot="toast-description"
|
||||||
className="text-neutral-700"
|
className="text-muted-foreground"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<ToastPrimitive.Close
|
<ToastPrimitive.Close
|
||||||
data-slot="toast-close"
|
data-slot="toast-close"
|
||||||
aria-label={t("common.close")}
|
aria-label={t("common.close")}
|
||||||
className="text-neutral-400 hover:text-neutral-700"
|
className="text-muted-foreground hover:text-foreground"
|
||||||
>
|
>
|
||||||
×
|
<X className="size-4" aria-hidden="true" />
|
||||||
</ToastPrimitive.Close>
|
</ToastPrimitive.Close>
|
||||||
</ToastPrimitive.Root>
|
</ToastPrimitive.Root>
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function TooltipPopup({ className, ...props }: TooltipPrimitive.Popup.Props) {
|
|||||||
<TooltipPrimitive.Popup
|
<TooltipPrimitive.Popup
|
||||||
data-slot="tooltip-popup"
|
data-slot="tooltip-popup"
|
||||||
className={cn(
|
className={cn(
|
||||||
"rounded border bg-white px-2 py-1 text-sm shadow-md",
|
"rounded border bg-popover px-2 py-1 text-sm text-popover-foreground shadow-md",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ export function FieldForm({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{isEdit && <p className="text-xs text-muted-foreground">{t("fields.lockedNote")}</p>}
|
||||||
|
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<Label htmlFor="field-key">{t("fields.key")}</Label>
|
<Label htmlFor="field-key">{t("fields.key")}</Label>
|
||||||
<Input
|
<Input
|
||||||
|
|||||||
@@ -90,18 +90,23 @@ export function FieldList({
|
|||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={cn("flex flex-1 items-center gap-2 rounded-sm text-left", focusRing)}
|
className={cn(
|
||||||
|
"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left",
|
||||||
|
focusRing,
|
||||||
|
)}
|
||||||
aria-pressed={def.key === selectedKey}
|
aria-pressed={def.key === selectedKey}
|
||||||
onClick={() => onSelect(def)}
|
onClick={() => onSelect(def)}
|
||||||
>
|
>
|
||||||
<span className="font-medium">{labelText(def.labels, lang)}</span>
|
<span className="min-w-0 truncate font-medium">
|
||||||
|
{labelText(def.labels, lang)}
|
||||||
|
</span>
|
||||||
<span className="text-xs text-muted-foreground">{def.key}</span>
|
<span className="text-xs text-muted-foreground">{def.key}</span>
|
||||||
<Badge variant="secondary">
|
<Badge variant="secondary" className="shrink-0">
|
||||||
{t(`fields.types.${def.data_type}`)}
|
{t(`fields.types.${def.data_type}`)}
|
||||||
</Badge>
|
</Badge>
|
||||||
{def.required && (
|
{def.required && (
|
||||||
<span
|
<span
|
||||||
className="text-xs text-destructive"
|
className="shrink-0 text-xs text-destructive"
|
||||||
title={t("fields.required")}
|
title={t("fields.required")}
|
||||||
aria-label={t("fields.required")}
|
aria-label={t("fields.required")}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
import { useState } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
||||||
import type { components } from "../api/schema";
|
import { useFieldDefinitions } from "../api/queries";
|
||||||
import { FieldList } from "./field-list";
|
import { FieldList } from "./field-list";
|
||||||
import { FieldForm } from "./field-form";
|
import { FieldForm } from "./field-form";
|
||||||
import { useDocumentTitle } from "../lib/use-document-title";
|
import { useDocumentTitle } from "../lib/use-document-title";
|
||||||
import { useBreadcrumb } from "../shell/use-breadcrumb";
|
import { useBreadcrumb } from "../shell/use-breadcrumb";
|
||||||
import { PageTitle } from "@/components/ui/page-title";
|
import { PageTitle } from "@/components/ui/page-title";
|
||||||
|
|
||||||
type FieldDefinitionView = components["schemas"]["FieldDefinitionView"];
|
|
||||||
|
|
||||||
export function FieldsPage() {
|
export function FieldsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [selected, setSelected] = useState<FieldDefinitionView | null>(null);
|
const navigate = useNavigate();
|
||||||
|
const { key } = useParams();
|
||||||
|
const { data } = useFieldDefinitions();
|
||||||
|
|
||||||
|
// Selection lives in the URL (/fields/:key) so it survives reload and can be
|
||||||
|
// shared, matching /vocabularies/:id. An unknown or absent key falls back to
|
||||||
|
// the create form. Same cached query as FieldList, so no extra fetch.
|
||||||
|
const selected = (key && data?.find((def) => def.key === key)) || null;
|
||||||
|
|
||||||
useDocumentTitle(t("fields.title"));
|
useDocumentTitle(t("fields.title"));
|
||||||
useBreadcrumb([{ label: t("nav.fields") }]);
|
useBreadcrumb([{ label: t("nav.fields") }]);
|
||||||
@@ -22,13 +27,16 @@ export function FieldsPage() {
|
|||||||
<PageTitle className="px-4 pt-4 pb-2">{t("fields.title")}</PageTitle>
|
<PageTitle className="px-4 pt-4 pb-2">{t("fields.title")}</PageTitle>
|
||||||
<div className="grid flex-1 grid-cols-1 overflow-auto lg:grid-cols-[20rem_1fr] lg:overflow-hidden">
|
<div className="grid flex-1 grid-cols-1 overflow-auto lg:grid-cols-[20rem_1fr] lg:overflow-hidden">
|
||||||
<div className="overflow-hidden border-b lg:border-r lg:border-b-0">
|
<div className="overflow-hidden border-b lg:border-r lg:border-b-0">
|
||||||
<FieldList selectedKey={selected?.key ?? null} onSelect={setSelected} />
|
<FieldList
|
||||||
|
selectedKey={selected?.key ?? null}
|
||||||
|
onSelect={(def) => navigate(`/fields/${encodeURIComponent(def.key)}`)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-hidden">
|
<div className="overflow-hidden">
|
||||||
<FieldForm
|
<FieldForm
|
||||||
key={selected?.key ?? "create"}
|
key={selected?.key ?? "create"}
|
||||||
editing={selected}
|
editing={selected}
|
||||||
onDone={() => setSelected(null)}
|
onDone={() => navigate("/fields")}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { FieldsPage } from "./fields-page";
|
|||||||
function tree() {
|
function tree() {
|
||||||
return (
|
return (
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/fields" element={<FieldsPage />} />
|
<Route path="/fields/:key?" element={<FieldsPage />} />
|
||||||
</Routes>
|
</Routes>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -87,6 +87,40 @@ test("filter narrows the visible fields", async () => {
|
|||||||
expect(await screen.findByText(/no matches/i)).toBeInTheDocument();
|
expect(await screen.findByText(/no matches/i)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("deep link /fields/:key opens the edit form for that field", async () => {
|
||||||
|
renderApp(tree(), { route: "/fields/inscription" });
|
||||||
|
|
||||||
|
// edit mode: the key input is locked and prefilled from the URL. The form
|
||||||
|
// remounts when the defs query resolves, so re-query inside waitFor.
|
||||||
|
await waitFor(() => expect(screen.getByLabelText(/^key$/i)).toHaveValue("inscription"));
|
||||||
|
expect(screen.getByLabelText(/^key$/i)).toBeDisabled();
|
||||||
|
expect(screen.getByRole("button", { name: /cancel/i })).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("selecting a field switches to its edit form; cancel returns to create", async () => {
|
||||||
|
renderApp(tree(), { route: "/fields" });
|
||||||
|
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: /inscription/i }));
|
||||||
|
|
||||||
|
await waitFor(() => expect(screen.getByLabelText(/^key$/i)).toHaveValue("inscription"));
|
||||||
|
expect(screen.getByLabelText(/^key$/i)).toBeDisabled();
|
||||||
|
|
||||||
|
await userEvent.click(screen.getByRole("button", { name: /cancel/i }));
|
||||||
|
|
||||||
|
await waitFor(() => expect(screen.getByLabelText(/^key$/i)).toHaveValue(""));
|
||||||
|
expect(screen.getByLabelText(/^key$/i)).toBeEnabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("an unknown key falls back to the create form", async () => {
|
||||||
|
renderApp(tree(), { route: "/fields/zzz-does-not-exist" });
|
||||||
|
|
||||||
|
await screen.findByText("Inscription");
|
||||||
|
|
||||||
|
const key = screen.getByLabelText(/^key$/i);
|
||||||
|
expect(key).toHaveValue("");
|
||||||
|
expect(key).toBeEnabled();
|
||||||
|
});
|
||||||
|
|
||||||
test("creates a text field — posts the body and clears the key input", async () => {
|
test("creates a text field — posts the body and clears the key input", async () => {
|
||||||
let body: { key: string; data_type: string } | undefined;
|
let body: { key: string; data_type: string } | undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"common": { "yes": "Yes", "no": "No", "close": "Close", "loading": "Loading", "filter": "Filter…", "noMatches": "No matches", "language": "Language", "skipToContent": "Skip to content", "clear": "Clear", "open": "Open" },
|
"common": { "yes": "Yes", "no": "No", "close": "Close", "loading": "Loading", "filter": "Filter…", "noMatches": "No matches", "language": "Language", "skipToContent": "Skip to content", "clear": "Clear", "open": "Open" },
|
||||||
"nav": { "objects": "Objects", "vocabularies": "Vocabularies", "authorities": "Authorities", "fields": "Fields", "search": "Search", "collapseSidebar": "Collapse sidebar", "expandSidebar": "Expand sidebar", "breadcrumb": "Breadcrumb" },
|
"nav": { "objects": "Objects", "vocabularies": "Vocabularies", "authorities": "Authorities", "fields": "Fields", "search": "Search", "collapseSidebar": "Collapse sidebar", "expandSidebar": "Expand sidebar", "breadcrumb": "Breadcrumb" },
|
||||||
"auth": { "email": "Email", "password": "Password", "signIn": "Sign in", "signOut": "Sign out", "invalid": "Invalid email or password", "networkError": "Could not reach the server", "sessionExpired": "Your session expired — please sign in again.", "signingOut": "Signing out…" },
|
"auth": { "email": "Email", "password": "Password", "signIn": "Sign in", "signingIn": "Signing in…", "signOut": "Sign out", "invalid": "Invalid email or password", "networkError": "Could not reach the server", "sessionExpired": "Your session expired — please sign in again.", "signingOut": "Signing out…" },
|
||||||
"objects": { "title": "Objects", "empty": "No objects yet", "loadError": "Could not load objects", "notFound": "Object not found", "prev": "Previous", "next": "Next", "of": "of", "new": "New object", "filter": "Filter objects…", "pageSize": "Per page", "columns": { "number": "Object №", "name": "Name", "visibility": "Visibility", "location": "Location", "count": "#", "updated": "Updated" }, "unknownRef": "(unknown)", "detailTitle": "Object detail", "tableLabel": "Objects" },
|
"objects": { "title": "Objects", "empty": "No objects yet", "loadError": "Could not load objects", "notFound": "Object not found", "prev": "Previous", "next": "Next", "of": "of", "new": "New object", "filter": "Filter objects…", "pageSize": "Per page", "columns": { "number": "Object №", "name": "Name", "visibility": "Visibility", "location": "Location", "count": "#", "updated": "Updated" }, "unknownRef": "(unknown)", "detailTitle": "Object detail", "tableLabel": "Objects" },
|
||||||
"fieldsLabels": { "objectNumber": "Object number", "objectName": "Name", "count": "Number of objects", "briefDescription": "Brief description", "currentLocation": "Current location", "currentOwner": "Current owner", "recorder": "Recorder", "recordingDate": "Recording date", "visibility": "Visibility" },
|
"fieldsLabels": { "objectNumber": "Object number", "objectName": "Name", "count": "Number of objects", "briefDescription": "Brief description", "currentLocation": "Current location", "currentOwner": "Current owner", "recorder": "Recorder", "recordingDate": "Recording date", "visibility": "Visibility" },
|
||||||
"visibility": { "draft": "Draft", "internal": "Internal", "public": "Public" },
|
"visibility": { "draft": "Draft", "internal": "Internal", "public": "Public" },
|
||||||
"form": { "selectPlaceholder": "— select —", "create": "Create object", "save": "Save", "cancel": "Cancel", "visibility": "Visibility", "draft": "Draft", "internal": "Internal", "required": "This field is required", "rejected": "The server rejected the changes — check required and referenced fields", "fieldRejected": "The field \"{{field}}\" was rejected — check its value", "createdButFieldRejected": "Object created, but a field was rejected — fix it below.", "flexibleHeading": "Catalogue fields", "saving": "Saving…", "createAnother": "Save & create another", "minCount": "Must be at least 1", "fieldError": { "type_mismatch": "Wrong type for this field", "unresolved": "Referenced value not found", "unknown": "Unknown field" }, "unsaved": { "title": "Discard unsaved changes?", "body": "You have unsaved changes that will be lost.", "stay": "Keep editing", "leave": "Discard" } },
|
"form": { "selectPlaceholder": "Select…", "create": "Create object", "save": "Save", "cancel": "Cancel", "visibility": "Visibility", "draft": "Draft", "internal": "Internal", "required": "This field is required", "rejected": "The server rejected the changes — check required and referenced fields", "fieldRejected": "The field \"{{field}}\" was rejected — check its value", "createdButFieldRejected": "Object created, but a field was rejected — fix it below.", "flexibleHeading": "Catalogue fields", "saving": "Saving…", "createAnother": "Save & create another", "minCount": "Must be at least 1", "fieldError": { "type_mismatch": "Wrong type for this field", "unresolved": "Referenced value not found", "unknown": "Unknown field" }, "unsaved": { "title": "Discard unsaved changes?", "body": "You have unsaved changes that will be lost.", "stay": "Keep editing", "leave": "Discard" } },
|
||||||
"actions": { "edit": "Edit", "delete": "Delete", "rename": "Rename", "save": "Save", "closeDetail": "Close detail", "confirmDelete": "Delete this object? This cannot be undone.", "confirmDeleteTerm": "Delete this term? This cannot be undone.", "confirmDeleteAuthority": "Delete this authority? This cannot be undone.", "confirmDeleteField": "Delete this field definition? This cannot be undone.", "confirmDeleteVocabulary": "Delete this vocabulary? This cannot be undone.", "inUse": "Can't delete — used by {{count}} object(s). Clear those fields first." },
|
"actions": { "deleting": "Deleting…", "edit": "Edit", "delete": "Delete", "rename": "Rename", "save": "Save", "closeDetail": "Close detail", "confirmDelete": "Delete this object? This cannot be undone.", "confirmDeleteTerm": "Delete this term? This cannot be undone.", "confirmDeleteAuthority": "Delete this authority? This cannot be undone.", "confirmDeleteField": "Delete this field definition? This cannot be undone.", "confirmDeleteVocabulary": "Delete this vocabulary? This cannot be undone.", "inUse": "Can't delete — used by {{count}} object(s). Clear those fields first." },
|
||||||
"labels": { "label": "Label", "externalUri": "External URI (optional)", "otherLanguages": "This entry also has labels in other languages, which are kept.", "uriPlaceholder": "https://…" },
|
"labels": { "label": "Label", "externalUri": "External URI (optional)", "otherLanguages": "This entry also has labels in other languages, which are kept.", "uriPlaceholder": "https://…" },
|
||||||
"theme": { "light": "Light", "dark": "Dark", "system": "System" },
|
"theme": { "light": "Light", "dark": "Dark", "system": "System" },
|
||||||
"vocab": {
|
"vocab": {
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
"authorityKind": "Authority kind",
|
"authorityKind": "Authority kind",
|
||||||
"anyKind": "Any",
|
"anyKind": "Any",
|
||||||
"group": "Group",
|
"group": "Group",
|
||||||
|
"lockedNote": "Key and type can't be changed after creation.",
|
||||||
"required": "Required",
|
"required": "Required",
|
||||||
"create": "Create field",
|
"create": "Create field",
|
||||||
"empty": "No field definitions yet",
|
"empty": "No field definitions yet",
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"common": { "yes": "Ja", "no": "Nej", "close": "Stäng", "loading": "Laddar", "filter": "Filtrera…", "noMatches": "Inga träffar", "language": "Språk", "skipToContent": "Hoppa till innehåll", "clear": "Rensa", "open": "Öppna" },
|
"common": { "yes": "Ja", "no": "Nej", "close": "Stäng", "loading": "Laddar", "filter": "Filtrera…", "noMatches": "Inga träffar", "language": "Språk", "skipToContent": "Hoppa till innehåll", "clear": "Rensa", "open": "Öppna" },
|
||||||
"nav": { "objects": "Föremål", "vocabularies": "Vokabulär", "authorities": "Auktoriteter", "fields": "Fält", "search": "Sök", "collapseSidebar": "Fäll ihop sidofältet", "expandSidebar": "Fäll ut sidofältet", "breadcrumb": "Brödsmulor" },
|
"nav": { "objects": "Föremål", "vocabularies": "Vokabulär", "authorities": "Auktoriteter", "fields": "Fält", "search": "Sök", "collapseSidebar": "Fäll ihop sidofältet", "expandSidebar": "Fäll ut sidofältet", "breadcrumb": "Brödsmulor" },
|
||||||
"auth": { "email": "E-post", "password": "Lösenord", "signIn": "Logga in", "signOut": "Logga ut", "invalid": "Fel e-post eller lösenord", "networkError": "Kunde inte nå servern", "sessionExpired": "Din session har gått ut — logga in igen.", "signingOut": "Loggar ut…" },
|
"auth": { "email": "E-post", "password": "Lösenord", "signIn": "Logga in", "signingIn": "Loggar in…", "signOut": "Logga ut", "invalid": "Fel e-post eller lösenord", "networkError": "Kunde inte nå servern", "sessionExpired": "Din session har gått ut — logga in igen.", "signingOut": "Loggar ut…" },
|
||||||
"objects": { "title": "Föremål", "empty": "Inga föremål ännu", "loadError": "Kunde inte ladda föremål", "notFound": "Föremålet hittades inte", "prev": "Föregående", "next": "Nästa", "of": "av", "new": "Nytt föremål", "filter": "Filtrera föremål…", "pageSize": "Per sida", "columns": { "number": "Föremålsnr", "name": "Namn", "visibility": "Synlighet", "location": "Plats", "count": "Antal", "updated": "Uppdaterad" }, "unknownRef": "(okänd)", "detailTitle": "Objektdetalj", "tableLabel": "Objekt" },
|
"objects": { "title": "Föremål", "empty": "Inga föremål ännu", "loadError": "Kunde inte ladda föremål", "notFound": "Föremålet hittades inte", "prev": "Föregående", "next": "Nästa", "of": "av", "new": "Nytt föremål", "filter": "Filtrera föremål…", "pageSize": "Per sida", "columns": { "number": "Föremålsnr", "name": "Namn", "visibility": "Synlighet", "location": "Plats", "count": "Antal", "updated": "Uppdaterad" }, "unknownRef": "(okänd)", "detailTitle": "Objektdetalj", "tableLabel": "Objekt" },
|
||||||
"fieldsLabels": { "objectNumber": "Föremålsnummer", "objectName": "Namn", "count": "Antal föremål", "briefDescription": "Kort beskrivning", "currentLocation": "Nuvarande plats", "currentOwner": "Nuvarande ägare", "recorder": "Registrerad av", "recordingDate": "Registreringsdatum", "visibility": "Synlighet" },
|
"fieldsLabels": { "objectNumber": "Föremålsnummer", "objectName": "Namn", "count": "Antal föremål", "briefDescription": "Kort beskrivning", "currentLocation": "Nuvarande plats", "currentOwner": "Nuvarande ägare", "recorder": "Registrerad av", "recordingDate": "Registreringsdatum", "visibility": "Synlighet" },
|
||||||
"visibility": { "draft": "Utkast", "internal": "Intern", "public": "Publik" },
|
"visibility": { "draft": "Utkast", "internal": "Intern", "public": "Publik" },
|
||||||
"form": { "selectPlaceholder": "— välj —", "create": "Skapa föremål", "save": "Spara", "cancel": "Avbryt", "visibility": "Synlighet", "draft": "Utkast", "internal": "Intern", "required": "Fältet är obligatoriskt", "rejected": "Servern avvisade ändringarna — kontrollera obligatoriska och refererade fält", "fieldRejected": "Fältet \"{{field}}\" avvisades — kontrollera värdet", "createdButFieldRejected": "Föremålet skapades, men ett fält avvisades — åtgärda nedan.", "flexibleHeading": "Katalogfält", "saving": "Sparar…", "createAnother": "Spara & skapa ny", "minCount": "Måste vara minst 1", "fieldError": { "type_mismatch": "Fel typ för detta fält", "unresolved": "Refererat värde hittades inte", "unknown": "Okänt fält" }, "unsaved": { "title": "Kasta osparade ändringar?", "body": "Du har osparade ändringar som går förlorade.", "stay": "Fortsätt redigera", "leave": "Kasta" } },
|
"form": { "selectPlaceholder": "Välj…", "create": "Skapa föremål", "save": "Spara", "cancel": "Avbryt", "visibility": "Synlighet", "draft": "Utkast", "internal": "Intern", "required": "Fältet är obligatoriskt", "rejected": "Servern avvisade ändringarna — kontrollera obligatoriska och refererade fält", "fieldRejected": "Fältet \"{{field}}\" avvisades — kontrollera värdet", "createdButFieldRejected": "Föremålet skapades, men ett fält avvisades — åtgärda nedan.", "flexibleHeading": "Katalogfält", "saving": "Sparar…", "createAnother": "Spara & skapa ny", "minCount": "Måste vara minst 1", "fieldError": { "type_mismatch": "Fel typ för detta fält", "unresolved": "Refererat värde hittades inte", "unknown": "Okänt fält" }, "unsaved": { "title": "Kasta osparade ändringar?", "body": "Du har osparade ändringar som går förlorade.", "stay": "Fortsätt redigera", "leave": "Kasta" } },
|
||||||
"actions": { "edit": "Redigera", "delete": "Ta bort", "rename": "Byt namn", "save": "Spara", "closeDetail": "Stäng detalj", "confirmDelete": "Ta bort detta föremål? Detta kan inte ångras.", "confirmDeleteTerm": "Ta bort denna term? Detta kan inte ångras.", "confirmDeleteAuthority": "Ta bort denna auktoritet? Detta kan inte ångras.", "confirmDeleteField": "Ta bort denna fältdefinition? Detta kan inte ångras.", "confirmDeleteVocabulary": "Ta bort denna vokabulär? Detta kan inte ångras.", "inUse": "Kan inte ta bort — används av {{count}} föremål. Rensa de fälten först." },
|
"actions": { "deleting": "Tar bort…", "edit": "Redigera", "delete": "Ta bort", "rename": "Byt namn", "save": "Spara", "closeDetail": "Stäng detalj", "confirmDelete": "Ta bort detta föremål? Detta kan inte ångras.", "confirmDeleteTerm": "Ta bort denna term? Detta kan inte ångras.", "confirmDeleteAuthority": "Ta bort denna auktoritet? Detta kan inte ångras.", "confirmDeleteField": "Ta bort denna fältdefinition? Detta kan inte ångras.", "confirmDeleteVocabulary": "Ta bort denna vokabulär? Detta kan inte ångras.", "inUse": "Kan inte ta bort — används av {{count}} föremål. Rensa de fälten först." },
|
||||||
"labels": { "label": "Etikett", "externalUri": "Extern URI (valfritt)", "otherLanguages": "Denna post har även etiketter på andra språk, som behålls.", "uriPlaceholder": "https://…" },
|
"labels": { "label": "Etikett", "externalUri": "Extern URI (valfritt)", "otherLanguages": "Denna post har även etiketter på andra språk, som behålls.", "uriPlaceholder": "https://…" },
|
||||||
"theme": { "light": "Ljust", "dark": "Mörkt", "system": "System" },
|
"theme": { "light": "Ljust", "dark": "Mörkt", "system": "System" },
|
||||||
"vocab": {
|
"vocab": {
|
||||||
@@ -41,6 +41,7 @@
|
|||||||
"authorityKind": "Auktoritetstyp",
|
"authorityKind": "Auktoritetstyp",
|
||||||
"anyKind": "Alla",
|
"anyKind": "Alla",
|
||||||
"group": "Grupp",
|
"group": "Grupp",
|
||||||
|
"lockedNote": "Nyckel och typ kan inte ändras efter att fältet skapats.",
|
||||||
"required": "Obligatoriskt",
|
"required": "Obligatoriskt",
|
||||||
"create": "Skapa fält",
|
"create": "Skapa fält",
|
||||||
"empty": "Inga fältdefinitioner ännu",
|
"empty": "Inga fältdefinitioner ännu",
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
|
color-scheme: light;
|
||||||
--background: oklch(1 0 0);
|
--background: oklch(1 0 0);
|
||||||
--foreground: oklch(0.145 0 0);
|
--foreground: oklch(0.145 0 0);
|
||||||
--card: oklch(1 0 0);
|
--card: oklch(1 0 0);
|
||||||
@@ -63,6 +64,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
|
color-scheme: dark;
|
||||||
--background: oklch(0.145 0 0);
|
--background: oklch(0.145 0 0);
|
||||||
--foreground: oklch(0.985 0 0);
|
--foreground: oklch(0.985 0 0);
|
||||||
--card: oklch(0.205 0 0);
|
--card: oklch(0.205 0 0);
|
||||||
@@ -97,6 +99,19 @@
|
|||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground font-sans;
|
@apply bg-background text-foreground font-sans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Collapse all animation/transition to a single frame for users who ask the
|
||||||
|
OS for reduced motion. Covers the kit's data-open/closed animations, the
|
||||||
|
skeleton pulse, and the sidebar width transition in one place. */
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
*,
|
||||||
|
::before,
|
||||||
|
::after {
|
||||||
|
animation-duration: 0.01ms !important;
|
||||||
|
animation-iteration-count: 1 !important;
|
||||||
|
transition-duration: 0.01ms !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer components {
|
@layer components {
|
||||||
|
|||||||
@@ -41,6 +41,35 @@ test("confirm delete: DELETE then navigate to the list", async () => {
|
|||||||
expect(deleted).toBe(true);
|
expect(deleted).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("confirm is disabled and labelled Deleting… while the DELETE is in flight", async () => {
|
||||||
|
let release!: () => void;
|
||||||
|
const gate = new Promise<void>((r) => {
|
||||||
|
release = r;
|
||||||
|
});
|
||||||
|
|
||||||
|
server.use(
|
||||||
|
http.delete("/api/admin/objects/:id", async () => {
|
||||||
|
await gate;
|
||||||
|
return new HttpResponse(null, { status: 204 });
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
renderApp(tree(), { route: "/objects/o-1" });
|
||||||
|
|
||||||
|
await userEvent.click(await screen.findByRole("button", { name: /delete/i }));
|
||||||
|
|
||||||
|
const dialog = await screen.findByRole("alertdialog");
|
||||||
|
|
||||||
|
await userEvent.click(within(dialog).getByRole("button", { name: /delete/i }));
|
||||||
|
|
||||||
|
const pending = await within(dialog).findByRole("button", { name: /deleting/i });
|
||||||
|
expect(pending).toBeDisabled();
|
||||||
|
expect(within(dialog).getByRole("button", { name: /cancel/i })).toBeDisabled();
|
||||||
|
|
||||||
|
release();
|
||||||
|
await waitFor(() => expect(screen.getByText("objects list")).toBeInTheDocument());
|
||||||
|
});
|
||||||
|
|
||||||
test("cancel does not delete", async () => {
|
test("cancel does not delete", async () => {
|
||||||
let deleted = false;
|
let deleted = false;
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,9 @@ export function DeleteObjectDialog({ id }: { id: string }) {
|
|||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
<AlertDialogFooter>
|
<AlertDialogFooter>
|
||||||
<AlertDialogCancel>{t("form.cancel")}</AlertDialogCancel>
|
<AlertDialogCancel disabled={del.isPending}>{t("form.cancel")}</AlertDialogCancel>
|
||||||
<AlertDialogAction onClick={onConfirm}>
|
<AlertDialogAction disabled={del.isPending} onClick={onConfirm}>
|
||||||
{t("actions.delete")}
|
{del.isPending ? t("actions.deleting") : t("actions.delete")}
|
||||||
</AlertDialogAction>
|
</AlertDialogAction>
|
||||||
</AlertDialogFooter>
|
</AlertDialogFooter>
|
||||||
</AlertDialogContent>
|
</AlertDialogContent>
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ test("term field filters and selects from the vocabulary combobox", async () =>
|
|||||||
|
|
||||||
renderApp(<FormHarness defKey="material" onSubmit={(v) => submitted.push(v)} />);
|
renderApp(<FormHarness defKey="material" onSubmit={(v) => submitted.push(v)} />);
|
||||||
|
|
||||||
const input = await screen.findByPlaceholderText("— select —");
|
const input = await screen.findByPlaceholderText("Select…");
|
||||||
|
|
||||||
await user.click(input);
|
await user.click(input);
|
||||||
await user.type(input, "bro");
|
await user.type(input, "bro");
|
||||||
@@ -73,7 +73,7 @@ test("authority field filters and selects from the authority combobox", async ()
|
|||||||
|
|
||||||
renderApp(<FormHarness defKey="maker" onSubmit={(v) => submitted.push(v)} />);
|
renderApp(<FormHarness defKey="maker" onSubmit={(v) => submitted.push(v)} />);
|
||||||
|
|
||||||
const input = await screen.findByPlaceholderText("— select —");
|
const input = await screen.findByPlaceholderText("Select…");
|
||||||
|
|
||||||
await user.click(input);
|
await user.click(input);
|
||||||
await user.type(input, "ada");
|
await user.type(input, "ada");
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ export function ObjectsTable() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => toggleSort(col)}
|
onClick={() => toggleSort(col)}
|
||||||
className="flex items-center gap-1 hover:text-foreground"
|
className={`flex items-center gap-1 rounded-sm hover:text-foreground ${focusRing}`}
|
||||||
>
|
>
|
||||||
{t(COLUMN_KEYS[col])}
|
{t(COLUMN_KEYS[col])}
|
||||||
<Icon className="size-3.5 text-muted-foreground" aria-hidden="true" />
|
<Icon className="size-3.5 text-muted-foreground" aria-hidden="true" />
|
||||||
@@ -287,7 +287,7 @@ export function ObjectsTable() {
|
|||||||
value={limit}
|
value={limit}
|
||||||
onChange={(event) => setLimit(Number(event.target.value))}
|
onChange={(event) => setLimit(Number(event.target.value))}
|
||||||
aria-label={t("objects.pageSize")}
|
aria-label={t("objects.pageSize")}
|
||||||
className="rounded-md border bg-white px-1 py-0.5"
|
className={`rounded-md border bg-background px-1 py-0.5 ${focusRing}`}
|
||||||
>
|
>
|
||||||
{PAGE_SIZES.map((size) => (
|
{PAGE_SIZES.map((size) => (
|
||||||
<option key={size} value={size}>
|
<option key={size} value={size}>
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export function SearchPanel() {
|
|||||||
|
|
||||||
{hits.length > 0 && (
|
{hits.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<p className="px-3 pt-2 text-xs text-muted-foreground">
|
<p role="status" className="px-3 pt-2 text-xs text-muted-foreground">
|
||||||
{t("search.resultCount", { count: total })}
|
{t("search.resultCount", { count: total })}
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ test("typing searches and renders highlighted rich rows", async () => {
|
|||||||
expect(await screen.findByText("Bronze figurine")).toBeInTheDocument();
|
expect(await screen.findByText("Bronze figurine")).toBeInTheDocument();
|
||||||
const mark = await screen.findByText("bronze");
|
const mark = await screen.findByText("bronze");
|
||||||
expect(mark.tagName).toBe("MARK");
|
expect(mark.tagName).toBe("MARK");
|
||||||
expect(screen.getByText(/~\s*25 results/i)).toBeInTheDocument();
|
// The estimated count lives in a status region so updates are announced.
|
||||||
|
expect(screen.getByRole("status")).toHaveTextContent(/~\s*25 results/i);
|
||||||
expect(screen.getByText(/1962-04-03/)).toBeInTheDocument();
|
expect(screen.getByText(/1962-04-03/)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { Fragment } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
|
import { focusRing } from "../lib/focus-ring";
|
||||||
import { useBreadcrumbTrail } from "./breadcrumb-context";
|
import { useBreadcrumbTrail } from "./breadcrumb-context";
|
||||||
|
|
||||||
export function Breadcrumb() {
|
export function Breadcrumb() {
|
||||||
@@ -16,7 +17,10 @@ export function Breadcrumb() {
|
|||||||
<Fragment key={`${item.label}-${i}`}>
|
<Fragment key={`${item.label}-${i}`}>
|
||||||
{i > 0 && <span className="text-muted-foreground">/</span>}
|
{i > 0 && <span className="text-muted-foreground">/</span>}
|
||||||
{item.to && !last ? (
|
{item.to && !last ? (
|
||||||
<Link to={item.to} className="truncate text-muted-foreground hover:text-foreground">
|
<Link
|
||||||
|
to={item.to}
|
||||||
|
className={`truncate rounded-sm text-muted-foreground hover:text-foreground ${focusRing}`}
|
||||||
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -80,15 +80,16 @@ export function Sidebar() {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={toggle}
|
onClick={toggle}
|
||||||
disabled={narrow}
|
|
||||||
aria-expanded={!collapsed}
|
aria-expanded={!collapsed}
|
||||||
aria-label={t(collapsed ? "nav.expandSidebar" : "nav.collapseSidebar")}
|
aria-label={t(collapsed ? "nav.expandSidebar" : "nav.collapseSidebar")}
|
||||||
title={t(collapsed ? "nav.expandSidebar" : "nav.collapseSidebar")}
|
title={t(collapsed ? "nav.expandSidebar" : "nav.collapseSidebar")}
|
||||||
className={cn(
|
className={cn(
|
||||||
"flex items-center justify-center rounded-md p-1 outline-none",
|
// On narrow viewports the rail is forced collapsed, so the toggle
|
||||||
|
// is hidden rather than shown disabled (a grayed button reads as
|
||||||
|
// broken, not unavailable).
|
||||||
|
"hidden items-center justify-center rounded-md p-1 outline-none md:flex",
|
||||||
"hover:bg-accent",
|
"hover:bg-accent",
|
||||||
focusRing,
|
focusRing,
|
||||||
"disabled:pointer-events-none disabled:opacity-50",
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{collapsed ? (
|
{collapsed ? (
|
||||||
|
|||||||
@@ -40,6 +40,21 @@ test("readTheme defaults to system when unset or invalid", () => {
|
|||||||
expect(readTheme()).toBe("dark");
|
expect(readTheme()).toBe("dark");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("applyTheme syncs the theme-color meta when present", () => {
|
||||||
|
const meta = document.createElement("meta");
|
||||||
|
meta.setAttribute("name", "theme-color");
|
||||||
|
document.head.appendChild(meta);
|
||||||
|
try {
|
||||||
|
mockMatchMedia(false);
|
||||||
|
applyTheme("dark");
|
||||||
|
expect(meta.getAttribute("content")).toBe("#0a0a0a");
|
||||||
|
applyTheme("light");
|
||||||
|
expect(meta.getAttribute("content")).toBe("#ffffff");
|
||||||
|
} finally {
|
||||||
|
meta.remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("applyTheme toggles the dark class on documentElement", () => {
|
test("applyTheme toggles the dark class on documentElement", () => {
|
||||||
mockMatchMedia(false);
|
mockMatchMedia(false);
|
||||||
applyTheme("dark");
|
applyTheme("dark");
|
||||||
|
|||||||
@@ -26,8 +26,16 @@ export function readTheme(): Theme {
|
|||||||
return THEMES.includes(stored as Theme) ? (stored as Theme) : "system";
|
return THEMES.includes(stored as Theme) ? (stored as Theme) : "system";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Browser-chrome colors per resolved theme; must match `--background` in index.css. */
|
||||||
|
const THEME_COLORS = { light: "#ffffff", dark: "#0a0a0a" } as const;
|
||||||
|
|
||||||
export function applyTheme(theme: Theme): void {
|
export function applyTheme(theme: Theme): void {
|
||||||
if (typeof document === "undefined") return;
|
if (typeof document === "undefined") return;
|
||||||
|
|
||||||
document.documentElement.classList.toggle("dark", resolveTheme(theme) === "dark");
|
const resolved = resolveTheme(theme);
|
||||||
|
|
||||||
|
document.documentElement.classList.toggle("dark", resolved === "dark");
|
||||||
|
document
|
||||||
|
.querySelector('meta[name="theme-color"]')
|
||||||
|
?.setAttribute("content", THEME_COLORS[resolved]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user