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,36 +0,0 @@
export const mockCompanySearchData = {
data: {
searchResults: [
{
id: 'fe256b39-3ec3-4fe3-8997-b76aa0bfa408',
name: 'Linkedin',
domain_name: 'linkedin-searched.com',
__typename: 'companies',
},
{
id: '118995f3-5d81-46d6-bf83-f7fd33ea6102',
name: 'Facebook',
domain_name: 'facebook-searched.com',
__typename: 'companies',
},
{
id: '04b2e9f5-0713-40a5-8216-82802401d33e',
name: 'Qonto',
domain_name: 'qonto-searched.com',
__typename: 'companies',
},
{
id: '460b6fb1-ed89-413a-b31a-962986e67bb4',
name: 'Microsoft',
domain_name: 'microsoft-searched.com',
__typename: 'companies',
},
{
id: '0d940997-c21e-4ec2-873b-de4264d89025',
name: 'Google',
domain_name: 'google-searched.com',
__typename: 'companies',
},
],
},
};

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>>,