Skip to content

Commit a1b3cfd

Browse files
Davydhhdebba
andauthored
feat(navigator): fuzzy search in the Quick Navigator (#421)
Co-authored-by: Andrea Debernardi <andrea@debbaweb.it>
1 parent c149d3d commit a1b3cfd

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/utils/quickNavigator.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { TableInfo, ViewInfo, RoutineInfo, TriggerInfo, SchemaData } from '../contexts/DatabaseContext';
2+
import { fuzzyFilter } from './fuzzy';
23

34
export interface NavigatorItem {
45
name: string;
@@ -158,11 +159,7 @@ export function getNavigatorItems(params: NavigatorItemParams): NavigatorItem[]
158159
}
159160

160161
export function filterNavigatorItems(items: NavigatorItem[], search: string): NavigatorItem[] {
161-
if (!search) return items;
162-
const lowerSearch = search.toLowerCase();
163-
return items.filter((item) => {
164-
const matchName = item.name.toLowerCase().includes(lowerSearch);
165-
const matchSchema = item.schema?.toLowerCase().includes(lowerSearch);
166-
return matchName || matchSchema;
167-
});
162+
return fuzzyFilter(items, search, (item) =>
163+
item.schema ? `${item.name} ${item.schema}` : item.name,
164+
);
168165
}

tests/utils/quickNavigator.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,11 @@ describe("quickNavigator utility", () => {
135135
expect(result).toHaveLength(1);
136136
expect(result[0].name).toBe("user_sessions");
137137
});
138+
139+
it("should tolerate typos", () => {
140+
const result = filterNavigatorItems(mockItems, "sesion").map((i) => i.name);
141+
expect(result).toContain("user_sessions");
142+
expect(result).toContain("active_sessions");
143+
});
138144
});
139145
});

0 commit comments

Comments
 (0)