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
2 changes: 1 addition & 1 deletion ci/clicks/journeys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export const JOURNEYS = [
async run(ctx) {
const { page, meter } = ctx;
await jumpTo(ctx);
await meter.type(page.getByRole("combobox", { name: /Search recordings and pages/ }), "welcome", "part of its title");
await meter.type(page.getByRole("combobox", { name: /^Search recordings/ }), "welcome", "part of its title");
await page.getByRole("option", { name: /Welcome back/ }).first().waitFor();
await meter.press("Enter", "Enter to open");
await page.waitForURL(/\/(recordings|resources)\//);
Expand Down
8 changes: 8 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ upload limit, allowed hosts, trusted proxies, session length), remote access, em
telemetry, the Fedora repository, sensors, file shares, uploads, storage, documents, API keys, and IIIF and metadata. The API
refuses an allowed-host list that leaves out the address you are using.

The sections are in groups: AI and search, Speech and voices, Media and documents, Chat and email, Security and
access, Files and devices, and System. **Find a setting** at the top of the list (or `/`) finds a section by its name
or what it's for, and a single setting by its label, hint or choices: Enter opens the first, and a setting found by
its label opens with its field in focus and its value selected, so typing replaces it. ⌘K (Ctrl+K) finds settings
the same way, beside recordings and pages. Agents reach the same settings through the API
(`GET/PUT /api/v1/settings/<section>`), and the admin assistant through `read_settings` and `change_settings`
([Assistant](assistant.md#setting-up-and-running-the-server-by-chat)).

## Word search

Searching by the words goes through the index of `search.engine` (Settings → Search → Word search; how each works is
Expand Down
127 changes: 127 additions & 0 deletions nextjs-frontend/__tests__/settings-find.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import "@testing-library/jest-dom";

import { findSettings, hitHref, SETTINGS_GROUPS } from "@/components/settings/find";
import { SECTIONS } from "@/components/settings/model";
import { SettingsShell } from "@/components/settings/settings-shell";
import { TooltipProvider } from "@/components/ui/tooltip";

const push = jest.fn();
let admin = true;

jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) }));
jest.mock("next/navigation", () => ({
usePathname: () => "/settings/speakers",
useRouter: () => ({ push }),
}));
jest.mock("@/components/speakers/speakers-page", () => ({ SpeakersPage: () => <p>The speakers</p> }));
jest.mock("@/lib/hooks/session", () => ({
useArchive: () => ({
admin,
namespaces: [],
partialNamespaces: [],
namespace: null,
roleIn: () => "owner",
can: () => true,
}),
}));

const shell = () =>
render(
<TooltipProvider>
<SettingsShell section="speakers" />
</TooltipProvider>,
);

beforeEach(() => {
admin = true;
push.mockClear();
});

describe("settings groups", () => {
it("puts every section in exactly one group", () => {
const grouped = SETTINGS_GROUPS.flatMap((g) => g.sections);
expect([...grouped].sort()).toEqual(SECTIONS.map((s) => s.id).sort());
expect(new Set(grouped).size).toBe(grouped.length);
});

it("shows the sections under their groups, the model first", () => {
shell();
expect(screen.getByText("AI and search")).toBeInTheDocument();
expect(screen.getByText("System")).toBeInTheDocument();
const links = screen.getAllByRole("link").map((a) => a.textContent);
expect(links.indexOf("LLM provider")).toBe(links.indexOf("Speakers") + 1);
expect(links).toHaveLength(SECTIONS.length + 1);
});
});

describe("finding a setting", () => {
it("finds a section by its name first", () => {
const hits = findSettings("telegram", true);
expect(hits[0]).toMatchObject({ section: "telegram", byField: false });
expect(hitHref(hits[0])).toBe("/settings/telegram");
});

it("finds a field by its label, and opens the section on it", () => {
const hits = findSettings("timeout seconds", true);
const llm = hits.find((h) => h.section === "llm")!;
expect(llm.byField).toBe(true);
expect(llm.fields.map((f) => f.key)).toContain("timeout");
});

it("finds a field by one of its choices, ignoring case and accents", () => {
const hits = findSettings("DEEPGRAM", true);
expect(hits.some((h) => h.section === "transcription" && h.fields.some((f) => f.key === "engine"))).toBe(true);
});

it("finds only Speakers for people who aren't admins", () => {
expect(findSettings("speak", false).map((h) => h.section)).toEqual(["speakers"]);
expect(findSettings("telegram", false)).toEqual([]);
});

it("filters the list as you type, and Enter opens the first", () => {
shell();
const box = screen.getByRole("searchbox", { name: "Find a setting" });
fireEvent.change(box, { target: { value: "slack" } });
expect(screen.getByRole("link", { name: "Slack" })).toBeInTheDocument();
expect(screen.queryByRole("link", { name: "Transcription" })).not.toBeInTheDocument();
fireEvent.keyDown(box, { key: "Enter" });
expect(push).toHaveBeenCalledWith("/settings/slack");
expect(box).toHaveValue("");
});

it("says so when nothing matches", () => {
shell();
fireEvent.change(screen.getByRole("searchbox", { name: "Find a setting" }), { target: { value: "zzzz" } });
expect(screen.getByText("No setting matches that.")).toBeInTheDocument();
});

it("focuses the Find box on /", async () => {
shell();
fireEvent.keyDown(document.body, { key: "/" });
await waitFor(() => expect(screen.getByRole("searchbox", { name: "Find a setting" })).toHaveFocus());
});

it("has no Find box for people who aren't admins", () => {
admin = false;
shell();
expect(screen.queryByRole("searchbox", { name: "Find a setting" })).not.toBeInTheDocument();
});
});

describe("⌘K", () => {
it("finds settings beside pages, a field opening its section on it", async () => {
const { CommandPalette } = await import("@/components/app-shell/command-palette");
const { QueryClient, QueryClientProvider } = await import("@tanstack/react-query");
render(
<QueryClientProvider client={new QueryClient()}>
<CommandPalette />
</QueryClientProvider>,
);
fireEvent.keyDown(window, { key: "k", ctrlKey: true });
fireEvent.change(screen.getByRole("combobox"), { target: { value: "timeout seconds" } });
const llm = screen.getAllByRole("option").find((o) => o.textContent?.includes("Settings › LLM provider"))!;
fireEvent.click(llm);
expect(push).toHaveBeenCalledWith("/settings/llm?field=llm.timeout");
});
});
17 changes: 17 additions & 0 deletions nextjs-frontend/__tests__/settings-save.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,20 @@ describe("settings", () => {
await waitFor(() => expect(Admin.updateSettings).toHaveBeenCalledTimes(1));
});
});

