Restructure project (#124)
This commit is contained in:
29
front/src/interfaces/entities/generic.interface.ts
Normal file
29
front/src/interfaces/entities/generic.interface.ts
Normal 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;
|
||||
60
front/src/interfaces/filters/interface.ts
Normal file
60
front/src/interfaces/filters/interface.ts
Normal 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>;
|
||||
};
|
||||
24
front/src/interfaces/search/interface.ts
Normal file
24
front/src/interfaces/search/interface.ts
Normal 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;
|
||||
};
|
||||
};
|
||||
21
front/src/interfaces/sorts/interface.ts
Normal file
21
front/src/interfaces/sorts/interface.ts
Normal 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';
|
||||
};
|
||||
Reference in New Issue
Block a user