File tree 4 files changed +352
-459
lines changed
GeographicalFeatures/AdministrativeLevels
4 files changed +352
-459
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -90,6 +90,25 @@ const AdministrativeLevelForm = ({
90
90
}
91
91
} ;
92
92
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
+
93
112
return (
94
113
< Form
95
114
labelCol = { labelCol }
@@ -141,7 +160,9 @@ const AdministrativeLevelForm = ({
141
160
name = { [ 'relations' , 'parent' , '_id' ] }
142
161
>
143
162
< SearchableSelectInput
144
- onSearch = { getAdministrativeLevels }
163
+ onSearch = { ( optns = { } ) => {
164
+ return searchAdministrativeLevels ( optns , administrativeLevel ) ;
165
+ } }
145
166
optionLabel = { ( parent ) => get ( parent , 'strings.name.en' ) }
146
167
optionValue = "_id"
147
168
initialValue = { get (
You can’t perform that action at this time.
0 commit comments