describe("opened on one setting", () => {
it("focuses its field with the value selected, so typing replaces it", async () => {
const qc = new QueryClient();
render(
<QueryClientProvider client={qc}>
<TooltipProvider>
<SettingsSection id="mail" view={VIEW} onErrors={() => undefined} field="mail.port" />
</TooltipProvider>
</QueryClientProvider>,
);
const port = screen.getByLabelText("Port") as HTMLInputElement;
await waitFor(() => expect(port).toHaveFocus());
expect([port.selectionStart, port.selectionEnd]).toEqual([0, port.value.length]);
expect(port.closest("[data-setting]")).toHaveClass("setting-found");
});
});
7 changes: 7 additions & 0 deletions nextjs-frontend/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@
}
}

/* A setting opened from Find or ⌘K: marked a moment, so the eye lands on it. */
[data-setting].setting-found {
border-radius: 6px;
background: var(--intent-surface);
box-shadow: 0 0 0 6px var(--intent-surface);
}

@keyframes skeleton {
from {
background-position: 200% 0;
Expand Down
24 changes: 20 additions & 4 deletions nextjs-frontend/components/app-shell/command-palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import * as D from "@radix-ui/react-dialog";
import { useQuery } from "@tanstack/react-query";
import { CornerDownLeft, FileAudio, Search, Zap } from "lucide-react";
import { CornerDownLeft, FileAudio, Search, Settings, Zap } from "lucide-react";
import { useRouter } from "next/navigation";
import { useEffect, useMemo, useRef, useState } from "react";

import { Resources } from "@/app/openapi-client";
import { navFor } from "@/components/app-shell/nav-config";
import { findSettings, hitHref, settingHref } from "@/components/settings/find";
import { data, useApiClient } from "@/lib/api/browser";
import { tc } from "@/lib/format";
import { useArchive } from "@/lib/hooks/session";
Expand All @@ -21,7 +22,7 @@ type Item = {
icon: React.ReactNode;
};

/** ⌘K: jump to a recording or a page; ">" limits results to actions. */
/** ⌘K: jump to a recording, a page or a setting; ">" limits results to actions. */
export function CommandPalette() {
const [open, setOpen] = useState(false);
const [q, setQ] = useState("");
Expand Down Expand Up @@ -105,7 +106,22 @@ export function CommandPalette() {
icon: <FileAudio className="size-4" />,
}))
: [];
return [...recordings, ...pages, ...actions];
// Settings by name, or by a field in them (the LLM's timeout): a field opens its section on it
const settings: Item[] = t
? findSettings(t, admin)
.flatMap((h) =>
h.byField
? h.fields.map((f) => ({
label: f.label,
meta: `Settings › ${h.label}`,
href: settingHref(h.section, f),
}))
: [{ label: h.label, meta: `Settings · ${h.group}`, href: hitHref(h) }],
)
.slice(0, 6)
.map((x) => ({ group: "Settings", icon: <Settings className="size-4" />, ...x }))
: [];
return [...recordings, ...pages, ...settings, ...actions];
}, [q, recs.data, admin, can]);

