From 63c2684f7c8970c08d7921f428ade2f6c295cd9c Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 12:45:45 -0800 Subject: [PATCH 01/12] Polish app discovery and connection management --- CHANGELOG.md | 3 + .../components/connections/apps-toolbar.tsx | 91 +++ .../components/plugins/broker-directory.tsx | 536 ++++++++++++------ app/src/lib/apps/discovery.ts | 41 ++ app/src/lib/connections/rows.ts | 3 + .../routes/_authed/_app/connections.index.tsx | 195 +++---- app/tests/browse-apps-pages.test.tsx | 14 +- app/tests/personal-connections.test.tsx | 13 +- ...team-connections-directory-layout.test.tsx | 2 +- app/tests/team-connections-directory.test.tsx | 33 +- app/tests/ui-look-guard.allowlist.json | 1 - 11 files changed, 631 insertions(+), 301 deletions(-) create mode 100644 app/src/components/connections/apps-toolbar.tsx create mode 100644 app/src/lib/apps/discovery.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index a03f3650ad..53767b3856 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. ## Unreleased +- Browse apps opens with popular apps and category shortcuts. Search and Add custom MCP stay + within reach as you scroll through the directory or your connections. + ## 1.2.6 **Before upgrading.** diff --git a/app/src/components/connections/apps-toolbar.tsx b/app/src/components/connections/apps-toolbar.tsx new file mode 100644 index 0000000000..9862fa54e4 --- /dev/null +++ b/app/src/components/connections/apps-toolbar.tsx @@ -0,0 +1,91 @@ +import { Link } from "@tanstack/react-router"; +import type { ReactNode } from "react"; +import { IconPlus, IconSearch } from "@/components/icons"; +import { Button } from "@/components/ui/button"; +import { + InputGroup, + InputGroupAddon, + InputGroupInput, +} from "@/components/ui/input-group"; +import type { PluginsProvider } from "@/lib/plugins/provider-vocabulary"; +import { cn } from "@/lib/utils"; + +export function AppsNavigation({ + provider, + browsing, +}: { + provider: PluginsProvider; + browsing?: boolean; +}) { + const style = (active: boolean) => + cn( + "border-b-2 border-transparent px-1 pb-2 text-sm font-medium text-muted-foreground", + active && "border-foreground text-foreground", + ); + return ( + + ); +} + +export function AppsToolbar({ + search, + onSearch, + mayAdd, + placeholder = "Search apps", + children, +}: { + search: string; + onSearch: (value: string) => void; + mayAdd: boolean; + placeholder?: string; + children?: ReactNode; +}) { + return ( +
+
+ + + + onSearch(event.target.value)} + /> + + {mayAdd && ( + + )} +
+ {children} +
+ ); +} diff --git a/app/src/components/plugins/broker-directory.tsx b/app/src/components/plugins/broker-directory.tsx index 2858ac80b2..a6a71338c7 100644 --- a/app/src/components/plugins/broker-directory.tsx +++ b/app/src/components/plugins/broker-directory.tsx @@ -1,11 +1,16 @@ -import { IconKey, IconPlug, IconSearch } from "@/components/icons"; import { type UseInfiniteQueryResult, useInfiniteQuery, + useQueries, useQuery, } from "@tanstack/react-query"; import { Link, type LinkOptions } from "@tanstack/react-router"; import * as React from "react"; +import { + AppsNavigation, + AppsToolbar, +} from "@/components/connections/apps-toolbar"; +import { IconKey, IconPlug, IconSearch } from "@/components/icons"; import { PageEmpty, PageRows, @@ -33,11 +38,19 @@ import { import { Separator } from "@/components/ui/separator"; import { Skeleton } from "@/components/ui/skeleton"; import { myAppRequestsQueryOptions } from "@/lib/app-access/queries"; +import { + categories, + type DiscoveryCategory, + inDiscoveryCategory, + popularNames, + sameAppName, +} from "@/lib/apps/discovery"; import { appsQueryOptions, type DirectoryApp, type DirectoryAppPage, directoryAppPagesQueryOptions, + directoryAppsQueryOptions, directorySlug, } from "@/lib/apps/queries"; import { currentUserQueryOptions } from "@/lib/auth/queries"; @@ -66,12 +79,8 @@ import { import { connectionsQueryOptions } from "@/lib/plugins/queries"; /** - * The active broker's directory, searched rather than listed. - * - * The catalogue on the previous screen is a reviewed handful, and every entry there is a decision - * somebody made about a vendor. This is a directory nobody here has reviewed, which is why it is a - * search field and not a list: the only sensible entry point into a directory that size is the name - * of the app you already came looking for. + * The active broker's directory. Connections offers curated picks and category shortcuts; + * Admin retains its paged list. Both use the same directory entries and connection actions. * * Adding one is account-wide, and it still reads nothing. Every app here is reached as whoever is * asking, so a person's own connection is what makes their own mail or messages readable. @@ -139,7 +148,50 @@ export function BrokerDirectory({ * (`MoreWhenSeen`). Reading every page before drawing any kept this screen on its placeholders * for a quarter of a minute. */ - const apps = useInfiniteQuery(directoryAppPagesQueryOptions(query)); + const discover = place === "connections"; + const [category, setCategory] = React.useState( + null, + ); + const [all, setAll] = React.useState(false); + const popular = discover && !category && !all && !query.trim(); + const picks = useQueries({ + queries: popularNames.map((name) => ({ + ...directoryAppsQueryOptions(name), + enabled: popular, + staleTime: 5 * 60_000, + })), + }); + const featured = picks.flatMap( + (result, index) => + result.data?.find((app) => sameAppName(app.title, popularNames[index])) ?? + [], + ); + const loadingPicks = popular && picks.some((result) => result.isPending); + const showFeatured = popular && (loadingPicks || featured.length > 0); + // Category membership comes from every matching page, including apps beyond the first fifty. + const categoryApps = useQuery({ + ...directoryAppsQueryOptions(""), + enabled: discover && category !== null, + staleTime: 5 * 60_000, + }); + const apps = useInfiniteQuery({ + ...directoryAppPagesQueryOptions(query), + enabled: !category && !showFeatured, + }); + const toolbar = React.useRef(null); + function choose(next: DiscoveryCategory | null, showAll = false) { + setCategory(next); + setAll(showAll); + setSearch(""); + setQuery(""); + const scroller = toolbar.current?.closest(".overflow-y-auto"); + const results = toolbar.current?.nextElementSibling; + if (scroller && toolbar.current && results && scroller.scrollTop > 0) { + scroller.scrollTop += + results.getBoundingClientRect().top - + toolbar.current.getBoundingClientRect().bottom; + } + } const personal = paths.edition === "personal"; const role = useQuery(currentUserQueryOptions()).data?.role; const open = useAppsOpen(); @@ -169,21 +221,46 @@ export function BrokerDirectory({ const press = useDirectoryPress(mode); const { tab, signingIn } = press; const { waiting } = tab; - /* - * In the order the server answers, which is the order this screen draws (apps you sign in to - * first, then apps that take a key, each by title). Sorting here instead would move rows already - * on screen each time a page arrived. - */ - const listed = apps.data?.pages.flatMap((page) => page.apps) ?? []; + const entries = category + ? (categoryApps.data ?? []).filter( + (entry) => + inDiscoveryCategory(entry, category) && + `${entry.title} ${entry.summary}` + .toLowerCase() + .includes(query.trim().toLowerCase()), + ) + : showFeatured + ? featured + : (apps.data?.pages.flatMap((page) => page.apps) ?? []); + const pending = category + ? categoryApps.isPending + : showFeatured + ? loadingPicks && !featured.length + : apps.isPending; + const failure = category + ? categoryApps.error + : showFeatured + ? null + : apps.data + ? null + : apps.error; /** How many the whole list holds; counted from the rows only once they are all here. */ const total = - apps.data?.pages[0]?.total ?? (apps.hasNextPage ? null : listed.length); + apps.data?.pages[0]?.total ?? (apps.hasNextPage ? null : entries.length); const stateOf = (entry: DirectoryApp) => directoryAppState(entry, { servers: plugins.data, connections: connections.data?.connections, }); + const listed = + discover && !query.trim() + ? [ + ...entries.filter((entry) => entry.appId === null), + ...entries.filter((entry) => entry.appId !== null), + ] + : entries; + const Rows = discover ? "div" : PageRows; /* * WHERE AN ADDED KEY VERSION'S PAGE IS, beside the sign-in it was offered under. Its key form opens * on arrival while this person hasn't connected it, as Connect on a key app's own row does. @@ -226,27 +303,95 @@ export function BrokerDirectory({ return ( - + {discover && ( + <> + +
+ +
+ {categories.map((name) => ( + + ))} +
+
+
+ + )} + + {discover && ( +
+

+ {category ?? + (query + ? "Search results" + : showFeatured + ? "Popular apps" + : "All apps")} +

+ {!showFeatured && ( + + {category + ? `${listed.length} apps` + : total !== null && !pending + ? `${total.toLocaleString()} ${query ? (total === 1 ? "match" : "matches") : "apps"}` + : null} + + )} + +
+ )} {press.error ? (

) : null} - setSearch(event.target.value)} - placeholder="Search by app name" - value={search} - /> + {!discover && ( + setSearch(event.target.value)} + placeholder="Search by app name" + value={search} + /> + )} {/* * Pending, error, empty, rows. Pending draws placeholder rows until the first page comes, @@ -254,7 +399,7 @@ export function BrokerDirectory({ * nothing, so no sentence claims anything mid-fetch. The error is the first page's: a later * page that fails keeps the rows already here and says so under them (`MoreWhenSeen`). */} - {apps.isPending ? ( + {pending ? (
{LOADING_ROWS.map((key, index) => ( @@ -273,7 +418,7 @@ export function BrokerDirectory({ ))}
- ) : apps.data === undefined ? ( + ) : failure ? (

{/* * The server's own sentence, as the enable failure above already does. A keyless @@ -282,18 +427,20 @@ export function BrokerDirectory({ * stays as the fallback for a failure that arrived carrying no message of its own. */} {loadFailure( - apps.error, - apps.error.message || directoryReadFailure(provider), + failure, + failure.message || directoryReadFailure(provider), )}

) : listed.length === 0 ? ( {query ? `No app matches "${query}".` - : "No apps to show yet. Try again in a moment."} + : category + ? `No apps in ${category} here yet.` + : "No apps to show yet. Try again in a moment."} ) : ( <> @@ -301,162 +448,205 @@ export function BrokerDirectory({ * How many there are, before the list: with no search, this is the whole directory, * counted by the server across every page rather than by the rows read so far. */} -

- {query - ? total === null - ? null - : `${total.toLocaleString()} ${total === 1 ? "match" : "matches"}` - : total === null - ? "Search by name to narrow them." - : `${total.toLocaleString()} apps. Search by name to narrow them.`} -

- - {listed.map((entry, index) => { - // One mutation serves every row, so which rows are mid-request is tracked beside it - // rather than read off it (`useDirectoryPress`). - const isAdding = press.adding.has(entry.id); - const slug = directorySlug(entry.id) ?? entry.id; - const state = stateOf(entry); - const mine = signingIn === entry.id; + {!discover && ( +

+ {query + ? total === null + ? null + : `${total.toLocaleString()} ${total === 1 ? "match" : "matches"}` + : total === null + ? "Search by name to narrow them." + : `${total.toLocaleString()} apps. Search by name to narrow them.`} +

+ )} +
+ + {listed.map((entry, index) => { + // One mutation serves every row, so which rows are mid-request is tracked beside it + // rather than read off it (`useDirectoryPress`). + const isAdding = press.adding.has(entry.id); + const slug = directorySlug(entry.id) ?? entry.id; + const state = stateOf(entry); + const mine = signingIn === entry.id; - return ( - - {/* The test id names the screen, not the vendor: this module draws whichever + return ( + + {/* The test id names the screen, not the vendor: this module draws whichever broker is active, and the id is not user-visible. */} - - {/* The vendor's own mark where the broker supplies one, and its initial where it - does not, so a list of third parties still has a fixed left edge. */} - - {entry.logo ? ( - - ) : ( - - )} - - - {entry.title} - {entry.summary} - - {entry.appId !== null ? null : ( - - )} - {entry.appId !== null ? null : ( - - )} - {entry.keyVersion ? ( - press.pressKey(entry)} - pending={press.addingKey.has(entry.id)} - /> - ) : null} - {mine ? ( - - ) : null} - - - {/* The size of the decision, stated before it is made: an app is not one + {/* The vendor's own mark where the broker supplies one, and its initial where it + does not, so a list of third parties still has a fixed left edge. */} + + {entry.logo ? ( + + ) : ( + + )} + + + + {entry.title} + + + {entry.summary} + + + {entry.appId !== null ? null : ( + + )} + {entry.appId !== null ? null : ( + + )} + {entry.keyVersion ? ( + press.pressKey(entry)} + pending={press.addingKey.has(entry.id)} + /> + ) : null} + {mine ? ( + + ) : null} + + + {/* The size of the decision, stated before it is made: an app is not one tool, and "167 actions" is what says so. */} - - {entry.actionCount} actions - - {/* - * An app this deployment already has says where it stands rather than - * offering to add it again. A second add would ask the server to record an - * app it already holds, and there is nothing on the row to suggest that - * would be harmless. - */} - {state.kind === "addable" && mode === "request" ? ( - requested.has(slug) ? ( - sent ? ( - - Requested - {sent} - + + {entry.actionCount} actions + + {/* + * An app this deployment already has says where it stands rather than + * offering to add it again. A second add would ask the server to record an + * app it already holds, and there is nothing on the row to suggest that + * would be harmless. + */} + {state.kind === "addable" && mode === "request" ? ( + requested.has(slug) ? ( + sent ? ( + + Requested + {sent} + + ) : ( + + Requested + + ) ) : ( - - Requested - + ) - ) : ( + ) : state.kind === "addable" ? ( + /* + * Connect, never Add: the press adds the app and goes straight on to this + * person's own sign-in or key form (`useDirectoryPress`). + */ - ) - ) : state.kind === "addable" ? ( - /* - * Connect, never Add: the press adds the app and goes straight on to this - * person's own sign-in or key form (`useDirectoryPress`). - */ - - ) : ( - press.connect(entry.id, state.serverId) - : undefined - } - opening={mine && tab.pending} - personal={ownPages} - state={state} - waiting={mine && waiting} - /> - )} - - - {index !== listed.length - 1 && } - - ); - })} - - + ) : ( + + press.connect(entry.id, state.serverId) + : undefined + } + opening={mine && tab.pending} + personal={ownPages} + state={state} + waiting={mine && waiting} + /> + )} + + + {!discover && index !== listed.length - 1 && ( + + )} + + ); + })} + +
+ {!category && !showFeatured && ( + + )} )} + {discover && ( +

+ {personal + ? "OpenBot hasn’t reviewed these apps." + : "Nobody in your organization has reviewed these apps."} +

+ )}
{/* OpenBot's step before a sign-in, in OpenBot Desktop's window. */} {tab.consentStep} diff --git a/app/src/lib/apps/discovery.ts b/app/src/lib/apps/discovery.ts new file mode 100644 index 0000000000..41649d0ad7 --- /dev/null +++ b/app/src/lib/apps/discovery.ts @@ -0,0 +1,41 @@ +import type { DirectoryApp } from "./queries"; + +/** Curated shortcuts are resolved against the deployment's own directory. */ +export const popularNames = [ + "Slack", + "Google Drive", + "Gmail", + "Notion", + "GitHub", + "Linear", +] as const; +export const categories = [ + "Communication", + "Files & docs", + "Meetings", + "Developer tools", +] as const; +export type DiscoveryCategory = (typeof categories)[number]; +const matchesCategory: Record = { + Communication: + /communicat|messaging|email|chat|collaboration|slack|discord|outlook|gmail/i, + "Files & docs": + /document|file|storage|knowledge|notion|dropbox|google drive|google docs/i, + Meetings: + /meeting|conferenc|schedul|calendar|transcription|granola|fireflies|zoom|calendly|fathom/i, + "Developer tools": + /develop|engineering|source control|code hosting|software development|github|gitlab|bitbucket|linear|sentry|vercel/i, +}; +export function inDiscoveryCategory( + app: DirectoryApp, + category: DiscoveryCategory, +) { + return matchesCategory[category].test( + [app.title, ...app.categories].join(" "), + ); +} +export function sameAppName(left: string, right: string) { + const normalize = (name: string) => + name.toLowerCase().replace(/[^a-z0-9]/g, ""); + return normalize(left) === normalize(right); +} diff --git a/app/src/lib/connections/rows.ts b/app/src/lib/connections/rows.ts index 246eb72ee9..3b4ff2ff2c 100644 --- a/app/src/lib/connections/rows.ts +++ b/app/src/lib/connections/rows.ts @@ -28,6 +28,8 @@ export type ConnectionRow = { key: string; title: string; summary: string; + /** The directory app whose default account can identify this connected tile. */ + accountAppId?: string; state: ConnectionState; /** * What pressing a tile that is not in use does, in the personal edition, where every app is a @@ -155,6 +157,7 @@ export function connectionRows(input: { .map( (server): ConnectionRow => ({ key: server.id, + accountAppId: server.id, title: server.title, // No line rather than "Connect your Todoist account.", which only repeated the tile's // Connect button. A key app not yet connected says it needs a key, so nobody who diff --git a/app/src/routes/_authed/_app/connections.index.tsx b/app/src/routes/_authed/_app/connections.index.tsx index aa0c4327d5..3b94894afa 100644 --- a/app/src/routes/_authed/_app/connections.index.tsx +++ b/app/src/routes/_authed/_app/connections.index.tsx @@ -1,22 +1,20 @@ +import { useQuery } from "@tanstack/react-query"; +import { createFileRoute, Link } from "@tanstack/react-router"; +import * as React from "react"; +import { useElementVisible } from "@/components/computer/preview-visibility"; +import { + AppsNavigation, + AppsToolbar, +} from "@/components/connections/apps-toolbar"; import { - IconApps, IconBrandGoogleDrive, IconBrandNotion, IconCheck, IconChevronRight, IconLock, IconPlug, - IconPlus, IconSearch, } from "@/components/icons"; -import { useQuery } from "@tanstack/react-query"; -import { - createFileRoute, - Link, - type LinkOptions, - linkOptions, -} from "@tanstack/react-router"; -import * as React from "react"; import { PageEmpty, PageRows, @@ -38,11 +36,7 @@ import { visibleLinkedNotice, } from "@/components/settings/linked-notice"; import { Button } from "@/components/ui/button"; -import { - InputGroup, - InputGroupAddon, - InputGroupInput, -} from "@/components/ui/input-group"; + import { Item, ItemActions, @@ -97,11 +91,12 @@ import { moreAppsRow, } from "@/lib/plugins/provider-vocabulary"; import { + brokeredAccountsQueryOptions, connectionsQueryOptions, personalConnections, } from "@/lib/plugins/queries"; -import { searchTextEntry } from "@/lib/search-text"; import { loadFirstScreen } from "@/lib/route-data"; +import { searchTextEntry } from "@/lib/search-text"; /** * The services a Bot reads as you. @@ -451,7 +446,7 @@ function RouteComponent() { const mayAddServer = mayAdd; const connectApp = useConnectApp(); const paths = useManagePaths(); - // The broker's directory of more apps, as one more tile, where a broker is set up. + // Only installations with a directory get the Browse apps tab. const provider = directoryProvider(setup.data); const directoryAvailable = setup.data?.directoryAvailable ?? false; const moreApps = moreAppsRow(provider, directoryAvailable, "personal"); @@ -460,19 +455,7 @@ function RouteComponent() { * copy: a member can't open Admin, and an admin opening it there adds an app for everybody without * connecting their own account. */ - const browse = - edition !== undefined && moreApps.linked - ? { - title: moreApps.title, - description: mayAdd - ? moreApps.description - : "Find more apps and ask an admin for them.", - } - : null; - const browseLink = - provider === "arcade" - ? linkOptions({ to: "/connections/browse/arcade" }) - : linkOptions({ to: "/connections/browse/composio" }); + const browse = edition !== undefined && moreApps.linked; const authorizationNotice = authorizationNoticeFor( arrival.authorized, paths.edition, @@ -524,13 +507,19 @@ function RouteComponent() { links: links.data ?? [], providers: providers.data, }); - const matching = rows.filter((row) => - `${row.title} ${row.summary}`.toLocaleLowerCase().includes(query), - ); + const matching = rows + .filter((row) => + `${row.title} ${row.summary}`.toLocaleLowerCase().includes(query), + ) + .sort( + (a, b) => + Number(b.state === "needs_reconnect") - + Number(a.state === "needs_reconnect") || + a.title.localeCompare(b.title), + ); /* * The personal edition answers two questions, one section each: what your Bots use, and what you - * can add. Every app you could add is in the second, the ones that need a key included, and the - * broker's directory is its last tile. + * can add. Every app you could add is in the second, including apps that need a key. */ const yourApps = matching.filter((row) => row.state !== "available"); /* @@ -614,7 +603,7 @@ function RouteComponent() { !loading && !appsError && !connections.error && - (rows.length > 0 || teamToAdd.length > 0 || browse !== null); + (rows.length > 0 || teamToAdd.length > 0 || browse); /* * A search that matches nothing, here or in the directory, says so once, with no section or * directory tile under it. @@ -631,22 +620,6 @@ function RouteComponent() { return ( } - size="sm" - variant="outline" - > - - Add custom MCP - - ) : undefined - } className="@container" description={ personal @@ -655,6 +628,8 @@ function RouteComponent() { } title="Apps" > + {browse && } + {/* * For `?connected=` only the failure is worth saying. A success needs no sentence: the row it * came back to now reads "Connected", which is the same news told by the thing it is news @@ -707,13 +682,7 @@ function RouteComponent() { /> {/* What a move to OpenBot Cloud left to connect again, and the way to the list of it. */} - {/* - * The first section has no heading of its own: in the team edition it is the page's one list, - * and "Your connections" under the page's own title said the same thing twice. It holds the search, - * which filters every section under it. In the personal edition Your apps and Connect an app - * follow as sections of their own. - */} - + {/* * BOTH APP READS DECIDE THIS. Apps that loaded (listApps, the catalogue, getAppSetup) beside a * listConnections that failed would leave the `connected` set empty and every row @@ -788,27 +757,24 @@ function RouteComponent() { ) : ( <> - - - - setSearch(event.target.value)} - /> - {nothingMatches ? ( Nothing matches “{search.trim()}”. ) : personal || matching.length === 0 ? null : ( - + <> +
+

Your connections

+ + {matching.length} {matching.length === 1 ? "app" : "apps"} + +
+ + )} {searchesDirectory && directory.error ? (

@@ -847,20 +813,18 @@ function RouteComponent() { ) : null} {/* * Connect an app, in both editions: the apps you could add (the personal edition's catalogue), the - * directory's matches for a search, and Browse apps last. In the team edition an admin's press + * directory's matches for a search. In the team edition an admin's press * adds and connects, and so does everybody's with apps open; locked down, a member's asks an * admin. */} - {showingApps && (toAdd.length + found.length > 0 || browse) ? ( + {showingApps && toAdd.length + found.length > 0 ? ( - {browse ? : null} - + /> ) : null} {/* OpenBot's step before a sign-in, in OpenBot Desktop's window. */} @@ -897,14 +861,13 @@ function RouteComponent() { * Tiles two across, where every other list is one `PageRows` card of divided rows. The accepted * exception: connections are apps you pick out by their mark, so they are laid out as tiles rather * than read down as a list. In the personal edition, pressing a tile that is not in use connects or - * adds it. `children` go after the tiles. + * adds it. */ function ConnectionGrid({ rows, connectApp, press, directory = [], - children, }: { rows: ConnectionRow[]; connectApp: ReturnType; @@ -912,7 +875,6 @@ function ConnectionGrid({ press: DirectoryPress; /** The directory entries those tiles stand for. */ directory?: readonly DirectoryApp[]; - children?: React.ReactNode; }) { /* * RECONNECT IS ONE PRESS: the app's page opens with its connect started (the sign-in, or the key @@ -965,7 +927,6 @@ function ConnectionGrid({ /> ); })} - {children} ); } @@ -1034,32 +995,33 @@ function ConnectionsLoading() { ); } -/** The broker's directory of more apps, as the last tile of Connect an app. */ -function BrowseTile({ - browse, - link, +/** Fetch account identity only for visible connected tiles. The app summary remains the fallback. */ +function ConnectedAccountSummary({ + appId, + fallback, }: { - browse: { title: string; description: string }; - link: LinkOptions; + appId: string; + fallback: string; }) { + const [ref, visible] = useElementVisible(); + const accounts = useQuery({ + ...brokeredAccountsQueryOptions(appId), + enabled: visible, + staleTime: 5 * 60_000, + retry: false, + }); + const account = + accounts.data?.accounts.find((item) => item.isDefault) ?? + accounts.data?.accounts[0]; + const summary = account?.identity || account?.label || fallback; return ( - } - size="sm" - variant="outline" + - - - - - {browse.title} - - {browse.description} - - - + {summary} + ); } @@ -1078,7 +1040,7 @@ function ConnectionItem({ }) { return ( - {row.title} - {row.summary ? ( + + {row.title} + + {row.accountAppId && row.state === "connected" ? ( + + ) : row.summary ? ( ) : null} - + + {row.state === "needs_reconnect" && ( + Sign in again + )} + {!onPress && !row.requested && ( + + )} ); diff --git a/app/tests/browse-apps-pages.test.tsx b/app/tests/browse-apps-pages.test.tsx index 5ff88bdd35..b0d7cecffc 100644 --- a/app/tests/browse-apps-pages.test.tsx +++ b/app/tests/browse-apps-pages.test.tsx @@ -240,13 +240,13 @@ describe.skipIf(!asked)("Browse apps, a page at a time", () => { await first.waitFor({ timeout: 15_000 }); const shownAfter = Date.now() - started; // One request, one page, and the count of the whole directory. - expect(await reads(page)).toEqual(["?source=directory&limit=50"]); + expect( + (await reads(page)).filter((query) => !query.includes("search=")), + ).toEqual(["?source=directory&limit=50"]); expect(shownAfter).toBeLessThan(FIRST_PAGE_MS); expect((await rows(page)).length).toBe(50); await page - .getByText( - `${APPS.toLocaleString("en-US")} apps. Search by name to narrow them.`, - ) + .getByText(`${APPS.toLocaleString("en-US")} apps`) .waitFor(); expect(await sideways(page)).toBe(false); await shoot(page, "first-page", name); @@ -267,7 +267,9 @@ describe.skipIf(!asked)("Browse apps, a page at a time", () => { undefined, { timeout: 15_000 }, ); - const read = await reads(page); + const read = (await reads(page)).filter( + (query) => !query.includes("search="), + ); expect(read.length).toBeGreaterThanOrEqual(2); expect(read[1]).toMatch(/^\?source=directory&limit=50&cursor=/); const twoPages = await rows(page); @@ -295,7 +297,7 @@ describe.skipIf(!asked)("Browse apps, a page at a time", () => { // App 1000 to App 1799, less the eighty that take a key, on the first page; all 800 counted. await page.getByText("800 matches").waitFor(); const searched = (await reads(page)).filter((query) => - query.includes("search="), + query.includes("limit=50&search="), ); expect(searched).toEqual([ "?source=directory&limit=50&search=app+1", diff --git a/app/tests/personal-connections.test.tsx b/app/tests/personal-connections.test.tsx index 7b80cc6796..67a40b69de 100644 --- a/app/tests/personal-connections.test.tsx +++ b/app/tests/personal-connections.test.tsx @@ -33,13 +33,13 @@ import { seedAppReads, type TodayServer, } from "./apps-api"; -import { settleReactWork } from "./settle-react-work"; import { connectionPage, MY_CONNECTIONS_PATH, myConnectionPath, startResponse, } from "./connections-api"; +import { settleReactWork } from "./settle-react-work"; beforeAll(() => GlobalRegistrator.register()); afterEach(cleanup); @@ -400,7 +400,7 @@ describe("Connections in the personal edition", () => { }); }); -test("with a broker set up, the last tile browses its directory of more apps", async () => { +test("with a broker set up, the navigation opens its directory of more apps", async () => { composio = true; const { view } = draw("personal"); const browse = await view.findByTestId("account-browse"); @@ -425,13 +425,10 @@ test("Your apps and Connect an app are sections of the page itself, spaced as ev expect(section.parentElement?.closest("section")).toBeNull(); expect(section.className.split(/\s+/)).toEqual(["mt-12"]); } - // The search is at the top of the page's first section, above them both. const search = view.getByRole("textbox", { name: "Search apps" }); - const first = sectionOf(search); - expect(first.parentElement?.closest("section")).toBeNull(); - expect(first.parentElement?.querySelector("section")).toBe(first); + expect(search.closest(".sticky")).toBeTruthy(); expect( - first.compareDocumentPosition(yours) & Node.DOCUMENT_POSITION_FOLLOWING, + search.compareDocumentPosition(yours) & Node.DOCUMENT_POSITION_FOLLOWING, ).toBeTruthy(); }); @@ -446,7 +443,7 @@ test("a search that matches nothing says No matches, with no sections and no dir expect( view.container.querySelector(".icon-search:not([aria-hidden])"), ).not.toBeNull(); - expect(view.queryByTestId("account-browse")).toBeNull(); + expect(view.getByTestId("account-browse")).toBeTruthy(); expect(view.queryByRole("heading", { name: "Your apps" })).toBeNull(); expect(view.queryByRole("heading", { name: "Connect an app" })).toBeNull(); diff --git a/app/tests/team-connections-directory-layout.test.tsx b/app/tests/team-connections-directory-layout.test.tsx index 246b2ac1c8..11c9929baf 100644 --- a/app/tests/team-connections-directory-layout.test.tsx +++ b/app/tests/team-connections-directory-layout.test.tsx @@ -420,7 +420,7 @@ describe.skipIf(!asked)("Connections on OpenBot Cloud", () => { try { const browse = page.getByTestId("account-browse"); await browse.waitFor({ timeout: 15_000 }); - expect(await browse.innerText()).toContain("ask an admin"); + expect(await browse.innerText()).toContain("Browse apps"); await search(page, "linear"); const linear = page.getByTestId("directory-linear"); await linear.waitFor({ timeout: 15_000 }); diff --git a/app/tests/team-connections-directory.test.tsx b/app/tests/team-connections-directory.test.tsx index 1e6c017512..67d40e910d 100644 --- a/app/tests/team-connections-directory.test.tsx +++ b/app/tests/team-connections-directory.test.tsx @@ -131,6 +131,7 @@ const CATALOGUE: TodayCatalogueItem[] = [ let servers: TodayServer[] = []; let connected: string[] = []; +let directoryPageSize: number | undefined; let requests: AppAccessRequest[] = []; const writes: string[] = []; /** Every directory read, with its search, so a test can see nothing read the whole directory. */ @@ -145,6 +146,7 @@ const originalFetch = global.fetch; beforeEach(() => { servers = [added("notion")]; connected = ["composio-notion"]; + directoryPageSize = undefined; requests = []; writes.length = 0; directoryReads.length = 0; @@ -215,6 +217,7 @@ beforeEach(() => { servers, catalogue: CATALOGUE, directory: DIRECTORY, + pageSize: directoryPageSize, composioConfigured: true, provider: "composio", botsMayCallBack: true, @@ -378,11 +381,37 @@ describe("team-edition Connections search finds an app not yet added", () => { const drawn = draw("admin"); await search(drawn, "zzz-nothing"); await drawn.view.findByText("No matches", undefined, { timeout: 3_000 }); - expect(drawn.view.queryByTestId("account-browse")).toBeNull(); + expect(drawn.view.getByTestId("account-browse")).toBeTruthy(); }); }); describe("Browse apps on the team edition's Connections", () => { + test("discovery puts new apps first and searches a category across page boundaries", async () => { + directoryPageSize = 1; + const { view, user } = draw("admin", "/connections/browse/composio"); + await view.findByTestId("directory-notion"); + await view.findByTestId("directory-slack"); + await waitFor(() => + expect( + view.container + .querySelector("[data-testid^='directory-']") + ?.getAttribute("data-testid"), + ).toBe("directory-slack"), + ); + await user.click(view.getByRole("button", { name: "Communication" })); + await view.findByTestId("directory-slack"); + await waitFor(() => + expect(view.queryByTestId("directory-notion")).toBeNull(), + ); + await user.type( + view.getByRole("textbox", { name: "Search apps" }), + "notion", + ); + await view.findByText("No matches"); + await user.click(view.getByRole("button", { name: "Files & docs" })); + await view.findByTestId("directory-notion"); + expect(view.queryByTestId("directory-slack")).toBeNull(); + }); test("is there for an admin, and opens Browse apps under Connections, where one Connect adds and connects", async () => { const drawn = draw("admin"); const browse = await drawn.view.findByTestId("account-browse"); @@ -406,7 +435,7 @@ describe("Browse apps on the team edition's Connections", () => { test("apps locked down: is there for a member, says they ask an admin, and Request asks with no Bot", async () => { const drawn = draw("member"); const browse = await drawn.view.findByTestId("account-browse"); - expect(browse.textContent).toContain("ask an admin"); + expect(browse.textContent).toContain("Browse apps"); await drawn.user.click(browse); await drawn.view.findByRole("heading", { name: "Browse apps" }); const row = await drawn.view.findByTestId("directory-slack"); diff --git a/app/tests/ui-look-guard.allowlist.json b/app/tests/ui-look-guard.allowlist.json index 6c1a98f711..32594bdf44 100644 --- a/app/tests/ui-look-guard.allowlist.json +++ b/app/tests/ui-look-guard.allowlist.json @@ -259,7 +259,6 @@ "shadowStep": 1 }, "routes/_authed/_app/connections.index.tsx": { - "darkColor": 1, "card": 1 }, "routes/_authed/admin/components/$name.tsx": { From 4f3de432c4b389dedd0dedc581e23590f7e58640 Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 12:52:45 -0800 Subject: [PATCH 02/12] Exercise the full directory when connecting PostHog with a key --- app/tests/key-version.test.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/tests/key-version.test.tsx b/app/tests/key-version.test.tsx index 60409b1c24..b1979c2dfb 100644 --- a/app/tests/key-version.test.tsx +++ b/app/tests/key-version.test.tsx @@ -301,6 +301,9 @@ describe("Browse apps, for somebody who connects as they add", () => { directory = [posthog(null), linear]; const { view, user, history } = browse("personal", "connections"); + await user.click( + await view.findByRole("button", { name: "Browse all apps" }), + ); const row = await view.findByTestId("directory-posthog"); // The sign-in is still the row's own action, and its count is the sign-in's. expect( From 81b99432cc3db94e4f2c9ac28d9d9ffb02a710ef Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 14:04:03 -0800 Subject: [PATCH 03/12] Page category searches and keep app cards stable while scrolling --- .../components/connections/apps-toolbar.tsx | 5 +- .../components/plugins/broker-directory.tsx | 107 +++++++----------- app/src/lib/apps/discovery.ts | 25 +--- app/src/lib/apps/queries.ts | 62 ++++++---- app/src/lib/connections/rows.ts | 3 - .../routes/_authed/_app/connections.index.tsx | 49 +------- app/tests/browse-apps-pages.fixture.tsx | 3 +- app/tests/browse-apps-pages.test.tsx | 50 ++++++-- app/tests/team-connections-directory.test.tsx | 18 ++- 9 files changed, 153 insertions(+), 169 deletions(-) diff --git a/app/src/components/connections/apps-toolbar.tsx b/app/src/components/connections/apps-toolbar.tsx index 9862fa54e4..0a5f0accb9 100644 --- a/app/src/components/connections/apps-toolbar.tsx +++ b/app/src/components/connections/apps-toolbar.tsx @@ -23,10 +23,7 @@ export function AppsNavigation({ active && "border-foreground text-foreground", ); return ( -