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:
@ -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;
|
||||
};
|
||||
|
||||
@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user