@dartech/arsenal-ui 1.4.0 → 1.4.2

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
@@ -24,6 +24,7 @@ import Radio from '@mui/material/Radio';
24
24
  import RadioGroup from '@mui/material/RadioGroup';
25
25
  import FormLabel from '@mui/material/FormLabel';
26
26
  import Autocomplete from '@mui/material/Autocomplete';
27
+ import _get from 'lodash/get';
27
28
  import { useQuery } from '@tanstack/react-query';
28
29
  import qs from 'qs';
29
30
  import Tooltip from '@mui/material/Tooltip';
@@ -661,7 +662,7 @@ const useAutocomplete = ({
661
662
  if (typeof option === 'string') {
662
663
  return option === value;
663
664
  } else if (valueKey) {
664
- return option[valueKey] === value[valueKey] || option[valueKey] === value;
665
+ return _get(option, valueKey) === _get(value, valueKey) || _get(option, valueKey) === value;
665
666
  } else if (option.value) {
666
667
  return option.value === value.value || option.value === value;
667
668
  }
@@ -672,8 +673,8 @@ const useAutocomplete = ({
672
673
  if (!option) return '';
673
674
  if (typeof option === 'string') {
674
675
  return option;
675
- } else if (labelKey && option[labelKey]) {
676
- return option[labelKey] + '';
676
+ } else if (labelKey && _get(option, labelKey, '')) {
677
+ return _get(option, labelKey, '') + '';
677
678
  } else {
678
679
  return option.label + '' || option.name + '' || option.value + '' || option.code + '' || '--no label--';
679
680
  }
@@ -745,12 +746,12 @@ const ControlAutocomplete = _a => {
745
746
  labelKey
746
747
  });
747
748
  const handleChange = (_, value) => {
748
- onChange(useStringValue ? value[valueKey] : value);
749
+ onChange(useStringValue ? _get(value, valueKey) : value);
749
750
  setLocalValue(value);
750
751
  };
751
752
  useEffect(() => {
752
753
  if (typeof value === 'string' && valueKey && useStringValue && !localValue && options.length && !!options[0] && typeof options[0] === 'object') {
753
- setLocalValue(options.find(el => el[valueKey] === value));
754
+ setLocalValue(options.find(el => _get(el, valueKey) === value));
754
755
  } else setLocalValue(value);
755
756
  }, [localValue, options, useStringValue, value, valueKey]);
756
757
  return jsx(Autocomplete, Object.assign({}, fieldProps, {
@@ -866,11 +867,11 @@ function ControlQueryAutocomplete(_a) {
866
867
  if (!isDirty && formValue && itemQueryFunction) {
867
868
  let requestValue = formValue;
868
869
  if (typeof formValue === 'object' && valueKey in formValue) {
869
- requestValue = formValue[valueKey];
870
+ requestValue = _get(formValue, valueKey);
870
871
  }
871
872
  itemQueryFunction(requestValue).then(item => {
872
873
  setFieldValue(item);
873
- setInputValue(item[labelKey]);
874
+ setInputValue(_get(item, labelKey));
874
875
  }).catch();
875
876
  }
876
877
  }, [formValue, isDirty, valueKey, labelKey, itemQueryFunction, setFieldValue]);
@@ -1626,9 +1627,6 @@ const propertiesArrayToObject = (properties, isGlobalParameter) => {
1626
1627
  name,
1627
1628
  isRequired,
1628
1629
  isMultiple,
1629
- isVisible,
1630
- isFillable,
1631
- isEditable,
1632
1630
  sortOrder,
1633
1631
  isEnabled,
1634
1632
  uiSettings,
@@ -1647,9 +1645,6 @@ const propertiesArrayToObject = (properties, isGlobalParameter) => {
1647
1645
  }, getPropertyValue(Object.assign(Object.assign({}, property), {
1648
1646
  propertyType
1649
1647
  }), isGlobalParameter));
1650
- if (isVisible !== undefined) resultProperty.isVisible = isVisible;
1651
- if (isFillable !== undefined) resultProperty.isFillable = isFillable;
1652
- if (isEditable !== undefined) resultProperty.isEditable = isEditable;
1653
1648
  if ('isViewableInList' in property) {
1654
1649
  resultProperty['isViewableInList'] = property.isViewableInList;
1655
1650
  }
@@ -3378,7 +3373,7 @@ const EntityPropertiesShortView = ({
3378
3373
  };
3379
3374
  var EntityPropertiesShortView$1 = EntityPropertiesShortView;
3380
3375
 
3381
- const defaultPropertyValues$1 = {
3376
+ const defaultPropertyValues$2 = {
3382
3377
  key: '',
3383
3378
  propertyType: null,
3384
3379
  name: '',
@@ -3431,11 +3426,11 @@ const EntityAdditionalFields = ({
3431
3426
  const [focusedProperty, setFocusedProperty] = useState(0);
3432
3427
  const handleAddParameter = useCallback(() => {
3433
3428
  if ((properties === null || properties === void 0 ? void 0 : properties.length) > 0) {
3434
- append(defaultPropertyValues$1);
3429
+ append(defaultPropertyValues$2);
3435
3430
  const propertyIndex = properties.length;
3436
3431
  setFocusedProperty(propertyIndex);
3437
3432
  } else {
3438
- append(defaultPropertyValues$1);
3433
+ append(defaultPropertyValues$2);
3439
3434
  }
3440
3435
  propsRef.current.addProperty();
3441
3436
  }, [properties, append]);
@@ -5002,8 +4997,6 @@ const CreatePropertyFormFields = /*#__PURE__*/memo(({
5002
4997
  fileReferenceValueComponent
5003
4998
  }) => {
5004
4999
  var _a;
5005
- // const { control, setValue, watch } = useFormContext();
5006
- // console.log(propertyFieldName);
5007
5000
  const propertyType = useWatch({
5008
5001
  control,
5009
5002
  name: `${propertyFieldName}.propertyType`
@@ -5150,7 +5143,7 @@ const CreatePropertyFormFields = /*#__PURE__*/memo(({
5150
5143
  }));
5151
5144
  });
5152
5145
 
5153
- const defaultPropertyValues = {
5146
+ const defaultPropertyValues$1 = {
5154
5147
  key: '',
5155
5148
  propertyType: null,
5156
5149
  name: '',
@@ -5165,7 +5158,7 @@ const defaultPropertyValues = {
5165
5158
  };
5166
5159
  const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5167
5160
  properties,
5168
- // parentFieldName,
5161
+ parentFieldName,
5169
5162
  hideAddButton,
5170
5163
  focusOnIndex,
5171
5164
  required,
@@ -5177,10 +5170,6 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5177
5170
  entityReferenceValueComponent,
5178
5171
  fileReferenceValueComponent
5179
5172
  }, ref) => {
5180
- // const fieldName = useMemo(
5181
- // () => (parentFieldName ? `${parentFieldName}.properties` : `properties`),
5182
- // [parentFieldName]
5183
- // );
5184
5173
  var _a;
5185
5174
  const {
5186
5175
  clearErrors,
@@ -5219,7 +5208,7 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5219
5208
  });
5220
5209
  const refs = useRef([]);
5221
5210
  const handleAddParameter = useCallback(() => {
5222
- append(defaultPropertyValues);
5211
+ append(defaultPropertyValues$1);
5223
5212
  clearErrors('properties');
5224
5213
  }, [append, clearErrors]);
5225
5214
  const handleRemoveParameter = useCallback(index => {
@@ -5259,12 +5248,12 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5259
5248
  }, {
5260
5249
  children: error.message
5261
5250
  }))
5262
- })), Array.isArray(fields) && fields.map((item, index) => jsx(Grid, Object.assign({
5251
+ })), Array.isArray(fields) && fields.map((item, index, array) => jsx(Grid, Object.assign({
5263
5252
  sm: 12,
5264
5253
  ref: ref => refs.current[index] = ref
5265
5254
  }, {
5266
5255
  children: jsxs(Accordion, Object.assign({
5267
- defaultExpanded: !(properties === null || properties === void 0 ? void 0 : properties.length),
5256
+ defaultExpanded: index === array.length - 1 && !item.key,
5268
5257
  elevation: 3
5269
5258
  }, {
5270
5259
  children: [jsx(AccordionSummary, Object.assign({
@@ -5320,6 +5309,149 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5320
5309
  });
5321
5310
  });
5322
5311
 
5312
+ const defaultPropertyValues = {
5313
+ key: '',
5314
+ propertyType: null,
5315
+ name: '',
5316
+ defaultValue: '',
5317
+ defaultValues: [],
5318
+ isRequired: true,
5319
+ isMultiple: false,
5320
+ sortOrder: 0,
5321
+ isEnabled: true,
5322
+ executeValue: '',
5323
+ uiSettings: ''
5324
+ };
5325
+ const CreatePropertiesListContext = ({
5326
+ parentFieldName,
5327
+ hideAddButton,
5328
+ focusOnIndex,
5329
+ required,
5330
+ entityDefinition: _entityDefinition = false,
5331
+ globalParameter: _globalParameter = false,
5332
+ customPropertyFields: _customPropertyFields = [],
5333
+ parentRemove,
5334
+ entityReferenceDefinitionSources,
5335
+ entityReferenceValueComponent,
5336
+ fileReferenceValueComponent
5337
+ }) => {
5338
+ var _a;
5339
+ const fieldName = useMemo(() => parentFieldName ? `${parentFieldName}.properties` : `properties`, [parentFieldName]);
5340
+ const {
5341
+ clearErrors,
5342
+ control,
5343
+ setValue
5344
+ } = useFormContext();
5345
+ const {
5346
+ fields,
5347
+ append,
5348
+ remove
5349
+ } = useFieldArray({
5350
+ control,
5351
+ name: fieldName
5352
+ });
5353
+ const {
5354
+ fieldState: {
5355
+ error
5356
+ }
5357
+ } = useController({
5358
+ control,
5359
+ name: fieldName,
5360
+ rules: {
5361
+ validate: val => {
5362
+ if (required && Array.isArray(val) && val.length === 0) return 'Please, fill the properties';
5363
+ return true;
5364
+ }
5365
+ }
5366
+ });
5367
+ // const properties = useWatch({ control, name: fieldName });
5368
+ const refs = useRef([]);
5369
+ const handleAddParameter = useCallback(() => {
5370
+ append(defaultPropertyValues);
5371
+ clearErrors('properties');
5372
+ }, [append, clearErrors]);
5373
+ const handleRemoveParameter = useCallback(index => {
5374
+ if (parentRemove) parentRemove(index);
5375
+ remove(index);
5376
+ }, [parentRemove, remove]);
5377
+ useEffect(() => {
5378
+ if (typeof focusOnIndex === 'number' && refs.current[focusOnIndex]) {
5379
+ refs.current[focusOnIndex].scrollIntoView({
5380
+ behavior: 'smooth',
5381
+ block: 'start'
5382
+ });
5383
+ }
5384
+ }, [focusOnIndex, refs]);
5385
+ return jsxs(Fragment, {
5386
+ children: [error && error.message && jsx(Grid, Object.assign({
5387
+ sm: 12
5388
+ }, {
5389
+ children: jsx(Typography, Object.assign({
5390
+ color: "secondary"
5391
+ }, {
5392
+ children: error.message
5393
+ }))
5394
+ })), Array.isArray(fields) && fields.map((item, index, array) => jsx(Grid, Object.assign({
5395
+ sm: 12,
5396
+ ref: ref => refs.current[index] = ref
5397
+ }, {
5398
+ children: jsxs(Accordion, Object.assign({
5399
+ defaultExpanded: index === array.length - 1 && !item.key,
5400
+ elevation: 3
5401
+ }, {
5402
+ children: [jsx(AccordionSummary, Object.assign({
5403
+ expandIcon: jsx(ExpandMore, {})
5404
+ }, {
5405
+ children: jsx(Typography, Object.assign({
5406
+ color: error && error[index] ? 'secondary' : 'initial',
5407
+ style: {
5408
+ wordBreak: 'break-word'
5409
+ }
5410
+ }, {
5411
+ children: item.name || `Property ${index + 1}`
5412
+ }))
5413
+ })), jsx(AccordionDetails, {
5414
+ children: jsx(CreatePropertyFormFields, {
5415
+ control: control,
5416
+ setValue: setValue,
5417
+ propertyFieldName: `${fieldName}.${index}`,
5418
+ entityDefinition: _entityDefinition,
5419
+ globalParameter: _globalParameter,
5420
+ customPropertyFields: _customPropertyFields,
5421
+ entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5422
+ entityReferenceValueComponent: entityReferenceValueComponent,
5423
+ fileReferenceValueComponent: fileReferenceValueComponent
5424
+ })
5425
+ }), jsx(AccordionActions, {
5426
+ children: jsx(Button, Object.assign({
5427
+ variant: "contained",
5428
+ size: "small",
5429
+ color: "secondary",
5430
+ onClick: () => handleRemoveParameter(index)
5431
+ }, {
5432
+ children: "Remove"
5433
+ }))
5434
+ })]
5435
+ }))
5436
+ }), item.id)), !hideAddButton && jsxs(Grid, Object.assign({
5437
+ xs: 12
5438
+ }, {
5439
+ children: [jsx(Button, Object.assign({
5440
+ variant: "contained",
5441
+ size: "small",
5442
+ color: "primary",
5443
+ onClick: handleAddParameter
5444
+ }, {
5445
+ children: "Add property"
5446
+ })), error && jsx(FormHelperText, Object.assign({
5447
+ error: true
5448
+ }, {
5449
+ children: (_a = error.root) === null || _a === void 0 ? void 0 : _a.message
5450
+ }))]
5451
+ }))]
5452
+ });
5453
+ };
5454
+
5323
5455
  const CreateDefinition = /*#__PURE__*/forwardRef(({
5324
5456
  definitionFieldName,
5325
5457
  title,
@@ -5380,7 +5512,7 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
5380
5512
  name: definitionFieldName ? `${definitionFieldName}.version` : `version`,
5381
5513
  label: "Version"
5382
5514
  })
5383
- })), jsx(CreatePropertiesList, {
5515
+ })), ref ? jsx(CreatePropertiesList, {
5384
5516
  ref: ref,
5385
5517
  properties: properties,
5386
5518
  required: _required,
@@ -5388,6 +5520,12 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
5388
5520
  entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5389
5521
  entityReferenceValueComponent: entityReferenceValueComponent,
5390
5522
  fileReferenceValueComponent: fileReferenceValueComponent
5523
+ }) : jsx(CreatePropertiesListContext, {
5524
+ required: _required,
5525
+ parentFieldName: definitionFieldName,
5526
+ entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5527
+ entityReferenceValueComponent: entityReferenceValueComponent,
5528
+ fileReferenceValueComponent: fileReferenceValueComponent
5391
5529
  })]
5392
5530
  }));
5393
5531
  });
@@ -5844,6 +5982,12 @@ const PropertyFiller = ({
5844
5982
  entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5845
5983
  entityReferenceValueComponent: entityReferenceValueComponent,
5846
5984
  fileReferenceValueComponent: fileReferenceValueComponent
5985
+ }), fillOption === 'dem_builder' && jsx(CreateDefinition, {
5986
+ title: "JSON",
5987
+ definitionFieldName: name,
5988
+ entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5989
+ entityReferenceValueComponent: entityReferenceValueComponent,
5990
+ fileReferenceValueComponent: fileReferenceValueComponent
5847
5991
  }), error && jsx(FormHelperText, Object.assign({
5848
5992
  error: true
5849
5993
  }, {
@@ -7512,4 +7656,4 @@ const defaultDefinitionObjectValue = {
7512
7656
  properties: {}
7513
7657
  };
7514
7658
 
7515
- export { AlertDialog, BackButton, Breadcrumbs, ContentLayout, ControlAceEditor, ControlArrayInput, ControlAutocomplete, ControlCheckbox, ControlDate, ControlDateTime, ControlDebouncedInput, ControlInput, ControlNumberInput, ControlPeriodInput, ControlPhoneInput, ControlQueryAutocomplete, ControlRadio, ControlSelect, ControlSwitch, ControlTime, CopyButton, CreateDefinition, CreatePropertiesList, CreatePropertyFormFields, DATE_DEFAULT_FORMAT, DATE_TIME_DEFAULT_FORMAT, DefinitionFiller, DefinitionValueView, InfoItem, JsonModalView, JsonPathPicker, JsonView, Loader, MenuIcon, MultiplePropertyFiller, PropertyFiller, PropertyType, PropertyValueField, RoundingMode, RouteTabs, Sidebar, SimpleTable, Status, StepperView, TIME_DEFAULT_FORMAT, TabPanel, Table, TableAction, TableActionCell, ViewPropertiesList, ViewProperty, capitalize, deepParseJson, defaultDefinitionArrayValue, defaultDefinitionObjectValue, digitsOnly, floatsOnly, formatDefinitionData, formatTableRowValue, getDemPropertyDateFormat, getEntityStarterValue, getJsonStringValue, getMultiplePropertyFillOptions, getSinglePropertyFillOptions, isDateType, isExpression, isPropertyValueEmpty, propertiesArrayToObject, propertiesObjectToArray, removeArrayItem, safeParseJson, sortArrayOfObjects, theme, useDebounce, useToggle, validateJson };
7659
+ export { AlertDialog, BackButton, Breadcrumbs, ContentLayout, ControlAceEditor, ControlArrayInput, ControlAutocomplete, ControlCheckbox, ControlDate, ControlDateTime, ControlDebouncedInput, ControlInput, ControlNumberInput, ControlPeriodInput, ControlPhoneInput, ControlQueryAutocomplete, ControlRadio, ControlSelect, ControlSwitch, ControlTime, CopyButton, CreateDefinition, CreatePropertiesList, CreatePropertiesListContext, CreatePropertyFormFields, DATE_DEFAULT_FORMAT, DATE_TIME_DEFAULT_FORMAT, DefinitionFiller, DefinitionValueView, InfoItem, JsonModalView, JsonPathPicker, JsonView, Loader, MenuIcon, MultiplePropertyFiller, PropertyFiller, PropertyType, PropertyValueField, RoundingMode, RouteTabs, Sidebar, SimpleTable, Status, StepperView, TIME_DEFAULT_FORMAT, TabPanel, Table, TableAction, TableActionCell, ViewPropertiesList, ViewProperty, capitalize, deepParseJson, defaultDefinitionArrayValue, defaultDefinitionObjectValue, digitsOnly, floatsOnly, formatDefinitionData, formatTableRowValue, getDemPropertyDateFormat, getEntityStarterValue, getJsonStringValue, getMultiplePropertyFillOptions, getSinglePropertyFillOptions, isDateType, isExpression, isPropertyValueEmpty, propertiesArrayToObject, propertiesObjectToArray, removeArrayItem, safeParseJson, sortArrayOfObjects, theme, useDebounce, useToggle, validateJson };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -27,6 +27,7 @@
27
27
  "classnames": "^2.3.1",
28
28
  "@tanstack/react-query": "^4.24.10",
29
29
  "@rollup/plugin-node-resolve": "13.3.0",
30
+ "lodash": "4.17.21",
30
31
  "qs": "6.11.0",
31
32
  "react-input-mask": "2.0.4"
32
33
  },
@@ -43,9 +43,6 @@ export interface Property {
43
43
  isMultiple: boolean;
44
44
  sortOrder: number;
45
45
  isEnabled: boolean;
46
- isVisible?: boolean;
47
- isFillable?: boolean;
48
- isEditable?: boolean;
49
46
  uiSettings: unknown;
50
47
  validationNode: unknown;
51
48
  key?: string;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { type RefMethods } from '../../Property/UpsertProperty/CreatePropertiesList';
2
+ import { type RefMethods } from '../../Property/UpsertProperty';
3
3
  import { EntityReferenceProperty } from '../../../interfaces';
4
4
  type Props = {
5
5
  definitionFieldName?: string;
@@ -0,0 +1,28 @@
1
+ /// <reference types="react" />
2
+ import { CustomPropertyFieldProps, EntityReferenceProperty } from '../../../interfaces';
3
+ type Props = {
4
+ parentFieldName?: string;
5
+ hideAddButton?: boolean;
6
+ focusOnIndex?: number;
7
+ required?: boolean;
8
+ entityDefinition?: boolean;
9
+ globalParameter?: boolean;
10
+ customPropertyFields?: CustomPropertyFieldProps[];
11
+ entityPropFields?: Array<object & {
12
+ id: string;
13
+ }>;
14
+ parentRemove?: (index?: number | number[]) => void;
15
+ entityReferenceDefinitionSources?: {
16
+ label: string;
17
+ value: string;
18
+ }[];
19
+ entityReferenceValueComponent?: React.ElementType<{
20
+ name: string;
21
+ property: EntityReferenceProperty;
22
+ }>;
23
+ fileReferenceValueComponent?: React.ElementType<{
24
+ name: string;
25
+ }>;
26
+ };
27
+ export declare const CreatePropertiesListContext: ({ parentFieldName, hideAddButton, focusOnIndex, required, entityDefinition, globalParameter, customPropertyFields, parentRemove, entityReferenceDefinitionSources, entityReferenceValueComponent, fileReferenceValueComponent, }: Props) => JSX.Element;
28
+ export default CreatePropertiesListContext;
@@ -1,3 +1,4 @@
1
1
  export * from './CreatePropertiesList';
2
+ export * from './CreatePropertiesListContext';
2
3
  export * from './CreatePropertyFormFields';
3
4
  export * from './PropertyValueField';