Skip to content

Commit c6470db

Browse files
committed
refactor(features): improve list layout
see #250
1 parent 89850d8 commit c6470db

File tree

2 files changed

+355
-268
lines changed

2 files changed

+355
-268
lines changed

src/GeographicalFeatures/CriticalFacilities/Form/index.js

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import get from 'lodash/get';
4+
import map from 'lodash/map';
45
import { Button, Input, InputNumber, Form, Row, Col } from 'antd';
56
import { httpActions } from '@codetanzania/ewea-api-client';
67
import { reduxActions } from '@codetanzania/ewea-api-states';
@@ -71,6 +72,14 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
7172
const onFinish = (values) => {
7273
const formData = { ...values };
7374

75+
// TODO: fix clearing custodians relations
76+
// TODO: fix form ref geos.point.coordinates[0]
77+
const longitude = get(formData, 'geos.longitude');
78+
const latitude = get(formData, 'geos.latitude');
79+
if (longitude && latitude) {
80+
formData.geos.point = { coordinates: [longitude, latitude] };
81+
}
82+
7483
if (isEditForm) {
7584
const updates = { ...feature, ...formData };
7685
putFeature(
@@ -87,14 +96,20 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
8796
}
8897
};
8998

90-
const [moreFilters, setMoreFilters] = useState(false);
99+
const [moreOptions, setMoreOptions] = useState(false);
91100

92101
return (
93102
<Form
94103
labelCol={labelCol}
95104
wrapperCol={wrapperCol}
96105
onFinish={onFinish}
97-
initialValues={{ ...feature }}
106+
initialValues={{
107+
...feature,
108+
relations: {
109+
...get(feature, 'relations', {}),
110+
custodians: map(get(feature, 'relations.custodians', []), '_id'),
111+
},
112+
}}
98113
autoComplete="off"
99114
>
100115
{/* start: type & code */}
@@ -126,7 +141,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
126141
{/* start:code */}
127142
<Col span={11}>
128143
<Form.Item
129-
label="Code"
144+
label="Code/Number"
130145
title="Critical infrastructure code e.g DSM001"
131146
name={['strings', 'code']}
132147
>
@@ -172,7 +187,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
172187
>
173188
<SearchableSelectInput
174189
onSearch={(optns = {}) => {
175-
return getAdministrativeAreas(optns, feature);
190+
return getAdministrativeAreas(optns);
176191
}}
177192
optionLabel={(area) => {
178193
return `${get(area, 'strings.name.en')} (${get(
@@ -191,14 +206,15 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
191206
{/* end: name & area */}
192207

193208
{/* start: longitude & latitude */}
194-
{moreFilters && (
209+
{moreOptions && (
195210
<Row justify="space-between">
196211
{/* start:longitude */}
197212
<Col span={11}>
198213
<Form.Item
199214
label="Longitude"
200215
title="Critical infrastructure longitude(x-coordinate) e.g 39.2858"
201-
name={['geos', 'point[0]']}
216+
name={['geos', 'longitude']}
217+
initialValue={get(feature, 'geos.point.coordinates[0]')}
202218
>
203219
<InputNumber style={{ width: '100%' }} />
204220
</Form.Item>
@@ -209,7 +225,8 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
209225
<Form.Item
210226
label="Latitude"
211227
title="Critical infrastructure latitude(y-coordinate) e.g -6.8188"
212-
name={['geos', 'point[1]']}
228+
name={['geos', 'latitude']}
229+
initialValue={get(feature, 'geos.point.coordinates[1]')}
213230
>
214231
<InputNumber style={{ width: '100%' }} />
215232
</Form.Item>
@@ -227,7 +244,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
227244
>
228245
<SearchableSelectInput
229246
onSearch={(optns = {}) => {
230-
return getAgencies(optns, feature);
247+
return getAgencies(optns);
231248
}}
232249
optionLabel={(custodian) => get(custodian, 'name')}
233250
optionValue="_id"
@@ -249,8 +266,8 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
249266

250267
{/* start:form actions */}
251268
<Form.Item wrapperCol={{ span: 24 }} style={{ textAlign: 'right' }}>
252-
<Button type="link" onClick={() => setMoreFilters(!moreFilters)}>
253-
{moreFilters ? 'Less Filters' : 'More Filters'}
269+
<Button type="link" onClick={() => setMoreOptions(!moreOptions)}>
270+
{moreOptions ? 'Less Options' : 'More Options'}
254271
</Button>
255272
<Button style={{ marginLeft: 8 }} onClick={onCancel}>
256273
Cancel
@@ -261,7 +278,7 @@ const FeatureForm = ({ feature, isEditForm, posting, onCancel }) => {
261278
htmlType="submit"
262279
loading={posting}
263280
>
264-
Send
281+
Save
265282
</Button>
266283
</Form.Item>
267284
{/* end:form actions */}

0 commit comments

Comments
 (0)