Skip to content

Commit 8eec97a

Browse files
component details matched tags showing correctly
1 parent c067235 commit 8eec97a

File tree

5 files changed

+92
-69
lines changed

5 files changed

+92
-69
lines changed

webview-ui/src/components/package-manager/PackageManagerViewStateManager.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,26 +260,30 @@ export class PackageManagerViewStateManager {
260260
}
261261

262262
case "UPDATE_FILTERS": {
263-
const { filters } = transition.payload as TransitionPayloads["UPDATE_FILTERS"]
263+
const { filters = {} } = (transition.payload as TransitionPayloads["UPDATE_FILTERS"]) || {}
264264
console.log("=== UPDATE_FILTERS Started ===", {
265265
currentFilters: this.state.filters,
266266
newFilters: filters,
267267
})
268268

269+
// Create new filters object, preserving existing filters unless explicitly changed
270+
const updatedFilters = {
271+
type: filters.type ?? this.state.filters.type,
272+
search: filters.search ?? this.state.filters.search,
273+
tags: filters.tags ?? this.state.filters.tags,
274+
}
275+
269276
// Update state with new filters
270277
this.state = {
271278
...this.state,
272-
filters: {
273-
...this.state.filters,
274-
...filters,
275-
},
279+
filters: updatedFilters,
276280
}
277281
this.notifyStateChange()
278282

279283
// Send filter request immediately
280284
vscode.postMessage({
281285
type: "filterPackageManagerItems",
282-
filters: this.state.filters,
286+
filters: updatedFilters,
283287
} as WebviewMessage)
284288

285289
console.log("=== UPDATE_FILTERS Finished ===")

webview-ui/src/components/package-manager/__tests__/PackageManagerViewStateManager.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,52 @@ describe("PackageManagerViewStateManager", () => {
445445
},
446446
})
447447
})
448+
449+
it("should maintain filter criteria when search is cleared", async () => {
450+
// Reset mock before test
451+
;(vscode.postMessage as jest.Mock).mockClear()
452+
453+
// First set a type filter
454+
await manager.transition({
455+
type: "UPDATE_FILTERS",
456+
payload: {
457+
filters: { type: "mode" },
458+
},
459+
})
460+
461+
// Then add a search term
462+
await manager.transition({
463+
type: "UPDATE_FILTERS",
464+
payload: {
465+
filters: { search: "test" },
466+
},
467+
})
468+
469+
// Clear the search term
470+
await manager.transition({
471+
type: "UPDATE_FILTERS",
472+
payload: {
473+
filters: { search: "" },
474+
},
475+
})
476+
477+
// Should maintain type filter when search is cleared
478+
expect(vscode.postMessage).toHaveBeenLastCalledWith({
479+
type: "filterPackageManagerItems",
480+
filters: {
481+
type: "mode",
482+
search: "",
483+
tags: [],
484+
},
485+
})
486+
487+
const state = manager.getState()
488+
expect(state.filters).toEqual({
489+
type: "mode",
490+
search: "",
491+
tags: [],
492+
})
493+
})
448494
})
449495

