Skip to content

Commit 9190893

Browse files
committed
refactor(units): improve list grid
see #250
1 parent fcaa59e commit 9190893

File tree

3 files changed

+65
-68
lines changed

3 files changed

+65
-68
lines changed

src/Units/Form/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ const UnitForm = ({ unit, isEditForm, isPosting, onCancel }) => {
163163
);
164164
};
165165

166+
UnitForm.defaultProps = {
167+
unit: {},
168+
};
169+
166170
UnitForm.propTypes = {
167171
unit: PropTypes.shape({
168172
strings: PropTypes.shape({
@@ -175,7 +179,7 @@ UnitForm.propTypes = {
175179
}),
176180
_id: PropTypes.string,
177181
}),
178-
}).isRequired,
182+
}),
179183
isEditForm: PropTypes.bool.isRequired,
180184
isPosting: PropTypes.bool.isRequired,
181185
onCancel: PropTypes.func.isRequired,

src/Units/index.js

+57-56
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ const {
3838

3939
/* ui */
4040
const { confirm } = Modal;
41-
const nameSpan = { xxl: 5, xl: 5, lg: 5, md: 5, sm: 16, xs: 14 };
42-
const abbreviationSpan = { xxl: 3, xl: 3, lg: 3, md: 3, sm: 4, xs: 4 };
43-
const descriptionSpan = { xxl: 14, xl: 14, lg: 14, md: 13, sm: 0, xs: 0 };
41+
const nameSpan = { xxl: 4, xl: 4, lg: 4, md: 4, sm: 16, xs: 14 };
42+
const abbreviationSpan = { xxl: 4, xl: 4, lg: 4, md: 4, sm: 4, xs: 4 };
43+
const symbolSpan = { xxl: 4, xl: 3, lg: 4, md: 4, sm: 0, xs: 0 };
44+
const descriptionSpan = { xxl: 10, xl: 10, lg: 10, md: 8, sm: 0, xs: 0 };
4445
const headerLayout = [
4546
{ ...nameSpan, header: 'Name', title: 'Unit Name' },
4647
{ ...abbreviationSpan, header: 'Abbreviation', title: 'Unit Abbreviation' },
48+
{ ...symbolSpan, header: 'Symbol', title: 'Unit Symbol' },
4749
{
4850
...descriptionSpan,
4951
header: 'Description',
@@ -115,44 +117,6 @@ class UnitList extends Component {
115117
getUnits();
116118
}
117119

118-
/**
119-
* @function handleFormOpen
120-
* @name handleFormOpen
121-
* @description Handle form opening
122-
*
123-
* @version 0.1.0
124-
* @since 0.1.0
125-
*/
126-
handleFormOpen = () => {
127-
openUnitForm();
128-
};
129-
130-
/**
131-
* @function handleFormClose
132-
* @name handleFormClose
133-
* @description Handle form closing
134-
*
135-
* @version 0.1.0
136-
* @since 0.1.0
137-
*/
138-
handleFormClose = () => {
139-
closeUnitForm();
140-
this.setState({ isEditForm: false });
141-
};
142-
143-
/**
144-
* @function handleFormClose
145-
* @name handleFormClose
146-
* @description Handle post form close and perform cleanups
147-
*
148-
* @version 0.1.0
149-
* @since 0.1.0
150-
*/
151-
handleAfterFormClose = () => {
152-
selectUnit(null);
153-
this.setState({ isEditForm: false });
154-
};
155-
156120
/**
157121
* @function handleListSearch
158122
* @name handleListSearch
@@ -211,6 +175,44 @@ class UnitList extends Component {
211175
});
212176
};
213177

178+
/**
179+
* @function handleFormOpen
180+
* @name handleFormOpen
181+
* @description Handle form opening
182+
*
183+
* @version 0.1.0
184+
* @since 0.1.0
185+
*/
186+
handleFormOpen = () => {
187+
openUnitForm();
188+
};
189+
190+
/**
191+
* @function handleFormClose
192+
* @name handleFormClose
193+
* @description Handle form closing
194+
*
195+
* @version 0.1.0
196+
* @since 0.1.0
197+
*/
198+
handleFormClose = () => {
199+
closeUnitForm();
200+
this.setState({ isEditForm: false });
201+
};
202+
203+
/**
204+
* @function handleFormClose
205+
* @name handleFormClose
206+
* @description Handle post form close and perform cleanups
207+
*
208+
* @version 0.1.0
209+
* @since 0.1.0
210+
*/
211+
handleAfterFormClose = () => {
212+
selectUnit(null);
213+
this.setState({ isEditForm: false });
214+
};
215+
214216
/**
215217
* @function handleItemEdit
216218
* @name handleItemEdit
@@ -226,16 +228,14 @@ class UnitList extends Component {
226228
};
227229

228230
/**
229-
* @function
230-
* @name showArchiveConfirm
231-
* @description show confirm modal before archiving a unit
232-
*
231+
* @function handleItemArchive
232+
* @name handleItemArchive
233+
* @description Handle list item archiving with confirmation
233234
* @param {object} item List item
234235
* @version 0.1.0
235236
* @since 0.1.0
236237
*/
237-
238-
showArchiveConfirm = (item) => {
238+
handleItemArchive = (item) => {
239239
const itemId = get(item, '_id');
240240
const itemName = get(item, 'strings.name.en', 'N/A');
241241
confirm({
@@ -388,7 +388,7 @@ class UnitList extends Component {
388388
archive={{
389389
name: 'Archive Unit',
390390
title: 'Remove unit from list of active units',
391-
onClick: () => this.showArchiveConfirm(item),
391+
onClick: () => this.handleItemArchive(item),
392392
}}
393393
/>
394394
)}
@@ -398,6 +398,7 @@ class UnitList extends Component {
398398
<Col {...abbreviationSpan}>
399399
{get(item, 'strings.abbreviation.en', 'N/A')}
400400
</Col>
401+
<Col {...symbolSpan}>{get(item, 'strings.symbol', 'N/A')}</Col>
401402
<Col {...descriptionSpan}>
402403
<span title={get(item, 'strings.description.en', 'N/A')}>
403404
{truncateString(
@@ -464,15 +465,15 @@ class UnitList extends Component {
464465
}
465466

466467
UnitList.propTypes = {
467-
loading: PropTypes.bool.isRequired,
468468
units: PropTypes.arrayOf(PropTypes.shape({ name: PropTypes.string }))
469469
.isRequired,
470-
unit: PropTypes.shape({ name: PropTypes.string }),
471-
page: PropTypes.number.isRequired,
472-
searchQuery: PropTypes.string,
473-
total: PropTypes.number.isRequired,
470+
loading: PropTypes.bool.isRequired,
474471
posting: PropTypes.bool.isRequired,
472+
searchQuery: PropTypes.string,
475473
showForm: PropTypes.bool.isRequired,
474+
page: PropTypes.number.isRequired,
475+
total: PropTypes.number.isRequired,
476+
unit: PropTypes.shape({ name: PropTypes.string }),
476477
};
477478

478479
UnitList.defaultProps = {
@@ -482,11 +483,11 @@ UnitList.defaultProps = {
482483

483484
export default Connect(UnitList, {
484485
units: 'units.list',
485-
unit: 'units.selected',
486486
loading: 'units.loading',
487487
posting: 'units.posting',
488-
page: 'units.page',
488+
searchQuery: 'units.q',
489489
showForm: 'units.showForm',
490+
page: 'units.page',
490491
total: 'units.total',
491-
searchQuery: 'units.q',
492+
unit: 'units.selected',
492493
});

src/components/ListItem/index.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,13 @@ const ListItem = ({
125125

126126
ListItem.propTypes = {
127127
item: PropTypes.shape({
128-
location: PropTypes.string.isRequired,
129-
name: PropTypes.string.isRequired,
130-
role: PropTypes.shape({ strings: PropTypes.object }),
131-
area: PropTypes.shape({ strings: PropTypes.object }),
132-
email: PropTypes.string.isRequired,
133-
mobile: PropTypes.string.isRequired,
134-
party: PropTypes.shape({
135-
name: PropTypes.string,
136-
abbreviation: PropTypes.string,
137-
}),
128+
_id: PropTypes.string,
129+
name: PropTypes.string,
138130
}).isRequired,
139131
name: PropTypes.string,
140132
avatarBackgroundColor: PropTypes.string,
141133
children: PropTypes.node.isRequired,
142-
renderActions: PropTypes.string.isRequired,
134+
renderActions: PropTypes.func.isRequired,
143135
isSelected: PropTypes.bool.isRequired,
144136
onSelectItem: PropTypes.func.isRequired,
145137
onDeselectItem: PropTypes.func.isRequired,

0 commit comments

Comments
 (0)