Sammy/t 131 i see a ascending descending option in (#73)
* refactor: use safe css selector * feature: onclick update the order option * feature: set option in the dropdown * feature: display icon for sort options * refactor: indent key so react does not complain of conflicting keys * feature: align icon and text * feature: fix size of icon to align text * feature: create design for TopOption in dropdown * refactor: set font weight in style * feature: finalise design of TopOption * refactor: rename option to sort * refactor: remove order from the sortType * refactor: move sort mapper in service * test: selection of Descending in SortDropdownButton * refactor: fix styme-component warning * feature: add sorting by people * refactor: set SortFields types for tables * feature: add sort by company * refactor: rename sortFields to singular * refactor: rename option to SortDirection
This commit is contained in:
@ -5,8 +5,12 @@ import styled from '@emotion/styled';
|
||||
import { peopleColumns, sortsAvailable } from './people-table';
|
||||
import { mapPerson } from '../../interfaces/person.interface';
|
||||
import { useCallback, useState } from 'react';
|
||||
import { SortType } from '../../components/table/table-header/SortAndFilterBar';
|
||||
import { OrderBy, usePeopleQuery } from '../../services/people';
|
||||
import {
|
||||
OrderBy,
|
||||
PeopleSelectedSortType,
|
||||
reduceSortsToOrderBy,
|
||||
usePeopleQuery,
|
||||
} from '../../services/people';
|
||||
|
||||
const StyledPeopleContainer = styled.div`
|
||||
display: flex;
|
||||
@ -19,19 +23,11 @@ const defaultOrderBy: OrderBy[] = [
|
||||
},
|
||||
];
|
||||
|
||||
const reduceSortsToOrderBy = (sorts: Array<SortType>): OrderBy[] => {
|
||||
const mappedSorts = sorts.reduce((acc, sort) => {
|
||||
acc[sort.id] = sort.order;
|
||||
return acc;
|
||||
}, {} as OrderBy);
|
||||
return [mappedSorts];
|
||||
};
|
||||
|
||||
function People() {
|
||||
const [, setSorts] = useState([] as Array<SortType>);
|
||||
const [, setSorts] = useState([] as Array<PeopleSelectedSortType>);
|
||||
const [orderBy, setOrderBy] = useState(defaultOrderBy);
|
||||
|
||||
const updateSorts = useCallback((sorts: Array<SortType>) => {
|
||||
const updateSorts = useCallback((sorts: Array<PeopleSelectedSortType>) => {
|
||||
setSorts(sorts);
|
||||
setOrderBy(sorts.length ? reduceSortsToOrderBy(sorts) : defaultOrderBy);
|
||||
}, []);
|
||||
|
||||
@ -15,28 +15,36 @@ import Checkbox from '../../components/form/Checkbox';
|
||||
import HorizontalyAlignedContainer from '../../layout/containers/HorizontalyAlignedContainer';
|
||||
import CompanyChip from '../../components/chips/CompanyChip';
|
||||
import PersonChip from '../../components/chips/PersonChip';
|
||||
import { GraphqlQueryPerson, Person } from '../../interfaces/person.interface';
|
||||
import { Person } from '../../interfaces/person.interface';
|
||||
import PipeChip from '../../components/chips/PipeChip';
|
||||
import { SortType } from '../../components/table/table-header/SortAndFilterBar';
|
||||
import EditableCell from '../../components/table/EditableCell';
|
||||
import { updatePerson } from '../../services/people';
|
||||
import { OrderByFields, updatePerson } from '../../services/people';
|
||||
|
||||
export const sortsAvailable = [
|
||||
{
|
||||
id: 'fullname',
|
||||
label: 'People',
|
||||
icon: faUser,
|
||||
},
|
||||
{
|
||||
id: 'company_name',
|
||||
label: 'Company',
|
||||
icon: faBuildings,
|
||||
},
|
||||
{
|
||||
id: 'email',
|
||||
label: 'Email',
|
||||
order: 'asc',
|
||||
icon: faEnvelope,
|
||||
},
|
||||
{ id: 'phone', label: 'Phone', order: 'asc', icon: faPhone },
|
||||
{ id: 'phone', label: 'Phone', icon: faPhone },
|
||||
{
|
||||
id: 'created_at',
|
||||
label: 'Created at',
|
||||
order: 'asc',
|
||||
icon: faCalendar,
|
||||
},
|
||||
{ id: 'city', label: 'City', order: 'asc', icon: faMapPin },
|
||||
] satisfies Array<SortType<keyof GraphqlQueryPerson>>;
|
||||
{ id: 'city', label: 'City', icon: faMapPin },
|
||||
] satisfies Array<SortType<OrderByFields>>;
|
||||
|
||||
const columnHelper = createColumnHelper<Person>();
|
||||
export const peopleColumns = [
|
||||
|
||||
Reference in New Issue
Block a user