Add dedicated bot, workspace and user settings pages

This commit is contained in:
2026-10-19 13:17:17 +01:00
parent 731ea73486
commit 7667f2bc2f
74 changed files with 2183 additions and 358 deletions
@@ -0,0 +1,36 @@
import { describe, expect, test } from "bun:test";
import parseSettingsRecordPath from "./parse-settings-record-path";
describe("parseSettingsRecordPath", () => {
test("reads a nested settings record", () => {
expect(
parseSettingsRecordPath({ pathname: "/admin/settings/bots/3" }),
).toEqual({ kind: "bots", id: "3" });
expect(
parseSettingsRecordPath({
pathname: "/admin/settings/workspaces/12/",
}),
).toEqual({ kind: "workspaces", id: "12" });
expect(
parseSettingsRecordPath({ pathname: "/admin/settings/users/8" }),
).toEqual({ kind: "users", id: "8" });
});
test("ignores settings list pages and other paths", () => {
expect(
parseSettingsRecordPath({ pathname: "/admin/settings/bots" }),
).toBeNull();
expect(
parseSettingsRecordPath({ pathname: "/admin/settings/models" }),
).toBeNull();
expect(
parseSettingsRecordPath({
pathname: "/admin/settings/bots/3/models",
}),
).toBeNull();
expect(
parseSettingsRecordPath({ pathname: "/admin/bots/3" }),
).toBeNull();
expect(parseSettingsRecordPath({ pathname: undefined })).toBeNull();
});
});
+32
View File
@@ -0,0 +1,32 @@
export type SettingsRecordKind = "bots" | "workspaces" | "users";
export type SettingsRecordPath = {
kind: SettingsRecordKind;
id: string;
};
type Params = {
pathname?: string | null;
};
/**
* The record a nested settings page manages, e.g.
* `/admin/settings/bots/3` -> `{ kind: "bots", id: "3" }`. Null on the
* settings list pages and everywhere else.
*/
export default function parseSettingsRecordPath({
pathname,
}: Params): SettingsRecordPath | null {
if (!pathname) return null;
const match = pathname
.replace(/\/$/, "")
.match(/^\/admin\/settings\/(bots|workspaces|users)\/([^/]+)$/);
if (!match) return null;
return {
kind: match[1] as SettingsRecordKind,
id: match[2]!,
};
}