@flozy/editor 10.4.7 → 10.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -67,7 +67,7 @@ const SelectV1 = props => {
67
67
  setAvailableOptionsMap(obj);
68
68
  }, [availableOptions]);
69
69
  useEffect(() => {
70
- const resolved = selectedOptions?.map(sel => availableOptionsMap?.[sel?.id]) ?? [];
70
+ const resolved = selectedOptions?.filter(sel => sel?.id && availableOptionsMap?.[sel.id])?.map(sel => availableOptionsMap[sel?.id]) ?? [];
71
71
  setResolvedSelectedOptions(resolved);
72
72
  }, [selectedOptions, availableOptionsMap]);
73
73
  useEffect(() => {
@@ -14,11 +14,12 @@ const EditOption = props => {
14
14
  onClose,
15
15
  mode,
16
16
  onEvent,
17
- translation = () => {}
17
+ translation
18
18
  } = props;
19
19
  const [edit, setEdit] = useState({
20
20
  ...(mode?.edit || {})
21
21
  });
22
+ const [errorMessage, setErrorMessage] = useState("");
22
23
  const editData = useRef({
23
24
  ...edit
24
25
  });
@@ -31,10 +32,13 @@ const EditOption = props => {
31
32
  const selectedOption = edit?.options[optionIndex] || {};
32
33
  const pickerStyles = ColorPickerStyles(theme);
33
34
  const hideBackButton = edit?.hideBackButton || false;
35
+ const errorMessageRef = useRef(errorMessage);
36
+ useEffect(() => {
37
+ errorMessageRef.current = errorMessage;
38
+ }, [errorMessage]);
34
39
  useEffect(() => {
35
40
  return () => {
36
- // on un-mount update the option change
37
- if (editData?.current) {
41
+ if (editData?.current && !errorMessageRef.current) {
38
42
  delete editData?.current?.edited;
39
43
  onEvent("updateProperty", {
40
44
  ...editData?.current
@@ -43,18 +47,24 @@ const EditOption = props => {
43
47
  };
44
48
  }, []);
45
49
  const onChange = e => {
46
- const updatedOptions = edit?.options.map((m, i) => {
50
+ const {
51
+ name,
52
+ value,
53
+ delete: isDelete
54
+ } = e?.target || {};
55
+ const targetValue = value?.toLowerCase();
56
+ const updatedOptions = edit?.options?.map((m, i) => {
47
57
  if (i === edit?.optionIndex) {
48
58
  return {
49
59
  ...m,
50
- [e.target.name]: e?.target?.value
60
+ [name]: value
51
61
  };
52
62
  }
53
63
  return m;
54
64
  });
55
65
 
56
- // for delete
57
- if (edit?.optionIndex > -1 && e?.target?.delete) {
66
+ // If deleting the option
67
+ if (edit?.optionIndex > -1 && isDelete) {
58
68
  updatedOptions.splice(edit?.optionIndex, 1);
59
69
  }
60
70
  const latest = {
@@ -68,14 +78,28 @@ const EditOption = props => {
68
78
  ...latest,
69
79
  edited: true
70
80
  };
81
+ if (name === "value" && !value?.trim()) {
82
+ setErrorMessage("Option name must not be empty");
83
+ return;
84
+ }
85
+ const isDuplicate = name === "value" && targetValue && edit?.options?.some((op, i) => i !== edit?.optionIndex && op?.value?.toLowerCase?.() === targetValue);
86
+ if (isDuplicate) {
87
+ setErrorMessage("Option name must be unique");
88
+ return;
89
+ }
90
+ setErrorMessage(""); // Clear error on valid input
71
91
 
72
- // if delete go back
73
- if (e?.target?.delete) {
74
- onEvent("editProperty", {
75
- edit: {
76
- ...latest
77
- }
78
- });
92
+ // If delete go back
93
+ if (isDelete) {
94
+ if (hideBackButton) {
95
+ onClose();
96
+ } else {
97
+ onEvent("editProperty", {
98
+ edit: {
99
+ ...latest
100
+ }
101
+ });
102
+ }
79
103
  }
80
104
  };
81
105
  const onBack = () => {
@@ -137,7 +161,9 @@ const EditOption = props => {
137
161
  value: selectedOption?.value,
138
162
  onChange: onChange,
139
163
  fullWidth: true,
140
- placeholder: translation("Option Name")
164
+ placeholder: translation("Option Name"),
165
+ helperText: errorMessage,
166
+ error: !!errorMessage
141
167
  }),
142
168
  labelPlacement: "top"
143
169
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flozy/editor",
3
- "version": "10.4.7",
3
+ "version": "10.4.8",
4
4
  "description": "An Editor for flozy app brain",
5
5
  "files": [
6
6
  "dist"