Refactor Filter type to accept Is, Is Not, Contains, Does not Contain (#128)

* Refactor Filter type to accept Is, Is Not, Contains, Does not Contain

* Remove any and add tests
This commit is contained in:
Charles Bochet
2023-05-18 15:32:57 +02:00
committed by GitHub
parent 4211d5872b
commit 5286dfd695
20 changed files with 241 additions and 336 deletions

View File

@ -1,9 +1,7 @@
import { gql, useQuery } from '@apollo/client';
import { useMemo, useState } from 'react';
import {
SearchConfigType,
SearchableType,
} from '../../../interfaces/search/interface';
import { SearchConfigType } from '../../../interfaces/search/interface';
import { AnyEntity } from '../../../interfaces/entities/generic.interface';
export const SEARCH_PEOPLE_QUERY = gql`
query SearchQuery($where: people_bool_exp, $limit: Int) {
@ -58,7 +56,7 @@ const debounce = <FuncArgs extends any[]>(
};
};
export type SearchResultsType<T extends SearchableType> = {
export type SearchResultsType<T extends AnyEntity = AnyEntity> = {
results: {
render: (value: T) => string;
value: T;
@ -66,7 +64,7 @@ export type SearchResultsType<T extends SearchableType> = {
loading: boolean;
};
export const useSearch = <T extends SearchableType>(): [
export const useSearch = <T extends AnyEntity = AnyEntity>(): [
SearchResultsType<T>,
React.Dispatch<React.SetStateAction<string>>,
React.Dispatch<React.SetStateAction<SearchConfigType<T> | null>>,