@dartech/arsenal-ui 1.3.70 → 1.3.72

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
@@ -3286,17 +3286,24 @@ const EntityAdditionalFields = ({
3286
3286
  control,
3287
3287
  name: `${parentPropertyFieldName}.name`
3288
3288
  });
3289
+ const {
3290
+ fields,
3291
+ append
3292
+ } = useFieldArray({
3293
+ control,
3294
+ name: `${parentPropertyFieldName}.properties`
3295
+ });
3289
3296
  const parametersModal = useToggle();
3290
3297
  const [focusedProperty, setFocusedProperty] = useState(0);
3291
3298
  const handleAddParameter = useCallback(() => {
3292
- if (properties) {
3293
- const propertyIndex = properties.length;
3294
- setValue(`${parentPropertyFieldName}.properties.${propertyIndex}`, defaultPropertyValues$1);
3299
+ if (fields.length > 0) {
3300
+ append(defaultPropertyValues$1);
3301
+ const propertyIndex = fields.length;
3295
3302
  setFocusedProperty(propertyIndex);
3296
3303
  } else {
3297
- setValue(`${parentPropertyFieldName}.properties`, [defaultPropertyValues$1]);
3304
+ append(defaultPropertyValues$1);
3298
3305
  }
3299
- }, [properties, parentPropertyFieldName, setValue]);
3306
+ }, [fields, append]);
3300
3307
  const handleStepperClick = index => setFocusedProperty(index);
3301
3308
  const handleSubmitClick = () => __awaiter(void 0, void 0, void 0, function* () {
3302
3309
  const isValid = yield trigger(`${parentPropertyFieldName}.properties`);
@@ -3391,15 +3398,16 @@ const EntityAdditionalFields = ({
3391
3398
  container: true,
3392
3399
  wrap: "nowrap",
3393
3400
  direction: "column",
3394
- xs: 9,
3395
3401
  spacing: 2,
3396
3402
  style: {
3397
3403
  height: '100%',
3398
- overflowY: 'auto'
3404
+ overflowY: 'auto',
3405
+ width: '75%'
3399
3406
  }
3400
3407
  }, {
3401
3408
  children: jsx(CreatePropertiesList, {
3402
3409
  hideAddButton: true,
3410
+ entityPropFields: fields,
3403
3411
  parentFieldName: parentPropertyFieldName,
3404
3412
  focusOnIndex: focusedProperty,
3405
3413
  entityDefinition: _entityDefinition,
@@ -5127,14 +5135,23 @@ const CreatePropertiesList = ({
5127
5135
  required,
5128
5136
  entityDefinition: _entityDefinition = false,
5129
5137
  globalParameter: _globalParameter = false,
5130
- customPropertyFields: _customPropertyFields = []
5138
+ customPropertyFields: _customPropertyFields = [],
5139
+ entityPropFields
5131
5140
  }) => {
5132
5141
  const fieldName = useMemo(() => parentFieldName ? `${parentFieldName}.properties` : `properties`, [parentFieldName]);
5133
5142
  const {
5134
- setValue,
5135
5143
  clearErrors,
5136
- control
5144
+ control,
5145
+ watch
5137
5146
  } = useFormContext();
5147
+ const {
5148
+ fields,
5149
+ append,
5150
+ remove
5151
+ } = useFieldArray({
5152
+ control,
5153
+ name: fieldName
5154
+ });
5138
5155
  const {
5139
5156
  fieldState: {
5140
5157
  error
@@ -5160,16 +5177,19 @@ const CreatePropertiesList = ({
5160
5177
  }
5161
5178
  }, [focusOnIndex, refs]);
5162
5179
  const handleAddParameter = useCallback(() => {
5163
- if (properties) {
5164
- setValue(`${fieldName}.${properties.length}`, defaultPropertyValues);
5165
- } else {
5166
- setValue(fieldName, [defaultPropertyValues]);
5167
- }
5180
+ append(defaultPropertyValues);
5168
5181
  clearErrors(fieldName);
5169
- }, [properties, fieldName, clearErrors, setValue]);
5182
+ }, [append, fieldName, clearErrors]);
5170
5183
  const handleRemoveParameter = useCallback(index => {
5171
- setValue(`${fieldName}`, removeArrayItem(properties, index));
5172
- }, [properties, fieldName, setValue]);
5184
+ remove(index);
5185
+ }, [remove]);
5186
+ const propFields = useMemo(() => {
5187
+ if (entityPropFields) {
5188
+ return entityPropFields;
5189
+ } else {
5190
+ return fields;
5191
+ }
5192
+ }, [entityPropFields, fields]);
5173
5193
  return jsxs(Fragment, {
5174
5194
  children: [error && error.message && jsx(Grid, Object.assign({
5175
5195
  sm: 12
@@ -5179,7 +5199,7 @@ const CreatePropertiesList = ({
5179
5199
  }, {
5180
5200
  children: error.message
5181
5201
  }))
5182
- })), Array.isArray(properties) && properties.map((property, index) => jsx(Grid, Object.assign({
5202
+ })), Array.isArray(properties) && propFields.map((item, index) => jsx(Grid, Object.assign({
5183
5203
  sm: 12,
5184
5204
  ref: ref => refs.current[index] = ref
5185
5205
  }, {
@@ -5196,7 +5216,7 @@ const CreatePropertiesList = ({
5196
5216
  wordBreak: 'break-word'
5197
5217
  }
5198
5218
  }, {
5199
- children: property.name || `Property ${index + 1}`
5219
+ children: watch(`${fieldName}.${index}.name`) || `Property ${index + 1}`
5200
5220
  }))
5201
5221
  })), jsx(AccordionDetails, {
5202
5222
  children: jsx(CreatePropertyFormFields, {
@@ -5216,7 +5236,7 @@ const CreatePropertiesList = ({
5216
5236
  }))
5217
5237
  })]
5218
5238
  }))
5219
- }), index)), !hideAddButton && jsx(Grid, Object.assign({
5239
+ }), item.id)), !hideAddButton && jsx(Grid, Object.assign({
5220
5240
  xs: 12
5221
5241
  }, {
5222
5242
  children: jsx(Button, Object.assign({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.3.70",
3
+ "version": "1.3.72",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -8,6 +8,9 @@ type Props = {
8
8
  entityDefinition?: boolean;
9
9
  globalParameter?: boolean;
10
10
  customPropertyFields?: CustomPropertyFieldProps[];
11
+ entityPropFields?: Array<object & {
12
+ id: string;
13
+ }>;
11
14
  };
12
- export declare const CreatePropertiesList: ({ parentFieldName, hideAddButton, focusOnIndex, required, entityDefinition, globalParameter, customPropertyFields, }: Props) => JSX.Element;
15
+ export declare const CreatePropertiesList: ({ parentFieldName, hideAddButton, focusOnIndex, required, entityDefinition, globalParameter, customPropertyFields, entityPropFields, }: Props) => JSX.Element;
13
16
  export default CreatePropertiesList;