useEffect(() => setSel(0), [q]);
Expand Down Expand Up @@ -167,7 +183,7 @@ export function CommandPalette() {
aria-expanded
aria-controls="palette-list"
aria-activedescendant={items[sel] ? `palette-${sel}` : undefined}
placeholder="Search recordings and pages, or > for actions"
placeholder="Search recordings, pages and settings, or > for actions"
className="h-14 flex-1 bg-transparent text-[16px] text-fg outline-hidden placeholder:text-fg-muted"
/>
<kbd className="rounded-xs border border-border px-1.5 text-[11px] text-fg-muted">esc</kbd>
Expand Down
4 changes: 2 additions & 2 deletions nextjs-frontend/components/app-shell/shortcuts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { useEffect, useState } from "react";
import { Dialog } from "@/components/ui/dialog";

const KEYS: [string, string][] = [
["⌘ K", "Jump to a recording, speaker or page"],
["⌘ K", "Jump to a recording, speaker, page or setting"],
["[", "Collapse or expand the navigation"],
["Space", "Play or pause (recording page)"],
["J / L", "Back or forward 10 seconds"],
["← / →", "Back or forward 5 seconds"],
["↑ / ↓", "Previous or next turn"],
["/", "Find in transcript"],
["/", "Find in transcript, or find a setting"],
["?", "This list"],
];

Expand Down
4 changes: 2 additions & 2 deletions nextjs-frontend/components/settings/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function SettingField({

if (spec.kind === "switch")
return (
<div className={cn("flex items-start justify-between gap-5", className)}>
<div data-setting={fieldId(spec)} className={cn("flex items-start justify-between gap-5", className)}>
<div className="flex flex-col gap-1">
<span className="text-[14px] font-bold leading-tight text-fg">{title}</span>
{text && (
Expand All @@ -74,7 +74,7 @@ export function SettingField({
);

return (
<div className={cn("flex min-w-0 flex-col gap-1.5", className)}>
<div data-setting={fieldId(spec)} className={cn("flex min-w-0 flex-col gap-1.5", className)}>
{spec.kind === "pills" || spec.kind === "cards" || spec.kind === "checks" ? (
<span id={`${id}-label`} className="text-[13px] font-bold leading-tight text-fg-strong">
{title}
Expand Down
84 changes: 84 additions & 0 deletions nextjs-frontend/components/settings/find.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Finding a setting by name: the settings sections in their groups, and a search over the sections' names and
* descriptions and their fields' labels, hints and choices, for the Find box in Settings and ⌘K.
*/
import {
FIELDS,
fieldId,
SECTIONS,
WORKSPACE_SECTIONS,
type AnySectionId,
type FieldSpec,
type SectionId,
} from "@/components/settings/model";

/** The archive's settings sections (admins), in groups, most used first in each. Every section is in one group. */
export const SETTINGS_GROUPS: { label: string; sections: SectionId[] }[] = [
{ label: "AI and search", sections: ["llm", "local-model", "ai", "search", "analysis"] },
{ label: "Speech and voices", sections: ["transcription", "speaker-separation", "voice-ids", "speech-providers"] },
{ label: "Media and documents", sections: ["uploads", "documents", "video", "nsfw", "reports", "iiif"] },
{ label: "Chat and email", sections: ["telegram", "slack", "bridge", "mailbox", "mail", "notifications"] },
{ label: "Security and access", sections: ["sign-in", "tokens", "encryption", "access", "remote-access", "https"] },
{ label: "Files and devices", sections: ["storage", "shares", "smb", "nfs", "fedora", "sensors"] },
{
label: "System",
sections: ["updates", "backups", "components", "workers", "logs", "telemetry", "analytics", "startup"],
},
];

export type SettingHit = {
section: AnySectionId;
/** The section's name. */
label: string;
/** Its group in Settings ("Your namespaces" for Speakers). */
group: string;
/** The fields in it that matched. */
fields: FieldSpec[];
/** Found by a field only, not by the section's name or description: it opens on the first field. */
byField: boolean;
};

/** Where a setting opens: its section, with the field to scroll to and focus. */
export function settingHref(section: AnySectionId, field?: FieldSpec): string {
return field ? `/settings/${section}?field=${encodeURIComponent(fieldId(field))}` : `/settings/${section}`;
}

const fold = (s: string) => s.toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/[’‘]/g, "'");

/** Sections (and the fields in them) holding every word of `term`, best first: a section by its name, then by its
* group or description, then sections with a field whose label, hint, key or choices match. Admins search every
* section; members only theirs (Speakers). */
export function findSettings(term: string, admin: boolean): SettingHit[] {
const words = fold(term).split(/\s+/).filter(Boolean);
if (!words.length) return [];
const has = (text: string) => {
const t = fold(text);
return words.every((w) => t.includes(w));
};
const byName: SettingHit[] = [];
const byAbout: SettingHit[] = [];
const byField: SettingHit[] = [];
for (const s of WORKSPACE_SECTIONS)
if (has(`${s.label} ${s.id}`))
byName.push({ section: s.id, label: s.label, group: "Your namespaces", fields: [], byField: false });
if (!admin) return byName;
for (const g of SETTINGS_GROUPS)
for (const id of g.sections) {
const s = SECTIONS.find((x) => x.id === id)!;
const fields = FIELDS.filter(
(f) =>
s.backend.includes(f.section) &&
has(
`${f.label} ${f.hint ?? ""} ${f.unit ?? ""} ${fieldId(f)} ${(f.options ?? []).map((o) => o.label).join(" ")}`,
),
);
const hit = { section: s.id, label: s.label, group: g.label, fields, byField: false };
if (has(`${s.label} ${s.id}`)) byName.push(hit);
else if (has(`${g.label} ${s.description}`)) byAbout.push(hit);
else if (fields.length) byField.push({ ...hit, byField: true });
}
return [...byName, ...byAbout, ...byField];
}

/** Where a hit opens: on its first field when only a field matched, else at the top of the section. */
export const hitHref = (h: SettingHit) => settingHref(h.section, h.byField ? h.fields[0] : undefined);
2 changes: 1 addition & 1 deletion nextjs-frontend/components/settings/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export const SECTIONS: SectionSpec[] = [
},
{
id: "updates",
label: "Updates and backups",
label: "Updates",
backend: ["updates"],
description:
"New Lens releases: Lens checks for one once a day, backs up and installs it when you say so, and goes back if it doesn't start.",
Expand Down
Loading
Loading