@dartech/arsenal-ui 1.3.61 → 1.3.62

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.
package/index.js CHANGED
@@ -1057,23 +1057,21 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1057
1057
  error
1058
1058
  }
1059
1059
  } = _b;
1060
- // console.log('validateJson', validateJson, name);
1061
- // console.log('parseValue', parseValue, name);
1062
1060
  const extensions = useMemo(() => ({
1063
1061
  json: [langs.json()],
1064
1062
  javascript: [langs.javascript()],
1065
1063
  python: [langs.python()]
1066
1064
  }), []);
1067
1065
  const handleChange = useCallback(value => {
1068
- // console.log('handleChange', name, value);
1069
- // if (!value && required) {
1070
- // setError(name, { message: 'Required field' });
1071
- // } else {
1072
- // clearErrors(name);
1073
- // }
1066
+ if (!value && required) {
1067
+ setError(name, {
1068
+ message: 'Required field'
1069
+ });
1070
+ } else {
1071
+ clearErrors(name);
1072
+ }
1074
1073
  if (validateJson) {
1075
1074
  try {
1076
- // console.log('validateJson', JSON.parse(value), name);
1077
1075
  JSON.parse(value);
1078
1076
  clearErrors(name);
1079
1077
  } catch (error) {
@@ -1093,7 +1091,7 @@ const ControlAceEditor = /*#__PURE__*/forwardRef((_a, ref) => {
1093
1091
  } else {
1094
1092
  onChange(value);
1095
1093
  }
1096
- }, [setError, clearErrors, onChange, name, parseValue, validateJson]);
1094
+ }, [setError, clearErrors, onChange, name, parseValue, validateJson, required]);
1097
1095
  return jsxs(Box, Object.assign({
1098
1096
  display: "flex",
1099
1097
  flexDirection: "column",
@@ -3802,6 +3800,13 @@ const usePropertyFiller = ({
3802
3800
  return {};
3803
3801
  }
3804
3802
  }, [propertyType]);
3803
+ const checkFillOption = useCallback(() => {
3804
+ if (isExpression(value) && fillOption !== 'expression') {
3805
+ setFillOption('expression');
3806
+ } else if (value !== null && value !== undefined && !isExpression(value) && fillOption !== 'widget') {
3807
+ setFillOption('widget');
3808
+ }
3809
+ }, [value, fillOption]);
3805
3810
  useEffect(() => {
3806
3811
  if (!fillOption) {
3807
3812
  if (isPropertyValueEmpty(value) && (fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.length)) {
@@ -3812,13 +3817,9 @@ const usePropertyFiller = ({
3812
3817
  setFillOption('widget');
3813
3818
  }
3814
3819
  } else if (!isDirty) {
3815
- if (isExpression(value) && fillOption !== 'expression') {
3816
- setFillOption('expression');
3817
- } else if (value !== null && value !== undefined && !isExpression(value) && fillOption !== 'widget') {
3818
- setFillOption('widget');
3819
- }
3820
+ checkFillOption();
3820
3821
  }
3821
- }, [value, fillOption, fillOptions, _useExpression, isDirty]);
3822
+ }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption]);
3822
3823
  return {
3823
3824
  propertyType,
3824
3825
  valueLabel,
@@ -3826,7 +3827,8 @@ const usePropertyFiller = ({
3826
3827
  fillOption,
3827
3828
  fillOptions,
3828
3829
  setFillOption,
3829
- defaultProperyValue
3830
+ defaultProperyValue,
3831
+ checkFillOption
3830
3832
  };
3831
3833
  };
3832
3834
  var usePropertyFiller$1 = usePropertyFiller;
@@ -3933,7 +3935,7 @@ const PropertyFiller = ({
3933
3935
  }
3934
3936
  }, [isDirty, property, name, setValue]);
3935
3937
  useEffect(() => {
3936
- if (value === undefined || property.isRequired && value === null) {
3938
+ if (property.isRequired && !value) {
3937
3939
  setValue(name, defaultProperyValue);
3938
3940
  }
3939
3941
  }, [value, setValue, defaultProperyValue, property, name, isDirty]);
@@ -4157,6 +4159,8 @@ const MultiplePropertyFiller = ({
4157
4159
  label,
4158
4160
  title
4159
4161
  }) => {
4162
+ var _a;
4163
+ const [selectTouched, setSelectTouched] = useState(false);
4160
4164
  const {
4161
4165
  control,
4162
4166
  clearErrors,
@@ -4175,7 +4179,7 @@ const MultiplePropertyFiller = ({
4175
4179
  } = useController({
4176
4180
  control,
4177
4181
  name,
4178
- defaultValue: property.defaultValue,
4182
+ defaultValue: (_a = property.defaultValue) !== null && _a !== void 0 ? _a : [],
4179
4183
  rules: {
4180
4184
  validate: val => {
4181
4185
  if (required && !val) return 'Please, fill this field';
@@ -4189,7 +4193,8 @@ const MultiplePropertyFiller = ({
4189
4193
  fillOptionLabel,
4190
4194
  fillOption,
4191
4195
  fillOptions,
4192
- setFillOption
4196
+ setFillOption,
4197
+ checkFillOption
4193
4198
  } = usePropertyFiller$1({
4194
4199
  property,
4195
4200
  value,
@@ -4200,6 +4205,7 @@ const MultiplePropertyFiller = ({
4200
4205
  multipleOptions: true
4201
4206
  });
4202
4207
  const handleFillOptionChange = event => {
4208
+ setSelectTouched(true);
4203
4209
  const selectedType = event.target.value;
4204
4210
  if (selectedType === 'null') {
4205
4211
  setValue(name, null);
@@ -4216,6 +4222,11 @@ const MultiplePropertyFiller = ({
4216
4222
  onChange(property.isRequired ? [] : null);
4217
4223
  }
4218
4224
  }, [value, property, onChange]);
4225
+ useEffect(() => {
4226
+ if (value && !selectTouched) {
4227
+ checkFillOption();
4228
+ }
4229
+ }, [checkFillOption, selectTouched, value]);
4219
4230
  return jsxs(Grid$1, {
4220
4231
  children: [title && jsx(Box, Object.assign({
4221
4232
  mb: 2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.61",
3
+ "version": "1.3.62",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -21,5 +21,6 @@ declare const usePropertyFiller: ({ value, property, label, isDirty, required, u
21
21
  }[];
22
22
  setFillOption: import("react").Dispatch<import("react").SetStateAction<PropertyFillType>>;
23
23
  defaultProperyValue: {};
24
+ checkFillOption: () => void;
24
25
  };
25
26
  export default usePropertyFiller;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  format: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  type Props = {
2
3
  name: string;
3
4
  label?: string;
@@ -1,3 +1,4 @@
1
+ /// <reference types="react" />
1
2
  import { PropertyUnion } from '../../../interfaces';
2
3
  type PropertyItemProps = {
3
4
  property: PropertyUnion;