Refator/sorts dropdown (#1568)

* WIP

* Fixed lint

* Ok for sorts

* Fixed on dropdown toggle

* Fix lint
This commit is contained in:
Lucas Bordeau
2023-09-14 01:38:11 +02:00
committed by GitHub
parent a392a81994
commit 8627416d60
55 changed files with 339 additions and 309 deletions

View File

@ -85,25 +85,20 @@ const StyledTableContainer = styled.div`
overflow: auto;
`;
type OwnProps<SortField> = {
type OwnProps = {
updateEntityMutation: any;
} & Pick<
TableHeaderProps<SortField>,
| 'availableSorts'
| 'defaultViewName'
| 'onImport'
| 'onViewsChange'
| 'onViewSubmit'
TableHeaderProps,
'defaultViewName' | 'onImport' | 'onViewsChange' | 'onViewSubmit'
>;
export function EntityTable<SortField>({
availableSorts,
export function EntityTable({
defaultViewName,
onImport,
onViewsChange,
onViewSubmit,
updateEntityMutation,
}: OwnProps<SortField>) {
}: OwnProps) {
const tableBodyRef = useRef<HTMLDivElement>(null);
const setRowSelectedState = useSetRowSelectedState();
@ -141,7 +136,6 @@ export function EntityTable<SortField>({
<StyledTableWithHeader>
<StyledTableContainer ref={tableBodyRef}>
<TableHeader
availableSorts={availableSorts ?? []}
defaultViewName={defaultViewName}
onImport={onImport}
onViewsChange={onViewsChange}

View File

@ -4,9 +4,10 @@ import { useOptimisticEffect } from '@/apollo/optimistic-effect/hooks/useOptimis
import { OptimisticEffectDefinition } from '@/apollo/optimistic-effect/types/OptimisticEffectDefinition';
import { useSetEntityTableData } from '@/ui/table/hooks/useSetEntityTableData';
import { FilterDefinition } from '@/ui/view-bar/types/FilterDefinition';
import { SortDefinition } from '@/ui/view-bar/types/SortDefinition';
import { SortOrder } from '~/generated/graphql';
export function GenericEntityTableData({
export function EntityTableEffect({
useGetRequest,
getRequestResultKey,
getRequestOptimisticEffectDefinition,
@ -19,13 +20,18 @@ export function GenericEntityTableData({
filterDefinitionArray,
setActionBarEntries,
setContextMenuEntries,
sortDefinitionArray,
}: {
// TODO: type this
useGetRequest: any;
getRequestResultKey: string;
getRequestOptimisticEffectDefinition: OptimisticEffectDefinition<any>;
// TODO: type this and replace with defaultSorts reduce should be applied to defaultSorts in this component not before
orderBy?: any;
// TODO: type this and replace with defaultFilters reduce should be applied to defaultFilters in this component not before
whereFilters?: any;
filterDefinitionArray: FilterDefinition[];
sortDefinitionArray: SortDefinition[];
setActionBarEntries?: () => void;
setContextMenuEntries?: () => void;
}) {
@ -36,7 +42,9 @@ export function GenericEntityTableData({
variables: { orderBy, where: whereFilters },
onCompleted: (data: any) => {
const entities = data[getRequestResultKey] ?? [];
setEntityTableData(entities, filterDefinitionArray);
setEntityTableData(entities, filterDefinitionArray, sortDefinitionArray);
registerOptimisticEffect({
variables: { orderBy, where: whereFilters },
definition: getRequestOptimisticEffectDefinition,