summaryrefslogtreecommitdiff
path: root/src/lib/ServiceList.tsx
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-04-17 13:39:30 +0300
committereug-vs <eug-vs@keemail.me>2021-04-17 13:41:29 +0300
commit1bf07892f2cd8007f48469c42fa9fcc84d5ef435 (patch)
tree054d600ffa414a71f15e2dc7606121649f7587ca /src/lib/ServiceList.tsx
parenta4a1c456e0788ca52261efb38ff3998710a42a59 (diff)
downloadcommercel-ui-1bf07892f2cd8007f48469c42fa9fcc84d5ef435.tar.gz
feat: correctly add filters from Service JSON
Diffstat (limited to 'src/lib/ServiceList.tsx')
-rw-r--r--src/lib/ServiceList.tsx33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/lib/ServiceList.tsx b/src/lib/ServiceList.tsx
index a3c9842..9b12d6b 100644
--- a/src/lib/ServiceList.tsx
+++ b/src/lib/ServiceList.tsx
@@ -1,10 +1,16 @@
import React, { useContext } from 'react';
import { useHistory, useLocation } from 'react-router-dom';
+import _ from 'lodash';
import Page from '../containers/Page';
-import ListTable from '../components/ListTable';
+import ListTable, { Field } from '../components/ListTable';
import hooks from '../hooks/useAPIClient';
import ServiceContext from './ServiceContext';
+const getItemField = (item: any, field: Field) => {
+ const value = _.get(item, field.key);
+ return field.transform ? field.transform(value) : value;
+};
+
const ServiceList: React.FC = () => {
const service = useContext(ServiceContext);
const history = useHistory();
@@ -16,14 +22,23 @@ const ServiceList: React.FC = () => {
route: `/${service.route}/add${location.search}`,
}];
- const filters = [{
- field: '_id',
- options: [
- { key: 'a', label: 'a' },
- { key: 'b', label: 'b' },
- { key: 'c', label: 'c' },
- ],
- }];
+ const filters = service.filters?.map(key => {
+ const field = _.find(service.tableFields, { key });
+ if (!field) return { key: '-', label: '-', options: [] };
+
+ const options = data?.map((item: any) => ({
+ key: _.get(item, field.key),
+ label: getItemField(item, field),
+ }));
+
+ // Add default option
+ options?.unshift({
+ key: '-',
+ label: field.label,
+ });
+
+ return { ...field, options };
+ });
const handleRowClick = (item: any) => {
const route = service.rowLink