@dartech/arsenal-ui 1.3.61 → 1.3.63

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",
@@ -1216,22 +1214,10 @@ const JsonView = ({
1216
1214
  height: _height = '200px',
1217
1215
  fontSize: _fontSize = 16
1218
1216
  }) => {
1219
- const stringValue = useMemo(() => {
1220
- if (typeof value === 'string') {
1221
- return value;
1222
- } else if (typeof value === 'object') {
1223
- try {
1224
- return JSON.stringify(value, null, 2);
1225
- } catch (error) {
1226
- return 'Failed to stringify Object';
1227
- }
1228
- }
1229
- return '';
1230
- }, [value]);
1231
1217
  return jsx(CodeMirror, {
1232
1218
  readOnly: true,
1233
1219
  width: "100%",
1234
- value: stringValue,
1220
+ value: typeof value === 'string' ? value : JSON.stringify(value, null, 2),
1235
1221
  height: _height,
1236
1222
  basicSetup: {
1237
1223
  autocompletion: true,
@@ -3717,17 +3703,16 @@ const PropertyWidget = ({
3717
3703
  });
3718
3704
  // return <JsonEditor validate name={name} ref={ref} useParsedValue />;
3719
3705
  case PropertyType.STRING:
3720
- return jsx(StringValueField$1
3721
- // required={!property.isRequired}
3722
- , {
3723
- // required={!property.isRequired}
3706
+ return jsx(StringValueField$1, {
3724
3707
  name: name,
3725
3708
  label: label,
3726
3709
  restrictedValues: property.restrictedValues
3727
3710
  });
3728
3711
  case PropertyType.ENTITY_REFERENCE:
3729
- return jsx(ControlInput, {
3730
- required: true,
3712
+ return jsx(ControlInput
3713
+ // required
3714
+ , {
3715
+ // required
3731
3716
  hideErrorMessage: true,
3732
3717
  name: name,
3733
3718
  label: label,
@@ -3802,6 +3787,13 @@ const usePropertyFiller = ({
3802
3787
  return {};
3803
3788
  }
3804
3789
  }, [propertyType]);
3790
+ const checkFillOption = useCallback(() => {
3791
+ if (isExpression(value) && fillOption !== 'expression') {
3792
+ setFillOption('expression');
3793
+ } else if (value !== null && value !== undefined && !isExpression(value) && fillOption !== 'widget' && fillOption !== 'string') {
3794
+ setFillOption('widget');
3795
+ }
3796
+ }, [value, fillOption]);
3805
3797
  useEffect(() => {
3806
3798
  if (!fillOption) {
3807
3799
  if (isPropertyValueEmpty(value) && (fillOptions === null || fillOptions === void 0 ? void 0 : fillOptions.length)) {
@@ -3812,13 +3804,9 @@ const usePropertyFiller = ({
3812
3804
  setFillOption('widget');
3813
3805
  }
3814
3806
  } 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
- }
3807
+ checkFillOption();
3820
3808
  }
3821
- }, [value, fillOption, fillOptions, _useExpression, isDirty]);
3809
+ }, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption]);
3822
3810
  return {
3823
3811
  propertyType,
3824
3812
  valueLabel,
@@ -3826,7 +3814,8 @@ const usePropertyFiller = ({
3826
3814
  fillOption,
3827
3815
  fillOptions,
3828
3816
  setFillOption,
3829
- defaultProperyValue
3817
+ defaultProperyValue,
3818
+ checkFillOption
3830
3819
  };
3831
3820
  };
3832
3821
  var usePropertyFiller$1 = usePropertyFiller;
@@ -3866,7 +3855,10 @@ const PropertyFiller = ({
3866
3855
  control,
3867
3856
  defaultValue: property.defaultValue,
3868
3857
  rules: {
3869
- required
3858
+ validate: val => {
3859
+ if (required && val === null) return 'Please, fill this field555';
3860
+ return true;
3861
+ }
3870
3862
  }
3871
3863
  });
3872
3864
  const {
@@ -3919,7 +3911,6 @@ const PropertyFiller = ({
3919
3911
  setValue(name, definitionValue);
3920
3912
  } catch (error) {
3921
3913
  setValue(name, defaultArrayValue);
3922
- // console.log('Parse failed');
3923
3914
  }
3924
3915
  } else {
3925
3916
  setValue(name, defaultArrayValue);
@@ -3933,10 +3924,10 @@ const PropertyFiller = ({
3933
3924
  }
3934
3925
  }, [isDirty, property, name, setValue]);
3935
3926
  useEffect(() => {
3936
- if (value === undefined || property.isRequired && value === null) {
3927
+ if (value === undefined || property.isRequired && value === null && !property.defaultValue) {
3937
3928
  setValue(name, defaultProperyValue);
3938
3929
  }
3939
- }, [value, setValue, defaultProperyValue, property, name, isDirty]);
3930
+ }, [value, setValue, defaultProperyValue, property, name]);
3940
3931
  return jsxs(Grid$1, Object.assign({
3941
3932
  xs: 12
3942
3933
  }, {
@@ -3973,9 +3964,7 @@ const PropertyFiller = ({
3973
3964
  }), option.value))
3974
3965
  }))]
3975
3966
  }))
3976
- })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ?
3977
- // <JsonEditor validate name={name} useParsedValue />
3978
- jsx(ControlAceEditor, {
3967
+ })) : null, fillOption === 'expression' && (propertyType === PropertyType.JSON || propertyType === PropertyType.ENTITY || propertyType === PropertyType.ANY ? jsx(ControlAceEditor, {
3979
3968
  name: name,
3980
3969
  control: control,
3981
3970
  label: valueLabel,
@@ -3986,17 +3975,13 @@ const PropertyFiller = ({
3986
3975
  control: control,
3987
3976
  name: name,
3988
3977
  label: valueLabel,
3989
- required: true,
3990
3978
  hideErrorMessage: true
3991
3979
  })), fillOption === 'string' && jsx(ControlInput, {
3992
3980
  control: control,
3993
3981
  name: name,
3994
3982
  label: valueLabel,
3995
- required: true,
3996
3983
  hideErrorMessage: true
3997
- }), fillOption === 'json_notvalid' &&
3998
- // <JsonEditor validate name={name} />
3999
- jsx(ControlAceEditor, {
3984
+ }), fillOption === 'json_notvalid' && jsx(ControlAceEditor, {
4000
3985
  name: name,
4001
3986
  control: control,
4002
3987
  label: valueLabel,
@@ -4006,8 +3991,7 @@ const PropertyFiller = ({
4006
3991
  property: property,
4007
3992
  name: name,
4008
3993
  useExpression: useExpression,
4009
- label: valueLabel,
4010
- required: required
3994
+ label: valueLabel
4011
3995
  }), fillOption === 'dem_builder' && jsx(CreateDefinition, {
4012
3996
  title: "JSON",
4013
3997
  definitionFieldName: name
@@ -4157,6 +4141,8 @@ const MultiplePropertyFiller = ({
4157
4141
  label,
4158
4142
  title
4159
4143
  }) => {
4144
+ var _a;
4145
+ const [selectTouched, setSelectTouched] = useState(false);
4160
4146
  const {
4161
4147
  control,
4162
4148
  clearErrors,
@@ -4175,7 +4161,7 @@ const MultiplePropertyFiller = ({
4175
4161
  } = useController({
4176
4162
  control,
4177
4163
  name,
4178
- defaultValue: property.defaultValue,
4164
+ defaultValue: (_a = property.defaultValue) !== null && _a !== void 0 ? _a : [],
4179
4165
  rules: {
4180
4166
  validate: val => {
4181
4167
  if (required && !val) return 'Please, fill this field';
@@ -4189,7 +4175,8 @@ const MultiplePropertyFiller = ({
4189
4175
  fillOptionLabel,
4190
4176
  fillOption,
4191
4177
  fillOptions,
4192
- setFillOption
4178
+ setFillOption,
4179
+ checkFillOption
4193
4180
  } = usePropertyFiller$1({
4194
4181
  property,
4195
4182
  value,
@@ -4200,6 +4187,7 @@ const MultiplePropertyFiller = ({
4200
4187
  multipleOptions: true
4201
4188
  });
4202
4189
  const handleFillOptionChange = event => {
4190
+ setSelectTouched(true);
4203
4191
  const selectedType = event.target.value;
4204
4192
  if (selectedType === 'null') {
4205
4193
  setValue(name, null);
@@ -4216,6 +4204,11 @@ const MultiplePropertyFiller = ({
4216
4204
  onChange(property.isRequired ? [] : null);
4217
4205
  }
4218
4206
  }, [value, property, onChange]);
4207
+ useEffect(() => {
4208
+ if (value && !selectTouched) {
4209
+ checkFillOption();
4210
+ }
4211
+ }, [checkFillOption, selectTouched, value]);
4219
4212
  return jsxs(Grid$1, {
4220
4213
  children: [title && jsx(Box, Object.assign({
4221
4214
  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.63",
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;
@@ -6,7 +6,6 @@ type Props = {
6
6
  name: string;
7
7
  label?: string;
8
8
  useExpression?: boolean;
9
- required?: boolean;
10
9
  control: Control<any>;
11
10
  };
12
11
  export declare const PropertyWidget: ({ property, name, label, useExpression, control }: Props) => JSX.Element;
@@ -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;