@@ -47,8 +47,6 @@ function Landmarks() {
47
47
// local state
48
48
const [ selected , setSelected ] = React . useState ( null ) ;
49
49
const [ noLandmarks , setNoLandmarks ] = React . useState ( defaultNoLandmarks ) ;
50
- const [ needsLabel , setNeedsLabel ] = React . useState ( [ ] ) ;
51
- const [ labelsTemp , setLabelsTemp ] = React . useState ( { } ) ;
52
50
const [ openedDropdown , setOpenedDropdown ] = React . useState ( null ) ;
53
51
const [ maxUsageReached , setMaxUsageReached ] = React . useState ( [ ] ) ;
54
52
@@ -63,9 +61,8 @@ function Landmarks() {
63
61
const [ alwaysNeedLabel , setAlwaysNeedLabel ] = React . useState ( [ ] ) ;
64
62
const showAlwaysNeedLabel = alwaysNeedLabel . length > 0 ;
65
63
66
- const showWarning =
67
- needsLabel . length > 0 &&
68
- Object . keys ( labelsTemp ) . length !== needsLabel . length ;
64
+ const [ hasLandmarkWord , setHasLandmarkWord ] = React . useState ( [ ] ) ;
65
+ const showLandmarkWordWarning = hasLandmarkWord . length > 0 ;
69
66
70
67
const onAddLandmark = ( landmarkType ) => {
71
68
const { bounds, id } = page ;
@@ -213,6 +210,22 @@ function Landmarks() {
213
210
setMaxUsageReached ( newMaxUsageReached ) ;
214
211
} ;
215
212
213
+ const checkForLandmarkInLabel = ( ) => {
214
+ const hasLandmarkInLabel = [ ] ;
215
+
216
+ Object . keys ( labelsTemp ) . forEach ( ( key ) => {
217
+ const label = labelsTemp [ key ] ;
218
+ const labelLower = label . value . toLowerCase ( ) ;
219
+
220
+ // "landmark" string exists?
221
+ if ( labelLower . includes ( 'landmark' ) ) {
222
+ hasLandmarkInLabel . push ( key ) ;
223
+ }
224
+ } ) ;
225
+
226
+ setHasLandmarkWord ( hasLandmarkInLabel ) ;
227
+ } ;
228
+
216
229
const onChange = ( e , id ) => {
217
230
const newLabelsTemp = { ...labelsTemp } ;
218
231
@@ -247,12 +260,18 @@ function Landmarks() {
247
260
checkForMaxUsage ( ) ;
248
261
} , [ landmarks ] ) ;
249
262
263
+ React . useEffect ( ( ) => {
264
+ // mount
265
+ checkForLandmarkInLabel ( ) ;
266
+ } , [ labelsTemp ] ) ;
267
+
250
268
const getPrimaryAction = ( ) => {
251
269
if ( landmarksAreSet || noLandmarks ) {
252
270
return {
253
271
completesStep : true ,
254
272
isDisabled :
255
- ( showDupWarning || showAlwaysNeedLabel ) && canContinue === false ,
273
+ ( showDupWarning || showAlwaysNeedLabel || showLandmarkWordWarning ) &&
274
+ canContinue === false ,
256
275
onClick : onDoneWithLandmarks
257
276
} ;
258
277
}
@@ -296,6 +315,18 @@ function Landmarks() {
296
315
</ React . Fragment >
297
316
) }
298
317
318
+ { showLandmarkWordWarning && (
319
+ < React . Fragment >
320
+ < Alert
321
+ icon = { < SvgWarning /> }
322
+ style = { { padding : 0 } }
323
+ text = { `Remove the word "landmark" as it is already included in the landmark type.` }
324
+ type = "warning"
325
+ />
326
+ < div className = "spacer1" />
327
+ </ React . Fragment >
328
+ ) }
329
+
299
330
{ landmarksAreSet && (
300
331
< React . Fragment >
301
332
{ landmarksArray . map ( ( key ) => {
@@ -306,9 +337,10 @@ function Landmarks() {
306
337
307
338
const hasTempLabel = labelsTemp [ id ] ?. value || label ;
308
339
309
- // is flagged for not having label
340
+ // is flagged for not having label (or can't have "Landmark" in the label)
310
341
const warnClass =
311
- needsLabel . includes ( id ) && hasTempLabel === null
342
+ ( needsLabel . includes ( id ) && hasTempLabel === null ) ||
343
+ hasLandmarkWord . includes ( id )
312
344
? ' warning'
313
345
: '' ;
314
346
0 commit comments