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 apps/web/src/components/machine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function MachineIcon({

/** A quiet selector above the composer: no fill until hovered or open. */
export const headerTrigger =
"group flex h-7 min-w-0 max-w-64 shrink-0 items-center gap-1.5 rounded-md px-2 text-ui text-ink-muted transition-[transform,background-color,color] duration-150 ease-out outline-none hover:bg-selection hover:text-ink focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97] data-[state=open]:bg-selection data-[state=open]:text-ink";
"group flex h-7 min-w-0 max-w-64 shrink-0 items-center gap-1.5 rounded-lg px-2 text-ui text-ink-muted transition-[transform,background-color,color] duration-150 ease-out outline-none hover:bg-selection hover:text-ink focus-visible:ring-2 focus-visible:ring-ring active:scale-[0.97] data-[state=open]:bg-selection data-[state=open]:text-ink";

const panel = "rounded-xl border-ink/10 bg-popover/95 p-0 shadow-(--cw-menu-shadow) backdrop-blur-xl";
const heading =
Expand Down
130 changes: 46 additions & 84 deletions apps/web/src/settings/connectors/directory.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { ConnectorCategory, ConnectorKind, ConnectorSpec } from "@codeworksh/contract";
import { CaretLeftIcon, CaretRightIcon, MagnifyingGlassIcon, PlusIcon, XIcon } from "@phosphor-icons/react";
import { CaretLeftIcon, CaretRightIcon } from "@phosphor-icons/react";
import { type ReactNode, useEffect, useMemo, useRef, useState } from "react";

import { Monogram } from "@/components/monogram";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { BACK_CLASS, Page, quietField } from "../blocks";
import { EmptyState } from "../controls";
import { CollapsiblePanel, InlineConnectPanel } from "./inline";
import { BACK_CLASS, Page } from "../blocks";
import { EmptyState, SearchField } from "../controls";
import { authSummary, CollapsiblePanel, ConnectToggle, InlineConnectPanel } from "./inline";

export type DirectoryDrill =
| { readonly kind: "featured" }
Expand All @@ -17,6 +16,9 @@ export type DirectoryDrill =

const PAGE_SIZE = 24;

/** "No Matching Providers": the plural noun in title case. */
export const noMatchTitle = (noun: string) => `No Matching ${noun.replace(/\b\w/g, (letter) => letter.toUpperCase())}`;

function chunkPairs<T>(items: ReadonlyArray<T>): ReadonlyArray<readonly [T, T | undefined]> {
const pairs: Array<readonly [T, T | undefined]> = [];
for (let i = 0; i < items.length; i += 2) {
Expand All @@ -25,13 +27,6 @@ function chunkPairs<T>(items: ReadonlyArray<T>): ReadonlyArray<readonly [T, T |
return pairs;
}

const authSummary = (spec: ConnectorSpec): string =>
[
...(spec.auth.oauth !== undefined ? ["OAuth"] : []),
...(spec.auth.apikey !== undefined ? ["API Key"] : []),
...(spec.auth.env !== undefined ? ["Env"] : []),
].join(" · ");

function DirectoryMark({ spec }: { readonly spec: ConnectorSpec }) {
return (
<div
Expand Down Expand Up @@ -145,9 +140,11 @@ function TwoColShelfGrid({
</div>
<Button
type="button"
variant={isOpen ? "ghost" : "outline"}
variant="outline"
size="xs"
className="h-7 w-[4.75rem] shrink-0 justify-center rounded-lg text-xs"
aria-label={`${isOpen ? "Close" : "Connect"} ${spec.name}`}
aria-expanded={isOpen}
onClick={() => onToggle(isOpen ? null : key)}
>
{isOpen ? "Close" : "Connect"}
Expand All @@ -157,7 +154,7 @@ function TwoColShelfGrid({
};

return (
<div key={left.id} className="border-b border-edge/50 py-1">
<div key={left.id} data-connector className="border-b border-edge/50 py-1">
<div className="grid grid-cols-1 gap-x-6 gap-y-1 sm:grid-cols-2">
{renderCell(left, leftKey)}
{right !== undefined && rightKey !== null && renderCell(right, rightKey)}
Expand Down Expand Up @@ -312,7 +309,7 @@ export function ConnectorsDirectory({
const key = `${shelf}:${spec.id}`;
const isOpen = expandedKey === key;
return (
<div key={spec.id} className="border-b border-edge/50 py-1">
<div key={spec.id} data-connector className="border-b border-edge/50 py-1">
<div
className={`-mx-2 flex min-h-14 items-center gap-3.5 rounded-lg px-2 py-2 transition-[background-color] duration-150 ease-(--ease-out) ${
isOpen ? "bg-selection-subtle" : "hover:bg-selection-subtle/70"
Expand All @@ -328,28 +325,16 @@ export function ConnectorsDirectory({
</span>
<span className="flex flex-col gap-0.5 text-xs font-book text-ink-muted">
<span className="line-clamp-1 text-pretty">{spec.description}</span>
<span className="text-2xs text-ink-muted/80">{authSummary(spec)}</span>
<span className="text-2xs text-ink-muted/80">
{authSummary(spec, slugsByConnector.get(spec.id)?.size)}
</span>
</span>
</div>
<Button
type="button"
variant={isOpen ? "ghost" : "outline"}
size="sm"
className="w-[5.75rem] shrink-0 justify-center pr-2.5 pl-2"
<ConnectToggle
open={isOpen}
name={spec.name}
onClick={() => setExpandedKey(isOpen ? null : key)}
>
{isOpen ? (
<>
<XIcon size={13} aria-hidden />
<span>Close</span>
</>
) : (
<>
<PlusIcon size={13} aria-hidden />
<span>Connect</span>
</>
)}
</Button>
/>
</div>
<CollapsiblePanel open={isOpen}>
<div className="pt-2 pb-2.5">
Expand Down Expand Up @@ -426,20 +411,12 @@ export function ConnectorsDirectory({
description={`Choose a category to browse its ${noun}.`}
>
<div className="flex flex-col gap-4">
<div className="relative">
<MagnifyingGlassIcon
size={14}
className="pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2 text-ink-muted"
aria-hidden
/>
<Input
type="search"
value={subQuery}
onChange={(e) => setSubQuery(e.target.value)}
placeholder="Filter categories…"
className={`h-8 bg-frame-top pl-8 ${quietField}`}
/>
</div>
<SearchField
value={subQuery}
onChange={setSubQuery}
label="Filter categories"
placeholder="Filter categories…"
/>

{cats.length === 0 ? (
<EmptyState title="No Matching Categories" description={`No categories match “${subQuery}”.`} />
Expand Down Expand Up @@ -482,26 +459,18 @@ export function ConnectorsDirectory({
<div ref={rootRef}>
<DrillPage key={drillKey} backLabel={pageTitle} onBack={closeDrill} title={title} count={filtered.length}>
<div className="flex flex-col gap-4">
<div className="relative">
<MagnifyingGlassIcon
size={14}
className="pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2 text-ink-muted"
aria-hidden
/>
<Input
type="search"
value={subQuery}
onChange={(e) => {
setSubQuery(e.target.value);
setLimit(PAGE_SIZE);
}}
placeholder={`Search ${title.toLowerCase()}…`}
className={`h-8 bg-frame-top pl-8 ${quietField}`}
/>
</div>
<SearchField
value={subQuery}
onChange={(next) => {
setSubQuery(next);
setLimit(PAGE_SIZE);
}}
label={`Search ${title.toLowerCase()}`}
placeholder={`Search ${title.toLowerCase()}…`}
/>

{visible.length === 0 ? (
<EmptyState title="No Matching Connectors" description={`No ${noun} match “${subQuery}”.`} />
<EmptyState title={noMatchTitle(noun)} description={`No ${noun} match “${subQuery}”.`} />
) : (
<>
{renderFullRows(`drill-${drill.kind}`, visible)}
Expand Down Expand Up @@ -531,27 +500,20 @@ export function ConnectorsDirectory({

return (
<div ref={rootRef} className="flex flex-col gap-10">
<div className="relative">
<MagnifyingGlassIcon
size={14}
className="pointer-events-none absolute top-1/2 left-2.5 -translate-y-1/2 text-ink-muted"
aria-hidden
/>
<Input
type="search"
value={globalQuery}
onChange={(e) => {
setGlobalQuery(e.target.value);
setExpandedKey(null);
}}
placeholder={connectors.length > 6 ? `Search all ${connectors.length} ${noun}…` : `Search ${noun}…`}
className={`h-9 bg-frame-top pl-8 ${quietField}`}
/>
</div>
<SearchField
value={globalQuery}
onChange={(next) => {
setGlobalQuery(next);
setExpandedKey(null);
}}
label={`Search ${noun}`}
placeholder={connectors.length > 6 ? `Search all ${connectors.length} ${noun}…` : `Search ${noun}…`}
className="h-9"
/>

{searching ? (
globalResults.length === 0 ? (
<EmptyState title="No Matching Connectors" description={`No ${noun} match “${globalQuery}”.`} />
<EmptyState title={noMatchTitle(noun)} description={`No ${noun} match “${globalQuery}”.`} />
) : (
<div className="flex flex-col gap-3">
<span className="text-xs text-ink-muted">
Expand Down
Loading