First working version of new dropdown UI (#360)

* First working version of new dropdown UI

* Removed consolelog

* Fixed test storybook

* Cleaned optional args
This commit is contained in:
Lucas Bordeau
2023-06-23 12:39:16 +02:00
committed by GitHub
parent 703f31632d
commit ceaf482f62
8 changed files with 111 additions and 40 deletions

View File

@ -2,6 +2,6 @@ import { DocumentNode } from 'graphql';
export type SearchConfigType = {
query: DocumentNode;
template: (searchInput: string) => any;
template: (searchInput: string, currentSelectedId?: string) => any;
resultMapper: (data: any) => any;
};

View File

@ -79,7 +79,13 @@ export type SearchResultsType<T> = {
loading: boolean;
};
export const useSearch = <T>(): [
type SearchArgs = {
currentSelectedId?: string | null;
};
export const useSearch = <T>(
searchArgs?: SearchArgs,
): [
SearchResultsType<T>,
React.Dispatch<React.SetStateAction<string>>,
React.Dispatch<React.SetStateAction<SearchConfigType | null>>,
@ -99,9 +105,12 @@ export const useSearch = <T>(): [
return (
searchConfig &&
searchConfig.template &&
searchConfig.template(searchInput)
searchConfig.template(
searchInput,
searchArgs?.currentSelectedId ?? undefined,
)
);
}, [searchConfig, searchInput]);
}, [searchConfig, searchInput, searchArgs]);
const searchQueryResults = useQuery(searchConfig?.query || EMPTY_QUERY, {
variables: {