From 6627ec88b2a02b522511b85eb38d21225098cfad Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 18 Apr 2021 20:36:19 +0300 Subject: feat: support date filters --- src/lib/ServiceContext.tsx | 1 + src/lib/ServiceFilters.tsx | 17 ++++++++++++----- src/services/transfers/index.ts | 1 + src/services/waybills/index.ts | 2 ++ 4 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lib/ServiceContext.tsx b/src/lib/ServiceContext.tsx index 2573134..b52c3d5 100644 --- a/src/lib/ServiceContext.tsx +++ b/src/lib/ServiceContext.tsx @@ -10,6 +10,7 @@ export interface Action extends ButtonProps { export interface Filter extends Field { as?: string; + date?: boolean; options?: Option[]; value?: string; } diff --git a/src/lib/ServiceFilters.tsx b/src/lib/ServiceFilters.tsx index 8a1e160..b3cfae9 100644 --- a/src/lib/ServiceFilters.tsx +++ b/src/lib/ServiceFilters.tsx @@ -5,13 +5,13 @@ import hooks from '../hooks/useAPIClient'; import useQuery from '../hooks/useQuery'; import ServiceContext, { Filter } from './ServiceContext'; import { SelectBase } from '../components/Select'; +import { InputBase } from '../components/Input'; const getOptionLabel = (item: any, filter: Filter) => { const value = _.get(item, filter.as || filter.key); return filter.transform ? filter.transform(value) : value; }; - const ServiceFilters: React.FC = () => { const service = useContext(ServiceContext); const { query, setQuery } = useQuery(); @@ -32,12 +32,12 @@ const ServiceFilters: React.FC = () => { label: filter.label, }); - const value = _.get(query, filter.key) || '-'; + const value = _.get(query, filter.key, '-'); return { ...filter, options, value }; }); - const handleFilterChange = (key: string) => (event: React.ChangeEvent) => { + const handleFilterChange = (key: string) => (event: React.ChangeEvent) => { const { value } = event.target; const updatedQuery = { ...query, [key]: value }; if (value === '-') delete updatedQuery[key]; @@ -57,14 +57,21 @@ const ServiceFilters: React.FC = () => { Сбросить фильтры )} - {filters?.map(filter => ( + {filters?.map(filter => (filter.date ? ( + + ) : ( - ))} + )))} ); }; diff --git a/src/services/transfers/index.ts b/src/services/transfers/index.ts index b0f71e6..84858ce 100644 --- a/src/services/transfers/index.ts +++ b/src/services/transfers/index.ts @@ -16,6 +16,7 @@ const service: ServiceParams = { { key: 'amount', label: 'Сумма' }, ], filters: [ + { key: 'date', label: 'Дата', date: true }, { key: 'operation', label: 'Операция', transform: transformOperation }, { key: 'contractorId', label: 'Контрагент', as: 'contractor.name' }, ], diff --git a/src/services/waybills/index.ts b/src/services/waybills/index.ts index 0b24876..b623da6 100644 --- a/src/services/waybills/index.ts +++ b/src/services/waybills/index.ts @@ -10,11 +10,13 @@ const service: ServiceParams = { nameSingular: 'Накладная', tableFields: [ { key: 'status', label: 'Статус', transform: transformStatus }, + { key: 'date', label: 'Дата' }, { key: 'operation', label: 'Операция', transform: transformOperation }, { key: 'total', label: 'Сумма' }, { key: 'contractor.name', label: 'Контрагент' }, ], filters: [ + { key: 'date', label: 'Дата', date: true }, { key: 'status', label: 'Статус', transform: transformStatus }, { key: 'operation', label: 'Операция', transform: transformOperation }, { key: 'contractorId', label: 'Контрагент', as: 'contractor.name' }, -- cgit v1.2.3