Skip to content

Commit befe3d2

Browse files
committed
restricted state name to be from PossibleTransitionValues
1 parent ba680ac commit befe3d2

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/components/Editor.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ export const Editor = () => {
204204
return;
205205
}
206206

207+
if (PossibleTransitionValues.includes(row.state)) {
208+
setAlertMessage(
209+
`State name cannot be ${PossibleTransitionValues.join(", ")}`
210+
);
211+
return;
212+
}
213+
207214
PossibleTransitionValues.forEach(
208215
(key) =>
209216
(row[key === "^" ? "nul" : key] = Array.from(

src/utils/PromptNewStateName.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { DraggableStateModel } from "../models";
22
import { StateNameMaxLength } from "../consts/StateNameMaxLength";
3+
import { PossibleTransitionValues } from "../consts/PossibleTransitionValues";
34

45
export const promptNewStateName = (
56
states: DraggableStateModel[],
@@ -9,7 +10,8 @@ export const promptNewStateName = (
910
while (
1011
!newName ||
1112
(newName && [...states].map((s) => s.id).includes(newName)) ||
12-
newName.length > StateNameMaxLength
13+
newName.length > StateNameMaxLength ||
14+
PossibleTransitionValues.includes(newName)
1315
) {
1416
if (!newName)
1517
newName = prompt(
@@ -26,6 +28,13 @@ export const promptNewStateName = (
2628
`State name cannot be more than ${StateNameMaxLength} characters.`,
2729
originalName
2830
);
31+
else if (PossibleTransitionValues.includes(newName))
32+
newName = prompt(
33+
`State name cannot be one of the following: ${PossibleTransitionValues.join(
34+
", "
35+
)}`,
36+
originalName
37+
);
2938
}
3039
return newName;
3140
};

0 commit comments

Comments
 (0)