The Open Framework for Building Agents
docs: list integrations alphabetically in the gallery (#5179)
Colton Padden06ebcb395a3e
diff --git a/apps/docs/app/[lang]/integrations/components/gallery.tsx b/apps/docs/app/[lang]/integrations/components/gallery.tsxindex acf0fa876..6ac9ae0e5 100644--- a/apps/docs/app/[lang]/integrations/components/gallery.tsx+++ b/apps/docs/app/[lang]/integrations/components/gallery.tsx@@ -11,11 +11,12 @@ import {getQueryLengthBucket,normalizeSearchQuery,} from "@/lib/analytics/events";-import type { Integration, IntegrationType } from "@/lib/integrations/data";+import type { Integration } from "@/lib/integrations/data";+import { filterIntegrations, type GalleryFilter } from "@/lib/integrations/gallery";import { cn } from "@/lib/utils";import { IntegrationCard } from "./integration-card";-export type GalleryFilter = "all" | IntegrationType | "memory";+export type { GalleryFilter };const FILTERS: { value: GalleryFilter; label: string }[] = [{ value: "all", label: "All" },@@ -46,24 +47,10 @@ export const Gallery = ({ filter, integrations }: GalleryProps) => {const [query, setQuery] = useState("");const lastTrackedSearch = useRef("");- const results = useMemo(() => {- const normalized = query.trim().toLowerCase();- return integrations.filter((integration) => {- if (filter === "memory" && !integration.keywords?.includes("memory")) {- return false;- }- if (filter !== "all" && filter !== "memory" && integration.type !== filter) {- return false;- }- if (!normalized) {- return true;- }- const haystack = [integration.name, integration.tagline, ...(integration.keywords ?? [])]- .join(" ")- .toLowerCase();- return haystack.includes(normalized);- });- }, [integrations, filter, query]);+ const results = useMemo(+ () => filterIntegrations(integrations, filter, query),+ [integrations, filter, query],+ );useEffect(() => {const normalizedQuery = normalizeSearchQuery(query);diff --git a/apps/docs/lib/integrations/data.ts b/apps/docs/lib/integrations/data.tsindex c5c1c6a7f..8a4d206ff 100644--- a/apps/docs/lib/integrations/data.ts+++ b/apps/docs/lib/integrations/data.ts@@ -8,6 +8,7 @@ import {instrumentationEntries,memoryEntries,} from "@eve/catalog";+import { compareByName } from "./gallery";import type { LogoKey } from "./logos";/**@@ -2748,23 +2749,28 @@ function buildInstrumentation(entry: IntegrationEntry): Integration {const channels: Integration[] = channelEntries().filter((entry) => entry.surfaces.gallery)- .map(buildChannel);+ .map(buildChannel)+ .sort(compareByName);const connections: Integration[] = connectionEntries().filter((entry) => entry.surfaces.gallery)- .map(buildConnection);+ .map(buildConnection)+ .sort(compareByName);const extensions: Integration[] = extensionEntries().filter((entry) => entry.surfaces.gallery)- .map(buildExtension);+ .map(buildExtension)+ .sort(compareByName);const memory: Integration[] = memoryEntries().filter((entry) => entry.surfaces.gallery)- .map(buildMemory);+ .map(buildMemory)+ .sort(compareByName);const instrumentation: Integration[] = instrumentationEntries().filter((entry) => entry.surfaces.gallery)- .map(buildInstrumentation);+ .map(buildInstrumentation)+ .sort(compareByName);/** Display label for each connection protocol. */export const protocolLabel: Record<ConnectionProtocol, string> = {diff --git a/apps/docs/lib/integrations/gallery.test.ts b/apps/docs/lib/integrations/gallery.test.tsnew file mode 100644index 000000000..0198eec60--- /dev/null+++ b/apps/docs/lib/integrations/gallery.test.ts@@ -0,0 +1,41 @@+import { describe, expect, it } from "vitest";+import { integrations } from "./data";+import { compareByName, filterIntegrations, type GalleryFilter } from "./gallery";++const names = (filter: GalleryFilter, query = "") =>+ filterIntegrations(integrations, filter, query).map(({ name }) => name);++const alphabetical = (list: string[]) =>+ [...list].sort((left, right) => left.localeCompare(right, "en", { sensitivity: "base" }));++describe("integrations gallery order", () => {+ it.each<GalleryFilter>(["channel", "connection", "extension", "memory", "instrumentation"])(+ "lists the %s tab alphabetically",+ (filter) => {+ const list = names(filter);+ expect(list.length).toBeGreaterThan(0);+ expect(list).toEqual(alphabetical(list));+ },+ );++ it("sorts keyword matches from other types into the Memory tab", () => {+ const memory = filterIntegrations(integrations, "memory", "");+ expect(memory.some(({ type }) => type !== "memory")).toBe(true);+ expect(memory).toEqual([...memory].sort(compareByName));+ });++ it("keeps search results alphabetical within a tab", () => {+ const list = names("connection", "mcp");+ expect(list).toEqual(alphabetical(list));+ });++ it("keeps All grouped by type with each group alphabetical", () => {+ const all = filterIntegrations(integrations, "all", "");+ const types = [...new Set(all.map(({ type }) => type))];+ expect(types).toEqual(["channel", "extension", "memory", "connection", "instrumentation"]);+ for (const type of types) {+ const group = all.filter((entry) => entry.type === type).map(({ name }) => name);+ expect(group, type).toEqual(alphabetical(group));+ }+ });+});diff --git a/apps/docs/lib/integrations/gallery.ts b/apps/docs/lib/integrations/gallery.tsnew file mode 100644index 000000000..884fecd78--- /dev/null+++ b/apps/docs/lib/integrations/gallery.ts@@ -0,0 +1,36 @@+import type { Integration, IntegrationType } from "./data";++export type GalleryFilter = "all" | IntegrationType;++/** Orders integrations alphabetically by name, case-insensitively. */+export const compareByName = (left: Integration, right: Integration): number =>+ left.name.localeCompare(right.name, "en", { sensitivity: "base" });++/**+ * Integrations shown for a gallery filter and search query. "All" keeps the+ * type grouping of `integrations`; every other tab is alphabetical, including+ * Memory, which matches by keyword across types.+ */+export const filterIntegrations = (+ integrations: Integration[],+ filter: GalleryFilter,+ query: string,+): Integration[] => {+ const normalized = query.trim().toLowerCase();+ const results = integrations.filter((integration) => {+ if (filter === "memory" && !integration.keywords?.includes("memory")) {+ return false;+ }+ if (filter !== "all" && filter !== "memory" && integration.type !== filter) {+ return false;+ }+ if (!normalized) {+ return true;+ }+ const haystack = [integration.name, integration.tagline, ...(integration.keywords ?? [])]+ .join(" ")+ .toLowerCase();+ return haystack.includes(normalized);+ });+ return filter === "all" ? results : results.sort(compareByName);+};