Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
feat(web): add provider model bulk visibility toggle (#243)
Leo46a555df95ca
diff --git a/apps/web/src/components/settings/ProviderModelsSection.test.ts b/apps/web/src/components/settings/ProviderModelsSection.test.tsnew file mode 100644index 000000000..09b9507a5--- /dev/null+++ b/apps/web/src/components/settings/ProviderModelsSection.test.ts@@ -0,0 +1,104 @@+import { createElement, type ReactNode } from "react";+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it, vi } from "vite-plus/test";+import {+ ProviderDriverKind,+ ProviderInstanceId,+ type ServerProviderModel,+} from "@t3tools/contracts";++const mocks = vi.hoisted(() => ({+ buttons: new Map<string, { onClick?: () => void }>(),+}));++vi.mock("../ui/button", () => ({+ Button: (props: { children: ReactNode; onClick?: () => void }) => {+ if (typeof props.children === "string") mocks.buttons.set(props.children, props);+ return null;+ },+}));++import { nextHiddenModelsForBulkToggle, ProviderModelsSection } from "./ProviderModelsSection";++function model(slug: string, isCustom = false): ServerProviderModel {+ return { slug, name: slug, isCustom, capabilities: null };+}++describe("nextHiddenModelsForBulkToggle", () => {+ it("hides every built-in model without hiding custom models", () => {+ const models = [model("a"), model("b"), model("custom", true)];++ expect(nextHiddenModelsForBulkToggle(models, ["a"])).toEqual(["a", "b"]);+ });++ it("shows every built-in model while preserving unrelated hidden entries", () => {+ const models = [model("a"), model("b"), model("custom", true)];++ expect(nextHiddenModelsForBulkToggle(models, ["a", "b", "legacy", "custom"])).toEqual([+ "legacy",+ "custom",+ ]);+ });++ it("leaves favorites untouched because they are a separate list", () => {+ const models = [model("codex"), model("gpt-5"), model("custom", true)];+ const next = nextHiddenModelsForBulkToggle(models, []);+ expect(next).toEqual(["codex", "gpt-5"]);+ expect(next).not.toContain("custom");+ });+});++describe("ProviderModelsSection bulk visibility control", () => {+ function renderSection(input: {+ models: ReadonlyArray<ServerProviderModel>;+ hiddenModels?: ReadonlyArray<string>;+ }) {+ mocks.buttons.clear();+ const onHiddenModelsChange = vi.fn();+ renderToStaticMarkup(+ createElement(ProviderModelsSection, {+ instanceId: ProviderInstanceId.make("codex"),+ driverKind: ProviderDriverKind.make("codex"),+ models: input.models,+ customModels: input.models.filter((entry) => entry.isCustom).map((entry) => entry.slug),+ hiddenModels: input.hiddenModels ?? [],+ favoriteModels: [],+ modelOrder: [],+ onChange: vi.fn(),+ onHiddenModelsChange,+ onFavoriteModelsChange: vi.fn(),+ onModelOrderChange: vi.fn(),+ }),+ );+ return { onHiddenModelsChange };+ }++ it("omits the bulk control when every model is custom", () => {+ renderSection({ models: [model("custom", true)] });++ expect(mocks.buttons.has("Disable all")).toBe(false);+ expect(mocks.buttons.has("Enable all")).toBe(false);+ });++ it("disables every built-in model from the visible control", () => {+ const { onHiddenModelsChange } = renderSection({+ models: [model("a"), model("b"), model("custom", true)],+ hiddenModels: ["a"],+ });++ expect(mocks.buttons.has("Enable all")).toBe(false);+ mocks.buttons.get("Disable all")?.onClick?.();+ expect(onHiddenModelsChange).toHaveBeenCalledWith(["a", "b"]);+ });++ it("enables built-in models without clearing leftover hidden entries", () => {+ const { onHiddenModelsChange } = renderSection({+ models: [model("a"), model("b"), model("custom", true)],+ hiddenModels: ["a", "b", "legacy", "custom"],+ });++ expect(mocks.buttons.has("Disable all")).toBe(false);+ mocks.buttons.get("Enable all")?.onClick?.();+ expect(onHiddenModelsChange).toHaveBeenCalledWith(["legacy", "custom"]);+ });+});diff --git a/apps/web/src/components/settings/ProviderModelsSection.tsx b/apps/web/src/components/settings/ProviderModelsSection.tsxindex 5ff639a86..56828e936 100644--- a/apps/web/src/components/settings/ProviderModelsSection.tsx+++ b/apps/web/src/components/settings/ProviderModelsSection.tsx@@ -75,6 +75,21 @@ interface ProviderModelsSectionProps {readonly onModelOrderChange: (next: ReadonlyArray<string>) => void;}+export function nextHiddenModelsForBulkToggle(+ models: ReadonlyArray<Pick<ServerProviderModel, "slug" | "isCustom">>,+ hiddenModels: ReadonlyArray<string>,+): string[] {+ const builtInSlugs = models.filter((model) => !model.isCustom).map((model) => model.slug);+ const builtInSlugSet = new Set(builtInSlugs);+ const allBuiltInModelsHidden = builtInSlugs.every((slug) => hiddenModels.includes(slug));++ if (allBuiltInModelsHidden) {+ return hiddenModels.filter((slug) => !builtInSlugSet.has(slug));+ }++ return [...new Set([...hiddenModels, ...builtInSlugs])];+}+/*** Shared "Models" section rendered on both the built-in default and custom* provider-instance cards. Owns its own input + error local state so two@@ -111,6 +126,9 @@ export function ProviderModelsSection({modelOrder,});}, [favoriteModelSet, modelOrder, models]);+ const builtInModels = useMemo(() => models.filter((model) => !model.isCustom), [models]);+ const allBuiltInModelsHidden =+ builtInModels.length > 0 && builtInModels.every((model) => hiddenModelSet.has(model.slug));const handleAdd = () => {const normalized = normalizeCustomModelSlug(input);@@ -188,7 +206,21 @@ export function ProviderModelsSection({return (<div>- <div className="text-xs font-medium text-foreground">Models</div>+ <div className="flex items-center justify-between gap-2">+ <div className="text-xs font-medium text-foreground">Models</div>+ {builtInModels.length > 0 ? (+ <Button+ type="button"+ size="xs"+ variant="ghost-muted"+ onClick={() =>+ onHiddenModelsChange(nextHiddenModelsForBulkToggle(models, hiddenModels))+ }+ >+ {allBuiltInModelsHidden ? "Enable all" : "Disable all"}+ </Button>+ ) : null}+ </div><div className="mt-1 text-xs text-muted-foreground">{models.length} model{models.length === 1 ? "" : "s"} available.</div>