Skip to content

Commit c12116f

Browse files
fix(dashboard): use type guard instead of type assertion in search items filter
1 parent 9a49333 commit c12116f

File tree

1 file changed

+9
-2
lines changed
  • packages/app/src/app/pages/Dashboard/Content/routes/Search

1 file changed

+9
-2
lines changed

packages/app/src/app/pages/Dashboard/Content/routes/Search/searchItems.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ type DashboardItem =
1313
| SandboxFragmentDashboardFragment
1414
| SidebarCollectionDashboardFragment;
1515

16+
// Type guard to check if an item is a sandbox
17+
function isSandbox(
18+
item: DashboardItem | { repository?: any; path?: string }
19+
): item is SandboxFragmentDashboardFragment {
20+
return !('path' in item) && !('repository' in item);
21+
}
22+
1623
// define which fields to search, with per-key thresholds & weights
1724
const SEARCH_KEYS = [
1825
{ name: 'title', threshold: 0.2, weight: 0.4 },
@@ -99,7 +106,7 @@ export const useGetItems = ({
99106
query: string;
100107
username: string;
101108
getFilteredSandboxes: (
102-
list: DashboardItem[]
109+
list: SandboxFragmentDashboardFragment[]
103110
) => SandboxFragmentDashboardFragment[];
104111
}) => {
105112
const state = useAppState();
@@ -137,7 +144,7 @@ export const useGetItems = ({
137144
}, [query, searchIndex]);
138145

139146
// then the rest is just your existing filtering / mapping logic:
140-
const sandboxesInSearch = foundResults.filter(s => !(s as any).path);
147+
const sandboxesInSearch = foundResults.filter(isSandbox);
141148
const foldersInSearch = foundResults.filter(s => (s as any).path);
142149
const filteredSandboxes = getFilteredSandboxes(sandboxesInSearch);
143150
const isLoadingQuery = query && !searchIndex;

0 commit comments

Comments
 (0)