feat: quick-find search for clients and pets (GH #97) #103
@@ -34,16 +34,6 @@ vi.mock("@groombook/db", () => {
|
|||||||
const clients = tableProxy("clients");
|
const clients = tableProxy("clients");
|
||||||
const pets = tableProxy("pets");
|
const pets = tableProxy("pets");
|
||||||
|
|
||||||
function makeSelectChain(results: unknown[]): unknown {
|
|
||||||
const chain: Record<string, unknown> = {};
|
|
||||||
const terminal = () => Promise.resolve(results);
|
|
||||||
chain.from = () => chain;
|
|
||||||
chain.innerJoin = () => chain;
|
|
||||||
chain.where = () => chain;
|
|
||||||
chain.limit = terminal;
|
|
||||||
return chain;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getDb: () => ({
|
getDb: () => ({
|
||||||
select: (_fields?: unknown) => {
|
select: (_fields?: unknown) => {
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ export function GlobalSearch() {
|
|||||||
setResults(data);
|
setResults(data);
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch (err) {
|
||||||
// ignore fetch errors
|
console.warn("GlobalSearch: fetch error", err);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
@@ -83,13 +83,13 @@ export function GlobalSearch() {
|
|||||||
function handleClientClick(client: ClientResult) {
|
function handleClientClick(client: ClientResult) {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
setQuery("");
|
setQuery("");
|
||||||
navigate("/admin/clients");
|
navigate(`/admin/clients?highlight=${client.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handlePetClick(pet: PetResult) {
|
function handlePetClick(pet: PetResult) {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
setQuery("");
|
setQuery("");
|
||||||
navigate("/admin/clients");
|
navigate(`/admin/clients?highlight=${pet.clientId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasResults = results && (results.clients.length > 0 || results.pets.length > 0);
|
const hasResults = results && (results.clients.length > 0 || results.pets.length > 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user