@dartech/arsenal-ui 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
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
  }
@@ -3378,7 +3379,7 @@ const EntityPropertiesShortView = ({
3378
3379
  };
3379
3380
  var EntityPropertiesShortView$1 = EntityPropertiesShortView;
3380
3381
 
3381
- const defaultPropertyValues$1 = {
3382
+ const defaultPropertyValues$2 = {
3382
3383
  key: '',
3383
3384
  propertyType: null,
3384
3385
  name: '',
@@ -3431,11 +3432,11 @@ const EntityAdditionalFields = ({
3431
3432
  const [focusedProperty, setFocusedProperty] = useState(0);
3432
3433
  const handleAddParameter = useCallback(() => {
3433
3434
  if ((properties === null || properties === void 0 ? void 0 : properties.length) > 0) {
3434
- append(defaultPropertyValues$1);
3435
+ append(defaultPropertyValues$2);
3435
3436
  const propertyIndex = properties.length;
3436
3437
  setFocusedProperty(propertyIndex);
3437
3438
  } else {
3438
- append(defaultPropertyValues$1);
3439
+ append(defaultPropertyValues$2);
3439
3440
  }
3440
3441
  propsRef.current.addProperty();
3441
3442
  }, [properties, append]);
@@ -5002,8 +5003,6 @@ const CreatePropertyFormFields = /*#__PURE__*/memo(({
5002
5003
  fileReferenceValueComponent
5003
5004
  }) => {
5004
5005
  var _a;
5005
- // const { control, setValue, watch } = useFormContext();
5006
- // console.log(propertyFieldName);
5007
5006
  const propertyType = useWatch({
5008
5007
  control,
5009
5008
  name: `${propertyFieldName}.propertyType`
@@ -5150,7 +5149,7 @@ const CreatePropertyFormFields = /*#__PURE__*/memo(({
5150
5149
  }));
5151
5150
  });
5152
5151
 
5153
- const defaultPropertyValues = {
5152
+ const defaultPropertyValues$1 = {
5154
5153
  key: '',
5155
5154
  propertyType: null,
5156
5155
  name: '',
@@ -5165,7 +5164,7 @@ const defaultPropertyValues = {
5165
5164
  };
5166
5165
  const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5167
5166
  properties,
5168
- // parentFieldName,
5167
+ parentFieldName,
5169
5168
  hideAddButton,
5170
5169
  focusOnIndex,
5171
5170
  required,
@@ -5177,10 +5176,6 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5177
5176
  entityReferenceValueComponent,
5178
5177
  fileReferenceValueComponent
5179
5178
  }, ref) => {
5180
- // const fieldName = useMemo(
5181
- // () => (parentFieldName ? `${parentFieldName}.properties` : `properties`),
5182
- // [parentFieldName]
5183
- // );
5184
5179
  var _a;
5185
5180
  const {
5186
5181
  clearErrors,
@@ -5219,7 +5214,7 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5219
5214
  });
5220
5215
  const refs = useRef([]);
5221
5216
  const handleAddParameter = useCallback(() => {
5222
- append(defaultPropertyValues);
5217
+ append(defaultPropertyValues$1);
5223
5218
  clearErrors('properties');
5224
5219
  }, [append, clearErrors]);
5225
5220
  const handleRemoveParameter = useCallback(index => {
@@ -5259,12 +5254,12 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5259
5254
  }, {
5260
5255
  children: error.message
5261
5256
  }))
5262
- })), Array.isArray(fields) && fields.map((item, index) => jsx(Grid, Object.assign({
5257
+ })), Array.isArray(fields) && fields.map((item, index, array) => jsx(Grid, Object.assign({
5263
5258
  sm: 12,
5264
5259
  ref: ref => refs.current[index] = ref
5265
5260
  }, {
5266
5261
  children: jsxs(Accordion, Object.assign({
5267
- defaultExpanded: !(properties === null || properties === void 0 ? void 0 : properties.length),
5262
+ defaultExpanded: index === array.length - 1 && !item.key,
5268
5263
  elevation: 3
5269
5264
  }, {
5270
5265
  children: [jsx(AccordionSummary, Object.assign({
@@ -5320,6 +5315,149 @@ const CreatePropertiesList = /*#__PURE__*/forwardRef(({
5320
5315
  });
5321
5316
  });
5322
5317
 
5318
+ const defaultPropertyValues = {
5319
+ key: '',
5320
+ propertyType: null,
5321
+ name: '',
5322
+ defaultValue: '',
5323
+ defaultValues: [],
5324
+ isRequired: true,
5325
+ isMultiple: false,
5326
+ sortOrder: 0,
5327
+ isEnabled: true,
5328
+ executeValue: '',
5329
+ uiSettings: ''
5330
+ };
5331
+ const CreatePropertiesListContext = ({
5332
+ parentFieldName,
5333
+ hideAddButton,
5334
+ focusOnIndex,
5335
+ required,
5336
+ entityDefinition: _entityDefinition = false,
5337
+ globalParameter: _globalParameter = false,
5338
+ customPropertyFields: _customPropertyFields = [],
5339
+ parentRemove,
5340
+ entityReferenceDefinitionSources,
5341
+ entityReferenceValueComponent,
5342
+ fileReferenceValueComponent
5343
+ }) => {
5344
+ var _a;
5345
+ const fieldName = useMemo(() => parentFieldName ? `${parentFieldName}.properties` : `properties`, [parentFieldName]);
5346
+ const {
5347
+ clearErrors,
5348
+ control,
5349
+ setValue
5350
+ } = useFormContext();
5351
+ const {
5352
+ fields,
5353
+ append,
5354
+ remove
5355
+ } = useFieldArray({
5356
+ control,
5357
+ name: fieldName
5358
+ });
5359
+ const {
5360
+ fieldState: {
5361
+ error
5362
+ }
5363
+ } = useController({
5364
+ control,
5365
+ name: fieldName,
5366
+ rules: {
5367
+ validate: val => {
5368
+ if (required && Array.isArray(val) && val.length === 0) return 'Please, fill the properties';
5369
+ return true;
5370
+ }
5371
+ }
5372
+ });
5373
+ // const properties = useWatch({ control, name: fieldName });
5374
+ const refs = useRef([]);
5375
+ const handleAddParameter = useCallback(() => {
5376
+ append(defaultPropertyValues);
5377
+ clearErrors('properties');
5378
+ }, [append, clearErrors]);
5379
+ const handleRemoveParameter = useCallback(index => {
5380
+ if (parentRemove) parentRemove(index);
5381
+ remove(index);
5382
+ }, [parentRemove, remove]);
5383
+ useEffect(() => {
5384
+ if (typeof focusOnIndex === 'number' && refs.current[focusOnIndex]) {
5385
+ refs.current[focusOnIndex].scrollIntoView({
5386
+ behavior: 'smooth',
5387
+ block: 'start'
5388
+ });
5389
+ }
5390
+ }, [focusOnIndex, refs]);
5391
+ return jsxs(Fragment, {
5392
+ children: [error && error.message && jsx(Grid, Object.assign({
5393
+ sm: 12
5394
+ }, {
5395
+ children: jsx(Typography, Object.assign({
5396
+ color: "secondary"
5397
+ }, {
5398
+ children: error.message
5399
+ }))
5400
+ })), Array.isArray(fields) && fields.map((item, index, array) => jsx(Grid, Object.assign({
5401
+ sm: 12,
5402
+ ref: ref => refs.current[index] = ref
5403
+ }, {
5404
+ children: jsxs(Accordion, Object.assign({
5405
+ defaultExpanded: index === array.length - 1 && !item.key,
5406
+ elevation: 3
5407
+ }, {
5408
+ children: [jsx(AccordionSummary, Object.assign({
5409
+ expandIcon: jsx(ExpandMore, {})
5410
+ }, {
5411
+ children: jsx(Typography, Object.assign({
5412
+ color: error && error[index] ? 'secondary' : 'initial',
5413
+ style: {
5414
+ wordBreak: 'break-word'
5415
+ }
5416
+ }, {
5417
+ children: item.name || `Property ${index + 1}`
5418
+ }))
5419
+ })), jsx(AccordionDetails, {
5420
+ children: jsx(CreatePropertyFormFields, {
5421
+ control: control,
5422
+ setValue: setValue,
5423
+ propertyFieldName: `${fieldName}.${index}`,
5424
+ entityDefinition: _entityDefinition,
5425
+ globalParameter: _globalParameter,
5426
+ customPropertyFields: _customPropertyFields,
5427
+ entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5428
+ entityReferenceValueComponent: entityReferenceValueComponent,
5429
+ fileReferenceValueComponent: fileReferenceValueComponent
5430
+ })
5431
+ }), jsx(AccordionActions, {
5432
+ children: jsx(Button, Object.assign({
5433
+ variant: "contained",
5434
+ size: "small",
5435
+ color: "secondary",
5436
+ onClick: () => handleRemoveParameter(index)
5437
+ }, {
5438
+ children: "Remove"
5439
+ }))
5440
+ })]
5441
+ }))
5442
+ }), item.id)), !hideAddButton && jsxs(Grid, Object.assign({
5443
+ xs: 12
5444
+ }, {
5445
+ children: [jsx(Button, Object.assign({
5446
+ variant: "contained",
5447
+ size: "small",
5448
+ color: "primary",
5449
+ onClick: handleAddParameter
5450
+ }, {
5451
+ children: "Add property"
5452
+ })), error && jsx(FormHelperText, Object.assign({
5453
+ error: true
5454
+ }, {
5455
+ children: (_a = error.root) === null || _a === void 0 ? void 0 : _a.message
5456
+ }))]
5457
+ }))]
5458
+ });
5459
+ };
5460
+
5323
5461
  const CreateDefinition = /*#__PURE__*/forwardRef(({
5324
5462
  definitionFieldName,
5325
5463
  title,
@@ -5380,7 +5518,7 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
5380
5518
  name: definitionFieldName ? `${definitionFieldName}.version` : `version`,
5381
5519
  label: "Version"
5382
5520
  })
5383
- })), jsx(CreatePropertiesList, {
5521
+ })), ref ? jsx(CreatePropertiesList, {
5384
5522
  ref: ref,
5385
5523
  properties: properties,
5386
5524
  required: _required,
@@ -5388,6 +5526,12 @@ const CreateDefinition = /*#__PURE__*/forwardRef(({
5388
5526
  entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5389
5527
  entityReferenceValueComponent: entityReferenceValueComponent,
5390
5528
  fileReferenceValueComponent: fileReferenceValueComponent
5529
+ }) : jsx(CreatePropertiesListContext, {
5530
+ required: _required,
5531
+ parentFieldName: definitionFieldName,
5532
+ entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5533
+ entityReferenceValueComponent: entityReferenceValueComponent,
5534
+ fileReferenceValueComponent: fileReferenceValueComponent
5391
5535
  })]
5392
5536
  }));
5393
5537
  });
@@ -5844,6 +5988,12 @@ const PropertyFiller = ({
5844
5988
  entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5845
5989
  entityReferenceValueComponent: entityReferenceValueComponent,
5846
5990
  fileReferenceValueComponent: fileReferenceValueComponent
5991
+ }), fillOption === 'dem_builder' && jsx(CreateDefinition, {
5992
+ title: "JSON",
5993
+ definitionFieldName: name,
5994
+ entityReferenceDefinitionSources: entityReferenceDefinitionSources,
5995
+ entityReferenceValueComponent: entityReferenceValueComponent,
5996
+ fileReferenceValueComponent: fileReferenceValueComponent
5847
5997
  }), error && jsx(FormHelperText, Object.assign({
5848
5998
  error: true
5849
5999
  }, {
@@ -7512,4 +7662,4 @@ const defaultDefinitionObjectValue = {
7512
7662
  properties: {}
7513
7663
  };
7514
7664
 
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 };
7665
+ 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.1",
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
  },
@@ -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,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { Control } from 'react-hook-form';
3
2
  type Props = {
4
3
  control: Control<any>;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  format: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  type Props = {
3
2
  name: string;
4
3
  label?: string;
@@ -1,3 +1,4 @@
1
1
  export * from './CreatePropertiesList';
2
+ export * from './CreatePropertiesListContext';
2
3
  export * from './CreatePropertyFormFields';
3
4
  export * from './PropertyValueField';
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { PropertyUnion } from '../../../interfaces';
3
2
  type PropertyItemProps = {
4
3
  property: PropertyUnion;