450496
describe("Message Handling", () => {

webview-ui/src/components/package-manager/components/PackageManagerItemCard.tsx

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -163,39 +163,14 @@ export const PackageManagerItemCard: React.FC<PackageManagerItemCardProps> = ({
163163
{groupedItems && (
164164
<ExpandableSection
165165
title="Component Details"
166-
badge={
167-
filters.search
168-
? (() => {
169-
const matchCount =
170-
item.items?.filter(
171-
(subItem) =>
172-
(subItem.metadata?.name || "")
173-
.toLowerCase()
174-
.includes(filters.search.toLowerCase()) ||
175-
(subItem.metadata?.description || "")
176-
.toLowerCase()
177-
.includes(filters.search.toLowerCase()),
178-
).length || 0
179-
return matchCount > 0
180-
? `${matchCount} match${matchCount !== 1 ? "es" : ""}`
181-
: undefined
182-
})()
183-
: undefined
184-
}
185-
defaultExpanded={
186-
!!filters.search &&
187-
(item.items?.some(
188-
(subItem) =>
189-
(subItem.metadata?.name || "").toLowerCase().includes(filters.search.toLowerCase()) ||
190-
(subItem.metadata?.description || "")
191-
.toLowerCase()
192-
.includes(filters.search.toLowerCase()),
193-
) ||
194-
false)
195-
}>
166+
badge={(() => {
167+
const matchCount = item.items?.filter((subItem) => subItem.matchInfo?.matched).length ?? 0
168+
return matchCount > 0 ? `${matchCount} match${matchCount !== 1 ? "es" : ""}` : undefined
169+
})()}
170+
defaultExpanded={item.items?.some((subItem) => subItem.matchInfo?.matched) ?? false}>
196171
<div className="space-y-4">
197172
{Object.entries(groupedItems).map(([type, group]) => (
198-
<TypeGroup key={type} type={type} items={group.items} searchTerm={filters.search} />
173+
<TypeGroup key={type} type={type} items={group.items} />
199174
))}
200175
</div>
201176
</ExpandableSection>

webview-ui/src/components/package-manager/components/TypeGroup.tsx

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ interface TypeGroupProps {
88
description?: string
99
metadata?: any
1010
path?: string
11+
matchInfo?: {
12+
matched: boolean
13+
matchReason?: Record<string, boolean>
14+
}
1115
}>
1216
className?: string
13-
searchTerm?: string
1417
}
1518

16-
export const TypeGroup: React.FC<TypeGroupProps> = ({ type, items, className, searchTerm }) => {
19+
export const TypeGroup: React.FC<TypeGroupProps> = ({ type, items, className }) => {
1720
const getTypeLabel = (type: string) => {
1821
switch (type) {
1922
case "mode":
@@ -33,41 +36,31 @@ export const TypeGroup: React.FC<TypeGroupProps> = ({ type, items, className, se
3336
return null
3437
}
3538

36-
// Check if an item matches the search term
37-
const itemMatchesSearch = (item: { name: string; description?: string }) => {
38-
if (!searchTerm) return false
39-
const term = searchTerm.toLowerCase()
40-
return item.name.toLowerCase().includes(term) || (item.description || "").toLowerCase().includes(term)
41-
}
42-
4339
return (
4440
<div className={cn("mb-4", className)}>
4541
<h4 className="text-sm font-medium text-vscode-foreground mb-2">{getTypeLabel(type)}</h4>
4642
<ol className="list-decimal list-inside space-y-1">
47-
{items.map((item, index) => {
48-
const matches = itemMatchesSearch(item)
49-
return (
50-
<li
51-
key={`${item.path || index}`}
52-
className={cn(
53-
"text-sm pl-1",
54-
matches ? "text-vscode-foreground font-medium" : "text-vscode-foreground",
55-
)}
56-
title={item.path}>
57-
<span className={cn("font-medium", matches ? "text-vscode-textLink" : "")}>
58-
{item.name}
43+
{items.map((item, index) => (
44+
<li
45+
key={`${item.path || index}`}
46+
className={cn(
47+
"text-sm pl-1",
48+
item.matchInfo?.matched ? "text-vscode-foreground font-medium" : "text-vscode-foreground",
49+
)}
50+
title={item.path}>
51+
<span className={cn("font-medium", item.matchInfo?.matched ? "text-vscode-textLink" : "")}>
52+
{item.name}
53+
</span>
54+
{item.description && (
55+
<span className="text-vscode-descriptionForeground"> - {item.description}</span>
56+
)}
57+
{item.matchInfo?.matched && (
58+
<span className="ml-2 text-xs bg-vscode-badge-background text-vscode-badge-foreground px-1 py-0.5 rounded">
59+
match
5960
</span>
60-
{item.description && (
61-
<span className="text-vscode-descriptionForeground"> - {item.description}</span>
62-
)}
63-
{matches && (
64-
<span className="ml-2 text-xs bg-vscode-badge-background text-vscode-badge-foreground px-1 py-0.5 rounded">
65-
match
66-
</span>
67-
)}
68-
</li>
69-
)
70-
})}
61+
)}
62+
</li>
63+
))}
7164
</ol>
7265
</div>
7366
)

webview-ui/src/components/package-manager/utils/grouping.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export interface GroupedItems {
88
description?: string
99
metadata?: any
1010
path?: string
11+
matchInfo?: {
12+
matched: boolean
13+
matchReason?: Record<string, boolean>
14+
}
1115
}>
1216
}
1317
}
@@ -39,6 +43,7 @@ export function groupItemsByType(items: PackageManagerItem["items"] = []): Group
3943
description: item.metadata?.description,
4044
metadata: item.metadata,
4145
path: item.path,
46+
matchInfo: item.matchInfo,
4247
})
4348

4449
return groups

0 commit comments

Comments
 (0)