Skip to content
Open
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
77 changes: 77 additions & 0 deletions src/routes/Dashboard/DashboardComponentsV2View.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ import {
type SourceFilterOption,
} from "./DashboardComponentsV2SourceFilter";
import {
buildComponentCollectionMatches,
createRegisteredLibrariesFingerprint,
DashboardComponentsV2View,
} from "./DashboardComponentsV2View";
Expand Down Expand Up @@ -406,6 +407,53 @@ describe("SourceFilterBar", () => {
});
});

describe("buildComponentCollectionMatches", () => {
it("returns registered library collections matching the query", () => {
const result = buildComponentCollectionMatches(
[
createIndexEntry("standard-component", {
kind: "standard",
label: "Standard",
id: "standard",
}),
createIndexEntry("load-csv", {
kind: "registered",
label: "Data tools",
id: "data-tools",
}),
createIndexEntry("clean-data", {
kind: "registered",
label: "Data tools",
id: "data-tools",
}),
],
"data",
);

expect(result).toEqual([
{
id: "data-tools",
label: "Data tools",
count: 2,
previewNames: ["load-csv", "clean-data"],
},
]);
});

it("returns no collections for empty or unmatched queries", () => {
const index = [
createIndexEntry("load-csv", {
kind: "registered",
label: "Data tools",
id: "data-tools",
}),
];

expect(buildComponentCollectionMatches(index, "")).toEqual([]);
expect(buildComponentCollectionMatches(index, "training")).toEqual([]);
});
});

describe("DashboardComponentsV2View", () => {
beforeEach(() => {
routeMocks.aiDescriptionsEnabled = false;
Expand Down Expand Up @@ -452,6 +500,35 @@ describe("DashboardComponentsV2View", () => {
});
});

it("shows registered library collection results when the query matches", async () => {
render(<DashboardComponentsV2View />);

fireEvent.change(screen.getByLabelText("Search components"), {
target: { value: "github" },
});

await waitFor(() => {
expect(screen.getByText("GitHub library")).toBeInTheDocument();
});
});

it("hides collection results from disabled sources", async () => {
render(<DashboardComponentsV2View />);

fireEvent.click(
screen.getByRole("button", {
name: "Registered libraries source (1 component)",
}),
);
fireEvent.change(screen.getByLabelText("Search components"), {
target: { value: "github" },
});

await waitFor(() => {
expect(screen.queryByText("GitHub library")).not.toBeInTheDocument();
});
});

it("initializes search state from URL params", () => {
routeMocks.search = {
q: "registered",
Expand Down
85 changes: 83 additions & 2 deletions src/routes/Dashboard/DashboardComponentsV2View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,45 @@ type ComponentLibraryFolder = Parameters<typeof flattenFolders>[0];
type UserFolder = { components?: ComponentReference[] };
type RerankMode = "smart" | "deep";

interface ComponentCollectionMatch {
id: string;
label: string;
count: number;
previewNames: string[];
}

export function buildComponentCollectionMatches(
Comment thread
Mbeaulne marked this conversation as resolved.
index: IndexEntry[],
query: string,
): ComponentCollectionMatch[] {
const trimmedQuery = query.trim().toLowerCase();
if (!trimmedQuery) return [];

const bySourceId = new Map<string, ComponentCollectionMatch>();
for (const entry of index) {
if (entry.source.kind !== "registered") continue;
const current = bySourceId.get(entry.source.id);
if (current) {
current.count += 1;
if (current.previewNames.length < 3)
current.previewNames.push(entry.name);
} else {
bySourceId.set(entry.source.id, {
id: entry.source.id,
label: entry.source.label,
count: 1,
previewNames: [entry.name],
});
}
}

return Array.from(bySourceId.values())
.filter((collection) =>
collection.label.toLowerCase().includes(trimmedQuery),
)
.sort((a, b) => a.label.localeCompare(b.label));
}

interface ComponentCardProps {
reference: ComponentReference;
source?: ComponentSearchSource;
Expand Down Expand Up @@ -316,6 +355,29 @@ const ComponentCard = ({
);
};

interface CollectionCardProps {
collection: ComponentCollectionMatch;
}

const CollectionCard = ({ collection }: CollectionCardProps) => (
<BlockStack gap="2" className={PANEL_CLASS}>
Comment thread
Mbeaulne marked this conversation as resolved.
<InlineStack gap="2" blockAlign="center" wrap="wrap">
<Icon name="Library" size="sm" className="text-violet-500" />
<Text size="sm" weight="semibold">
{collection.label}
</Text>
<Badge variant="secondary">
{collection.count} component{collection.count === 1 ? "" : "s"}
</Badge>
</InlineStack>
{collection.previewNames.length > 0 && (
<Paragraph size="xs" tone="subdued">
Includes {collection.previewNames.join(", ")}
</Paragraph>
)}
</BlockStack>
);

interface ComponentDescriptionPanelProps {
prefilledDescription?: string;
generatedDescription?: string;
Expand Down Expand Up @@ -820,6 +882,11 @@ export const DashboardComponentsV2View = () => {
0,
LEXICAL_RESULT_LIMIT,
);
const collectionMatches = buildComponentCollectionMatches(
filteredIndex,
deferredQuery,
);

const aiCandidateMatches: LexicalMatch[] = (() => {
if (trimmedQuery.length === 0) return [];
return broadLexicalMatches;
Expand Down Expand Up @@ -1147,7 +1214,11 @@ export const DashboardComponentsV2View = () => {
</BlockStack>
);
}
if (lexicalMatches.length === 0 && !rerankActive) {
if (
lexicalMatches.length === 0 &&
collectionMatches.length === 0 &&
!rerankActive
) {
return (
<Paragraph size="sm" tone="subdued">
No components matched “{trimmedQuery}”. Try different terms or check
Expand All @@ -1157,11 +1228,21 @@ export const DashboardComponentsV2View = () => {
}
return (
<BlockStack gap="2" align="stretch">
{collectionMatches.length > 0 && (
<BlockStack gap="2" align="stretch">
<Paragraph size="xs" tone="subdued">
Collection{collectionMatches.length === 1 ? "" : "s"}
</Paragraph>
{collectionMatches.map((collection) => (
<CollectionCard key={collection.id} collection={collection} />
))}
</BlockStack>
)}
<InlineStack align="space-between" blockAlign="center" gap="2">
<Paragraph size="xs" tone="subdued">
{rerankActive
? `AI-ranked ${displayedResults.length} result${displayedResults.length === 1 ? "" : "s"} for “${trimmedQuery}”`
: `${displayedResults.length} result${displayedResults.length === 1 ? "" : "s"} for “${trimmedQuery}”`}
: `${displayedResults.length} component result${displayedResults.length === 1 ? "" : "s"} for “${trimmedQuery}”`}
</Paragraph>
{rerankActive && (
<Button
Expand Down
Loading