@dartech/arsenal-ui 1.4.1 → 1.4.3
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 +58 -36
- package/package.json +1 -1
- package/src/interfaces/definition.d.ts +0 -3
- package/src/lib/Definition/CreateDefinition/CreateDefinition.d.ts +2 -0
- package/src/lib/Forms/ControlArrayInput.d.ts +2 -1
- package/src/lib/Property/UpsertProperty/CreatePropertiesListContext.d.ts +3 -1
- package/src/lib/Property/UpsertProperty/PropertyValueField/BooleanValueField.d.ts +1 -0
- package/src/lib/Property/UpsertProperty/PropertyValueField/DateTimeValueField.d.ts +1 -0
- package/src/lib/Property/UpsertProperty/PropertyValueField/DateValueField.d.ts +1 -0
- package/src/lib/Property/UpsertProperty/PropertyValueField/JsonValueField.d.ts +1 -0
- package/src/lib/Property/UpsertProperty/PropertyValueField/TimeValueField.d.ts +1 -0
- package/src/lib/Property/ViewProperty/PropertyItem.d.ts +1 -0
package/index.js
CHANGED
@@ -746,12 +746,12 @@ const ControlAutocomplete = _a => {
|
|
746
746
|
labelKey
|
747
747
|
});
|
748
748
|
const handleChange = (_, value) => {
|
749
|
-
onChange(useStringValue ? value
|
749
|
+
onChange(useStringValue ? _get(value, valueKey) : value);
|
750
750
|
setLocalValue(value);
|
751
751
|
};
|
752
752
|
useEffect(() => {
|
753
753
|
if (typeof value === 'string' && valueKey && useStringValue && !localValue && options.length && !!options[0] && typeof options[0] === 'object') {
|
754
|
-
setLocalValue(options.find(el => el
|
754
|
+
setLocalValue(options.find(el => _get(el, valueKey) === value));
|
755
755
|
} else setLocalValue(value);
|
756
756
|
}, [localValue, options, useStringValue, value, valueKey]);
|
757
757
|
return jsx(Autocomplete, Object.assign({}, fieldProps, {
|
@@ -867,11 +867,11 @@ function ControlQueryAutocomplete(_a) {
|
|
867
867
|
if (!isDirty && formValue && itemQueryFunction) {
|
868
868
|
let requestValue = formValue;
|
869
869
|
if (typeof formValue === 'object' && valueKey in formValue) {
|
870
|
-
requestValue = formValue
|
870
|
+
requestValue = _get(formValue, valueKey);
|
871
871
|
}
|
872
872
|
itemQueryFunction(requestValue).then(item => {
|
873
873
|
setFieldValue(item);
|
874
|
-
setInputValue(item
|
874
|
+
setInputValue(_get(item, labelKey));
|
875
875
|
}).catch();
|
876
876
|
}
|
877
877
|
}, [formValue, isDirty, valueKey, labelKey, itemQueryFunction, setFieldValue]);
|
@@ -1507,7 +1507,7 @@ const isPropertyValueEmpty = value => {
|
|
1507
1507
|
return true;
|
1508
1508
|
};
|
1509
1509
|
const formatPropertyValue = (propertyType, value, params) => {
|
1510
|
-
if (
|
1510
|
+
if (value === null || value === undefined) {
|
1511
1511
|
return null;
|
1512
1512
|
}
|
1513
1513
|
let parsedValue = value;
|
@@ -1516,8 +1516,10 @@ const formatPropertyValue = (propertyType, value, params) => {
|
|
1516
1516
|
case PropertyType.BOOLEAN:
|
1517
1517
|
if (value) {
|
1518
1518
|
parsedValue = true;
|
1519
|
-
} else {
|
1519
|
+
} else if (!value && value !== null) {
|
1520
1520
|
parsedValue = false;
|
1521
|
+
} else {
|
1522
|
+
parsedValue = null;
|
1521
1523
|
}
|
1522
1524
|
break;
|
1523
1525
|
case PropertyType.INTEGER:
|
@@ -1627,15 +1629,12 @@ const propertiesArrayToObject = (properties, isGlobalParameter) => {
|
|
1627
1629
|
name,
|
1628
1630
|
isRequired,
|
1629
1631
|
isMultiple,
|
1630
|
-
isVisible,
|
1631
|
-
isFillable,
|
1632
|
-
isEditable,
|
1633
1632
|
sortOrder,
|
1634
1633
|
isEnabled,
|
1635
1634
|
uiSettings,
|
1636
1635
|
validationNode
|
1637
1636
|
} = property;
|
1638
|
-
const propertyType = typeof property.propertyType === 'string' ? property.propertyType : property.propertyType.value;
|
1637
|
+
const propertyType = property.propertyType ? typeof property.propertyType === 'string' ? property.propertyType : property.propertyType.value : null;
|
1639
1638
|
const resultProperty = Object.assign({
|
1640
1639
|
name,
|
1641
1640
|
propertyType,
|
@@ -1648,9 +1647,6 @@ const propertiesArrayToObject = (properties, isGlobalParameter) => {
|
|
1648
1647
|
}, getPropertyValue(Object.assign(Object.assign({}, property), {
|
1649
1648
|
propertyType
|
1650
1649
|
}), isGlobalParameter));
|
1651
|
-
if (isVisible !== undefined) resultProperty.isVisible = isVisible;
|
1652
|
-
if (isFillable !== undefined) resultProperty.isFillable = isFillable;
|
1653
|
-
if (isEditable !== undefined) resultProperty.isEditable = isEditable;
|
1654
1650
|
if ('isViewableInList' in property) {
|
1655
1651
|
resultProperty['isViewableInList'] = property.isViewableInList;
|
1656
1652
|
}
|
@@ -2283,10 +2279,12 @@ const ControlArrayInput = ({
|
|
2283
2279
|
name,
|
2284
2280
|
control,
|
2285
2281
|
label,
|
2286
|
-
required
|
2282
|
+
required,
|
2283
|
+
defaultValue: _defaultValue = null
|
2287
2284
|
}) => {
|
2288
2285
|
var _a, _b, _c;
|
2289
2286
|
const [localValue, setLoacalValue] = useState('');
|
2287
|
+
const [error, setError] = useState(null);
|
2290
2288
|
const {
|
2291
2289
|
field: {
|
2292
2290
|
onChange,
|
@@ -2298,22 +2296,25 @@ const ControlArrayInput = ({
|
|
2298
2296
|
}
|
2299
2297
|
} = useController({
|
2300
2298
|
control,
|
2301
|
-
name
|
2299
|
+
name,
|
2300
|
+
defaultValue: _defaultValue
|
2302
2301
|
});
|
2303
2302
|
const handleInputChange = useCallback(e => {
|
2304
2303
|
const {
|
2305
2304
|
value
|
2306
2305
|
} = e.target;
|
2307
2306
|
setLoacalValue(value);
|
2308
|
-
|
2309
|
-
}, [values]);
|
2307
|
+
}, []);
|
2310
2308
|
const handleAdd = useCallback(() => {
|
2311
2309
|
var _a;
|
2312
|
-
|
2310
|
+
setError(null);
|
2311
|
+
if (localValue && !((_a = errors[name]) === null || _a === void 0 ? void 0 : _a.message) && !(Array.isArray(values) && values.includes(localValue))) {
|
2313
2312
|
onChange([...(values !== null && values !== void 0 ? values : []), localValue]);
|
2314
2313
|
setLoacalValue('');
|
2314
|
+
} else if (Array.isArray(values) && values.includes(localValue)) {
|
2315
|
+
setError('This value already exists');
|
2315
2316
|
}
|
2316
|
-
}, [localValue,
|
2317
|
+
}, [localValue, errors, name, onChange, values]);
|
2317
2318
|
const handleDelete = useCallback(value => {
|
2318
2319
|
onChange(values.filter(code => code !== value));
|
2319
2320
|
}, [values, onChange]);
|
@@ -2329,7 +2330,7 @@ const ControlArrayInput = ({
|
|
2329
2330
|
variant: "subtitle1"
|
2330
2331
|
}, {
|
2331
2332
|
children: required ? jsxs(Fragment, {
|
2332
|
-
children: [label,
|
2333
|
+
children: [label, ' ', jsx(Box, Object.assign({
|
2333
2334
|
component: "span",
|
2334
2335
|
color: "#D6331F"
|
2335
2336
|
}, {
|
@@ -2377,7 +2378,11 @@ const ControlArrayInput = ({
|
|
2377
2378
|
})
|
2378
2379
|
}))
|
2379
2380
|
}
|
2380
|
-
})
|
2381
|
+
}), error && jsx(FormHelperText, Object.assign({
|
2382
|
+
error: true
|
2383
|
+
}, {
|
2384
|
+
children: error
|
2385
|
+
}))]
|
2381
2386
|
});
|
2382
2387
|
};
|
2383
2388
|
|
@@ -4008,7 +4013,7 @@ const usePropertyFiller = ({
|
|
4008
4013
|
case PropertyType.JSON:
|
4009
4014
|
return {};
|
4010
4015
|
case PropertyType.BOOLEAN:
|
4011
|
-
return
|
4016
|
+
return false;
|
4012
4017
|
case PropertyType.INTEGER:
|
4013
4018
|
case PropertyType.BIG_DECIMAL:
|
4014
4019
|
case PropertyType.BIG_INTEGER:
|
@@ -4030,8 +4035,8 @@ const usePropertyFiller = ({
|
|
4030
4035
|
}, [value, fillOption, needRecursionCheck]);
|
4031
4036
|
useEffect(() => {
|
4032
4037
|
if (!fillOption) {
|
4033
|
-
if (isPropertyValueEmpty(value) && (
|
4034
|
-
setFillOption(
|
4038
|
+
if (isPropertyValueEmpty(value) && !property.isRequired && (property.defaultValue === null || property.value === null)) {
|
4039
|
+
setFillOption('null');
|
4035
4040
|
} else if (_useExpression && isExpression(value, needRecursionCheck)) {
|
4036
4041
|
setFillOption('expression');
|
4037
4042
|
} else {
|
@@ -4040,7 +4045,7 @@ const usePropertyFiller = ({
|
|
4040
4045
|
} else if (!isDirty) {
|
4041
4046
|
checkFillOption();
|
4042
4047
|
}
|
4043
|
-
}, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption, needRecursionCheck]);
|
4048
|
+
}, [value, fillOption, fillOptions, _useExpression, isDirty, checkFillOption, needRecursionCheck, _required, property]);
|
4044
4049
|
return {
|
4045
4050
|
propertyType,
|
4046
4051
|
valueLabel,
|
@@ -4248,6 +4253,7 @@ const ControlPropertyFiller = ({
|
|
4248
4253
|
entityReferenceValueComponent: entityReferenceValueComponent,
|
4249
4254
|
fileReferenceValueComponent: fileReferenceValueComponent
|
4250
4255
|
}), fillOption === 'dem_builder' && jsx(CreateDefinition, {
|
4256
|
+
control: control,
|
4251
4257
|
title: "JSON",
|
4252
4258
|
definitionFieldName: name,
|
4253
4259
|
entityReferenceDefinitionSources: entityReferenceDefinitionSources,
|
@@ -5329,6 +5335,7 @@ const defaultPropertyValues = {
|
|
5329
5335
|
uiSettings: ''
|
5330
5336
|
};
|
5331
5337
|
const CreatePropertiesListContext = ({
|
5338
|
+
control,
|
5332
5339
|
parentFieldName,
|
5333
5340
|
hideAddButton,
|
5334
5341
|
focusOnIndex,
|
@@ -5343,9 +5350,9 @@ const CreatePropertiesListContext = ({
|
|
5343
5350
|
}) => {
|
5344
5351
|
var _a;
|
5345
5352
|
const fieldName = useMemo(() => parentFieldName ? `${parentFieldName}.properties` : `properties`, [parentFieldName]);
|
5353
|
+
// const { } = useControler({ name: fieldName })
|
5346
5354
|
const {
|
5347
5355
|
clearErrors,
|
5348
|
-
control,
|
5349
5356
|
setValue
|
5350
5357
|
} = useFormContext();
|
5351
5358
|
const {
|
@@ -5459,6 +5466,7 @@ const CreatePropertiesListContext = ({
|
|
5459
5466
|
};
|
5460
5467
|
|
5461
5468
|
const CreateDefinition = /*#__PURE__*/forwardRef(({
|
5469
|
+
control: extControl,
|
5462
5470
|
definitionFieldName,
|
5463
5471
|
title,
|
5464
5472
|
hideCodeField,
|
@@ -5496,7 +5504,7 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
|
|
5496
5504
|
}, {
|
5497
5505
|
children: jsx(ControlInput, {
|
5498
5506
|
required: true,
|
5499
|
-
control: control,
|
5507
|
+
control: extControl !== null && extControl !== void 0 ? extControl : control,
|
5500
5508
|
name: definitionFieldName ? `${definitionFieldName}.name` : `name`,
|
5501
5509
|
label: "Name"
|
5502
5510
|
})
|
@@ -5505,7 +5513,7 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
|
|
5505
5513
|
}, {
|
5506
5514
|
children: jsx(ControlInput, {
|
5507
5515
|
required: true,
|
5508
|
-
control: control,
|
5516
|
+
control: extControl !== null && extControl !== void 0 ? extControl : control,
|
5509
5517
|
name: definitionFieldName ? `${definitionFieldName}.code` : `code`,
|
5510
5518
|
label: "Code"
|
5511
5519
|
})
|
@@ -5514,7 +5522,7 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
|
|
5514
5522
|
}, {
|
5515
5523
|
children: jsx(ControlNumberInput, {
|
5516
5524
|
required: true,
|
5517
|
-
control: control,
|
5525
|
+
control: extControl !== null && extControl !== void 0 ? extControl : control,
|
5518
5526
|
name: definitionFieldName ? `${definitionFieldName}.version` : `version`,
|
5519
5527
|
label: "Version"
|
5520
5528
|
})
|
@@ -5527,6 +5535,7 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
|
|
5527
5535
|
entityReferenceValueComponent: entityReferenceValueComponent,
|
5528
5536
|
fileReferenceValueComponent: fileReferenceValueComponent
|
5529
5537
|
}) : jsx(CreatePropertiesListContext, {
|
5538
|
+
control: extControl,
|
5530
5539
|
required: _required,
|
5531
5540
|
parentFieldName: definitionFieldName,
|
5532
5541
|
entityReferenceDefinitionSources: entityReferenceDefinitionSources,
|
@@ -5829,7 +5838,6 @@ const PropertyFiller = ({
|
|
5829
5838
|
} = useController({
|
5830
5839
|
name,
|
5831
5840
|
control,
|
5832
|
-
defaultValue: property.defaultValue,
|
5833
5841
|
rules: {
|
5834
5842
|
validate: val => {
|
5835
5843
|
if (required && val === null) return 'Please, fill this field';
|
@@ -5837,7 +5845,11 @@ const PropertyFiller = ({
|
|
5837
5845
|
}
|
5838
5846
|
}
|
5839
5847
|
});
|
5840
|
-
const value = watch(name);
|
5848
|
+
// const value = watch(name);
|
5849
|
+
const value = useWatch({
|
5850
|
+
control,
|
5851
|
+
name
|
5852
|
+
});
|
5841
5853
|
const prevValueRef = useRef({});
|
5842
5854
|
const {
|
5843
5855
|
propertyType,
|
@@ -5911,14 +5923,24 @@ const PropertyFiller = ({
|
|
5911
5923
|
clearErrors();
|
5912
5924
|
}, [name, defaultProperyValue, clearErrors, value, setFillOption, fillOption, propertyType, setValue, property]);
|
5913
5925
|
useEffect(() => {
|
5914
|
-
if (!isDirty && (property.defaultValue || property.value) &&
|
5915
|
-
setValue(name, property.defaultValue || property.value
|
5926
|
+
if (!isDirty && (property.defaultValue || property.value) && isPropertyValueEmpty(value)) {
|
5927
|
+
setValue(name, property.defaultValue || property.value, {
|
5928
|
+
shouldDirty: true
|
5929
|
+
});
|
5916
5930
|
}
|
5917
|
-
}, [isDirty, property, name, setValue, value]);
|
5931
|
+
}, [isDirty, property, name, setValue, value, required]);
|
5918
5932
|
useEffect(() => {
|
5919
5933
|
var _a;
|
5920
|
-
if (
|
5921
|
-
|
5934
|
+
if (
|
5935
|
+
// value === undefined ||
|
5936
|
+
property.isRequired && isPropertyValueEmpty(value) && (property.defaultValue === null || property.value === null)) {
|
5937
|
+
setValue(name, (_a = prevValueRef.current[fillOption]) !== null && _a !== void 0 ? _a : defaultProperyValue, {
|
5938
|
+
shouldDirty: true
|
5939
|
+
});
|
5940
|
+
} else if ((value === undefined || value === null) && !property.isRequired && (property.defaultValue === null || property.value === null)) {
|
5941
|
+
setValue(name, null, {
|
5942
|
+
shouldDirty: true
|
5943
|
+
});
|
5922
5944
|
}
|
5923
5945
|
}, [value, setValue, defaultProperyValue, property, name, fillOption]);
|
5924
5946
|
return jsxs(Grid, Object.assign({
|
package/package.json
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { type RefMethods } from '../../Property/UpsertProperty';
|
3
|
+
import { Control } from 'react-hook-form';
|
3
4
|
import { EntityReferenceProperty } from '../../../interfaces';
|
4
5
|
type Props = {
|
6
|
+
control?: Control<any>;
|
5
7
|
definitionFieldName?: string;
|
6
8
|
title?: string;
|
7
9
|
hideCodeField?: boolean;
|
@@ -5,6 +5,7 @@ type Props = {
|
|
5
5
|
control: Control<any>;
|
6
6
|
label: ReactNode;
|
7
7
|
required?: boolean;
|
8
|
+
defaultValue?: [] | null;
|
8
9
|
};
|
9
|
-
export declare const ControlArrayInput: ({ name, control, label, required }: Props) => JSX.Element;
|
10
|
+
export declare const ControlArrayInput: ({ name, control, label, required, defaultValue, }: Props) => JSX.Element;
|
10
11
|
export {};
|
@@ -1,6 +1,8 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
+
import { Control } from 'react-hook-form';
|
2
3
|
import { CustomPropertyFieldProps, EntityReferenceProperty } from '../../../interfaces';
|
3
4
|
type Props = {
|
5
|
+
control: Control<any>;
|
4
6
|
parentFieldName?: string;
|
5
7
|
hideAddButton?: boolean;
|
6
8
|
focusOnIndex?: number;
|
@@ -24,5 +26,5 @@ type Props = {
|
|
24
26
|
name: string;
|
25
27
|
}>;
|
26
28
|
};
|
27
|
-
export declare const CreatePropertiesListContext: ({ parentFieldName, hideAddButton, focusOnIndex, required, entityDefinition, globalParameter, customPropertyFields, parentRemove, entityReferenceDefinitionSources, entityReferenceValueComponent, fileReferenceValueComponent, }: Props) => JSX.Element;
|
29
|
+
export declare const CreatePropertiesListContext: ({ control, parentFieldName, hideAddButton, focusOnIndex, required, entityDefinition, globalParameter, customPropertyFields, parentRemove, entityReferenceDefinitionSources, entityReferenceValueComponent, fileReferenceValueComponent, }: Props) => JSX.Element;
|
28
30
|
export default CreatePropertiesListContext;
|