Skip to content

Commit

Permalink
refactor(administrative-level): improve list layout
Browse files Browse the repository at this point in the history
see #250
  • Loading branch information
lykmapipo committed May 24, 2020
1 parent 77d95af commit a307f97
Show file tree
Hide file tree
Showing 4 changed files with 352 additions and 459 deletions.
232 changes: 0 additions & 232 deletions src/GeographicalFeatures/AdministrativeLevels/Filters/index.js

This file was deleted.

23 changes: 22 additions & 1 deletion src/GeographicalFeatures/AdministrativeLevels/Form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ const AdministrativeLevelForm = ({
}
};

// search administrative level exclude self
const searchAdministrativeLevels = (optns, me) => {
const filter = {};
const myId = get(me, '_id');
const myLevel = get(me, 'numbers.weight');

// ignore self from selection
if (myId) {
// eslint-disable-next-line no-underscore-dangle
filter._id = { $nin: [myId] };
}
// ensure higher levels
if (myLevel) {
filter['numbers.weight'] = { $lt: myLevel };
}

return getAdministrativeLevels({ ...optns, filter });
};

return (
<Form
labelCol={labelCol}
Expand Down Expand Up @@ -141,7 +160,9 @@ const AdministrativeLevelForm = ({
name={['relations', 'parent', '_id']}
>
<SearchableSelectInput
onSearch={getAdministrativeLevels}
onSearch={(optns = {}) => {
return searchAdministrativeLevels(optns, administrativeLevel);
}}
optionLabel={(parent) => get(parent, 'strings.name.en')}
optionValue="_id"
initialValue={get(
Expand Down
Loading

0 comments on commit a307f97

Please sign in to comment.