Skip to content

Commit a307f97

Browse files
committed
refactor(administrative-level): improve list layout
see #250
1 parent 77d95af commit a307f97

File tree

4 files changed

+352
-459
lines changed

4 files changed

+352
-459
lines changed

src/GeographicalFeatures/AdministrativeLevels/Filters/index.js

-232
This file was deleted.

src/GeographicalFeatures/AdministrativeLevels/Form/index.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ const AdministrativeLevelForm = ({
9090
}
9191
};
9292

93+
// search administrative level exclude self
94+
const searchAdministrativeLevels = (optns, me) => {
95+
const filter = {};
96+
const myId = get(me, '_id');
97+
const myLevel = get(me, 'numbers.weight');
98+
99+
// ignore self from selection
100+
if (myId) {
101+
// eslint-disable-next-line no-underscore-dangle
102+
filter._id = { $nin: [myId] };
103+
}
104+
// ensure higher levels
105+
if (myLevel) {
106+
filter['numbers.weight'] = { $lt: myLevel };
107+
}
108+
109+
return getAdministrativeLevels({ ...optns, filter });
110+
};
111+
93112
return (
94113
<Form
95114
labelCol={labelCol}
@@ -141,7 +160,9 @@ const AdministrativeLevelForm = ({
141160
name={['relations', 'parent', '_id']}
142161
>
143162
<SearchableSelectInput
144-
onSearch={getAdministrativeLevels}
163+
onSearch={(optns = {}) => {
164+
return searchAdministrativeLevels(optns, administrativeLevel);
165+
}}
145166
optionLabel={(parent) => get(parent, 'strings.name.en')}
146167
optionValue="_id"
147168
initialValue={get(

0 commit comments

Comments
 (0)