Restructure project (#124)

This commit is contained in:
Charles Bochet
2023-05-17 22:31:16 +02:00
committed by GitHub
parent baca6150f5
commit 434e020846
76 changed files with 295 additions and 304 deletions

View File

@ -0,0 +1,29 @@
import {
Companies_Bool_Exp,
People_Bool_Exp,
Users_Bool_Exp,
} from '../../generated/graphql';
import { Company, GraphqlQueryCompany } from './company.interface';
import { GraphqlQueryPerson, Person } from './person.interface';
import { GraphqlQueryUser, User } from './user.interface';
export type AnyEntity = {
id: string;
__typename: string;
} & Record<string, any>;
export type GqlType<T> = T extends Company
? GraphqlQueryCompany
: T extends Person
? GraphqlQueryPerson
: T extends User
? GraphqlQueryUser
: never;
export type BoolExpType<T> = T extends Company
? Companies_Bool_Exp
: T extends Person
? People_Bool_Exp
: T extends User
? Users_Bool_Exp
: never;

View File

@ -0,0 +1,60 @@
import { ReactNode } from 'react';
import { SearchConfigType, SearchableType } from '../search/interface';
import { Person } from '../entities/person.interface';
import { Company } from '../entities/company.interface';
import { User } from '../entities/user.interface';
import { AnyEntity, BoolExpType } from '../entities/generic.interface';
export type FilterableFieldsType = Person | Company;
export type FilterWhereType = Person | Company | User | AnyEntity;
export type FilterConfigType<
FilteredType extends FilterableFieldsType,
WhereType extends FilterWhereType = any,
> = {
key: string;
label: string;
icon: ReactNode;
operands: FilterOperandType<FilteredType, WhereType>[];
searchConfig: WhereType extends SearchableType
? SearchConfigType<WhereType>
: null;
selectedValueRender: (selected: WhereType) => string;
};
export type FilterOperandType<
FilteredType extends FilterableFieldsType,
WhereType extends FilterWhereType = AnyEntity,
> =
| FilterOperandExactMatchType<FilteredType, WhereType>
| FilterOperandComparativeType<FilteredType, WhereType>;
type FilterOperandExactMatchType<
FilteredType extends FilterableFieldsType,
WhereType extends FilterWhereType,
> = {
label: 'Equal' | 'Not equal';
id: 'equal' | 'not-equal';
whereTemplate: (value: WhereType) => BoolExpType<FilteredType>;
};
type FilterOperandComparativeType<
FilteredType extends FilterableFieldsType,
WhereType extends FilterWhereType,
> = {
label: 'Like' | 'Not like' | 'Include';
id: 'like' | 'not_like' | 'include';
whereTemplate: (value: WhereType) => BoolExpType<FilteredType>;
};
export type SelectedFilterType<
FilteredType extends FilterableFieldsType,
WhereType extends FilterWhereType = AnyEntity,
> = {
key: string;
value: WhereType;
displayValue: string;
label: string;
icon: ReactNode;
operand: FilterOperandType<FilteredType, WhereType>;
};

View File

@ -0,0 +1,24 @@
import { DocumentNode } from 'graphql';
import { ReactNode } from 'react';
import {
Companies_Bool_Exp,
People_Bool_Exp,
Users_Bool_Exp,
} from '../../generated/graphql';
import { Person } from '../entities/person.interface';
import { Company } from '../entities/company.interface';
import { User } from '../entities/user.interface';
import { GqlType } from '../entities/generic.interface';
export type SearchableType = Person | Company | User;
export type SearchConfigType<SearchType extends SearchableType> = {
query: DocumentNode;
template: (
searchInput: string,
) => People_Bool_Exp | Companies_Bool_Exp | Users_Bool_Exp;
resultMapper: (data: GqlType<SearchType>) => {
value: SearchType;
render: (value: SearchType) => ReactNode;
};
};

View File

@ -0,0 +1,21 @@
import { ReactNode } from 'react';
import { Order_By } from '../../generated/graphql';
export type SortType<OrderByTemplate> =
| {
_type: 'default_sort';
label: string;
key: keyof OrderByTemplate & string;
icon?: ReactNode;
}
| {
_type: 'custom_sort';
label: string;
key: string;
icon?: ReactNode;
orderByTemplate: (order: Order_By) => OrderByTemplate;
};
export type SelectedSortType<OrderByTemplate> = SortType<OrderByTemplate> & {
order: 'asc' | 'desc';
};