mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-29 19:10:19 +03:00
Merge pull request #59 from twentyhq/cbo-finalize-filters
Finalize sort created_at filter
This commit is contained in:
commit
fe10c0ba7d
@ -16,7 +16,7 @@ type OwnProps<TData> = {
|
|||||||
columns: Array<ColumnDef<TData, any>>;
|
columns: Array<ColumnDef<TData, any>>;
|
||||||
viewName: string;
|
viewName: string;
|
||||||
viewIcon?: IconProp;
|
viewIcon?: IconProp;
|
||||||
onSortsUpdate?: React.Dispatch<React.SetStateAction<SortType[]>>;
|
onSortsUpdate?: (sorts: Array<SortType>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledTable = styled.table`
|
const StyledTable = styled.table`
|
||||||
|
@ -4,12 +4,12 @@ import DropdownButton from './DropdownButton';
|
|||||||
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
||||||
import { faCalendar } from '@fortawesome/pro-regular-svg-icons';
|
import { faCalendar } from '@fortawesome/pro-regular-svg-icons';
|
||||||
import SortAndFilterBar, { SortType } from './SortAndFilterBar';
|
import SortAndFilterBar, { SortType } from './SortAndFilterBar';
|
||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
viewName: string;
|
viewName: string;
|
||||||
viewIcon?: IconProp;
|
viewIcon?: IconProp;
|
||||||
onSortsUpdate?: React.Dispatch<React.SetStateAction<SortType[]>>;
|
onSortsUpdate?: (sorts: Array<SortType>) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledContainer = styled.div`
|
const StyledContainer = styled.div`
|
||||||
@ -53,15 +53,17 @@ function TableHeader({ viewName, viewIcon, onSortsUpdate }: OwnProps) {
|
|||||||
label: 'Created at',
|
label: 'Created at',
|
||||||
order: 'asc',
|
order: 'asc',
|
||||||
id: sortId,
|
id: sortId,
|
||||||
},
|
} as SortType,
|
||||||
]);
|
]);
|
||||||
onSortsUpdate && onSortsUpdate(sorts);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSortItemUnSelect = (sortId: string) => {
|
const onSortItemUnSelect = (sortId: string) => {
|
||||||
setSorts([]);
|
setSorts([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
onSortsUpdate && onSortsUpdate(sorts);
|
||||||
|
}, [sorts, onSortsUpdate]);
|
||||||
|
|
||||||
const sortsAvailable: Array<SortType> = [
|
const sortsAvailable: Array<SortType> = [
|
||||||
{
|
{
|
||||||
id: 'created_at',
|
id: 'created_at',
|
||||||
|
@ -34,7 +34,7 @@ export const GET_PEOPLE = gql`
|
|||||||
// @TODO get those types from generated-code person-order-by
|
// @TODO get those types from generated-code person-order-by
|
||||||
type OrderBy = Record<string, 'asc' | 'desc'>;
|
type OrderBy = Record<string, 'asc' | 'desc'>;
|
||||||
|
|
||||||
const defaultOrderBy = [
|
const defaultOrderBy: OrderBy[] = [
|
||||||
{
|
{
|
||||||
created_at: 'desc',
|
created_at: 'desc',
|
||||||
},
|
},
|
||||||
@ -49,8 +49,14 @@ const reduceSortsToOrderBy = (sorts: Array<SortType>): OrderBy[] => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function People() {
|
function People() {
|
||||||
const [sorts, setSorts] = useState([] as Array<SortType>);
|
const [, setSorts] = useState([] as Array<SortType>);
|
||||||
const orderBy = sorts.length ? reduceSortsToOrderBy(sorts) : defaultOrderBy;
|
const [orderBy, setOrderBy] = useState(defaultOrderBy);
|
||||||
|
|
||||||
|
const updateSorts = (sorts: Array<SortType>) => {
|
||||||
|
setSorts(sorts);
|
||||||
|
setOrderBy(sorts.length ? reduceSortsToOrderBy(sorts) : defaultOrderBy);
|
||||||
|
};
|
||||||
|
|
||||||
const { data } = useQuery<{ person: GraphqlPerson[] }>(GET_PEOPLE, {
|
const { data } = useQuery<{ person: GraphqlPerson[] }>(GET_PEOPLE, {
|
||||||
variables: { orderBy: orderBy },
|
variables: { orderBy: orderBy },
|
||||||
});
|
});
|
||||||
@ -58,15 +64,15 @@ function People() {
|
|||||||
return (
|
return (
|
||||||
<WithTopBarContainer title="People" icon={faUser}>
|
<WithTopBarContainer title="People" icon={faUser}>
|
||||||
<StyledPeopleContainer>
|
<StyledPeopleContainer>
|
||||||
{data && (
|
{
|
||||||
<Table
|
<Table
|
||||||
data={data.person.map(mapPerson)}
|
data={data ? data.person.map(mapPerson) : []}
|
||||||
columns={peopleColumns}
|
columns={peopleColumns}
|
||||||
viewName="All People"
|
viewName="All People"
|
||||||
viewIcon={faList}
|
viewIcon={faList}
|
||||||
onSortsUpdate={setSorts}
|
onSortsUpdate={updateSorts}
|
||||||
/>
|
/>
|
||||||
)}
|
}
|
||||||
</StyledPeopleContainer>
|
</StyledPeopleContainer>
|
||||||
</WithTopBarContainer>
|
</WithTopBarContainer>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user