Skip to content

Commit 40721b6

Browse files
committed
Don't allow text "Landmark" in label
1 parent 4df6a59 commit 40721b6

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

src/pages/Landmarks.js

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ function Landmarks() {
4747
// local state
4848
const [selected, setSelected] = React.useState(null);
4949
const [noLandmarks, setNoLandmarks] = React.useState(defaultNoLandmarks);
50-
const [needsLabel, setNeedsLabel] = React.useState([]);
51-
const [labelsTemp, setLabelsTemp] = React.useState({});
5250
const [openedDropdown, setOpenedDropdown] = React.useState(null);
5351
const [maxUsageReached, setMaxUsageReached] = React.useState([]);
5452

@@ -63,9 +61,8 @@ function Landmarks() {
6361
const [alwaysNeedLabel, setAlwaysNeedLabel] = React.useState([]);
6462
const showAlwaysNeedLabel = alwaysNeedLabel.length > 0;
6563

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;
6966

7067
const onAddLandmark = (landmarkType) => {
7168
const { bounds, id } = page;
@@ -213,6 +210,22 @@ function Landmarks() {
213210
setMaxUsageReached(newMaxUsageReached);
214211
};
215212

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+
216229
const onChange = (e, id) => {
217230
const newLabelsTemp = { ...labelsTemp };
218231

@@ -247,12 +260,18 @@ function Landmarks() {
247260
checkForMaxUsage();
248261
}, [landmarks]);
249262

263+
React.useEffect(() => {
264+
// mount
265+
checkForLandmarkInLabel();
266+
}, [labelsTemp]);
267+
250268
const getPrimaryAction = () => {
251269
if (landmarksAreSet || noLandmarks) {
252270
return {
253271
completesStep: true,
254272
isDisabled:
255-
(showDupWarning || showAlwaysNeedLabel) && canContinue === false,
273+
(showDupWarning || showAlwaysNeedLabel || showLandmarkWordWarning) &&
274+
canContinue === false,
256275
onClick: onDoneWithLandmarks
257276
};
258277
}
@@ -296,6 +315,18 @@ function Landmarks() {
296315
</React.Fragment>
297316
)}
298317

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+
299330
{landmarksAreSet && (
300331
<React.Fragment>
301332
{landmarksArray.map((key) => {
@@ -306,9 +337,10 @@ function Landmarks() {
306337

307338
const hasTempLabel = labelsTemp[id]?.value || label;
308339

309-
// is flagged for not having label
340+
// is flagged for not having label (or can't have "Landmark" in the label)
310341
const warnClass =
311-
needsLabel.includes(id) && hasTempLabel === null
342+
(needsLabel.includes(id) && hasTempLabel === null) ||
343+
hasLandmarkWord.includes(id)
312344
? ' warning'
313345
: '';
314346

0 commit comments

Comments
 (0)