@dartech/arsenal-ui 0.0.1

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.
Files changed (124) hide show
  1. package/.babelrc +12 -0
  2. package/.eslintrc.json +22 -0
  3. package/README.md +7 -0
  4. package/index.ts +3 -0
  5. package/jest.config.js +9 -0
  6. package/package.json +21 -0
  7. package/project.json +69 -0
  8. package/rollup.config.js +135 -0
  9. package/src/interfaces/common.ts +12 -0
  10. package/src/interfaces/definition.ts +143 -0
  11. package/src/interfaces/index.ts +3 -0
  12. package/src/interfaces/ui.ts +35 -0
  13. package/src/lib/Alert/Alert.tsx +108 -0
  14. package/src/lib/Alert/index.ts +1 -0
  15. package/src/lib/Definition/CreateDefinition/CreateDefinition.tsx +74 -0
  16. package/src/lib/Definition/CreateDefinition/index.ts +1 -0
  17. package/src/lib/Definition/DefinitionFiller/DefinitionFiller.tsx +85 -0
  18. package/src/lib/Definition/DefinitionFiller/WidgetDefinitionFiller.tsx +96 -0
  19. package/src/lib/Definition/DefinitionFiller/index.ts +2 -0
  20. package/src/lib/Definition/index.ts +2 -0
  21. package/src/lib/DemPropertyField/DemPropertyField.tsx +93 -0
  22. package/src/lib/DemPropertyField/DemPropertyView/DemPropertyView.tsx +44 -0
  23. package/src/lib/DemPropertyField/DemPropertyView/index.ts +1 -0
  24. package/src/lib/DemPropertyField/MultipleDemField/MultipleDemField.tsx +293 -0
  25. package/src/lib/DemPropertyField/MultipleDemField/index.tsx +1 -0
  26. package/src/lib/DemPropertyField/RestrictedValuesEditor.tsx +63 -0
  27. package/src/lib/DemPropertyField/SingleDemField/SingleDemField.tsx +156 -0
  28. package/src/lib/DemPropertyField/SingleDemField/index.ts +1 -0
  29. package/src/lib/DemPropertyField/index.ts +2 -0
  30. package/src/lib/DemPropertyField/styles.ts +50 -0
  31. package/src/lib/DemPropertyField/widgets/DemBooleanWidget.tsx +26 -0
  32. package/src/lib/DemPropertyField/widgets/DemDateTimeWidget.tsx +34 -0
  33. package/src/lib/DemPropertyField/widgets/DemDateWidget.tsx +33 -0
  34. package/src/lib/DemPropertyField/widgets/DemFieldWidget.tsx +67 -0
  35. package/src/lib/DemPropertyField/widgets/DemFloatWidget.tsx +49 -0
  36. package/src/lib/DemPropertyField/widgets/DemIntegerWidget.tsx +63 -0
  37. package/src/lib/DemPropertyField/widgets/DemJsonWidget.tsx +33 -0
  38. package/src/lib/DemPropertyField/widgets/DemStringWidget.tsx +35 -0
  39. package/src/lib/DemPropertyField/widgets/DemTimeWidget.tsx +46 -0
  40. package/src/lib/DemPropertyField/widgets/index.ts +1 -0
  41. package/src/lib/Forms/BackButton.tsx +45 -0
  42. package/src/lib/Forms/ControlAceEditor.tsx +103 -0
  43. package/src/lib/Forms/ControlAutocomplete.tsx +134 -0
  44. package/src/lib/Forms/ControlCheckbox.tsx +57 -0
  45. package/src/lib/Forms/ControlDebouncedInput.tsx +69 -0
  46. package/src/lib/Forms/ControlInput.tsx +102 -0
  47. package/src/lib/Forms/ControlNumberInput.tsx +144 -0
  48. package/src/lib/Forms/ControlRadioBtn.tsx +46 -0
  49. package/src/lib/Forms/ControlSelect.tsx +135 -0
  50. package/src/lib/Forms/CopyButton.tsx +49 -0
  51. package/src/lib/Forms/index.ts +10 -0
  52. package/src/lib/InfoItem/InfoItem.tsx +39 -0
  53. package/src/lib/InfoItem/index.ts +1 -0
  54. package/src/lib/InfoItem/styles.ts +17 -0
  55. package/src/lib/JsonPathPicker/JsonPathPicker.tsx +71 -0
  56. package/src/lib/JsonPathPicker/PropertyStep.tsx +74 -0
  57. package/src/lib/JsonPathPicker/index.ts +1 -0
  58. package/src/lib/JsonView/JsonView.tsx +43 -0
  59. package/src/lib/JsonView/index.ts +1 -0
  60. package/src/lib/Loader/Loader.tsx +41 -0
  61. package/src/lib/Loader/index.ts +1 -0
  62. package/src/lib/Modals/JsonModalView.tsx +52 -0
  63. package/src/lib/Modals/index.ts +1 -0
  64. package/src/lib/Property/PropertyValueField/BooleanValueField.tsx +41 -0
  65. package/src/lib/Property/PropertyValueField/DateTimeValueField.tsx +59 -0
  66. package/src/lib/Property/PropertyValueField/DateValueField.tsx +59 -0
  67. package/src/lib/Property/PropertyValueField/EntityValueField.tsx +33 -0
  68. package/src/lib/Property/PropertyValueField/JsonValueField.tsx +64 -0
  69. package/src/lib/Property/PropertyValueField/PropertyValue.tsx +97 -0
  70. package/src/lib/Property/PropertyValueField/PropertyValueField.tsx +86 -0
  71. package/src/lib/Property/PropertyValueField/StringValueField.tsx +21 -0
  72. package/src/lib/Property/PropertyValueField/TimeValueField.tsx +68 -0
  73. package/src/lib/Property/PropertyValueField/ValueComponent.tsx +63 -0
  74. package/src/lib/Property/PropertyValueField/index.ts +1 -0
  75. package/src/lib/Property/PropertyWidget/PropertyWidget.tsx +167 -0
  76. package/src/lib/Property/PropertyWidget/index.ts +1 -0
  77. package/src/lib/Property/UpsertProperty/CreatePropertiesList.tsx +131 -0
  78. package/src/lib/Property/UpsertProperty/CreatePropertyFormFields.tsx +147 -0
  79. package/src/lib/Property/UpsertProperty/CustomPropertyField.tsx +40 -0
  80. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/BigDecimalPropertyFields.tsx +41 -0
  81. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/DateAdditionalFields.tsx +27 -0
  82. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/EntityAdditionalFields.tsx +133 -0
  83. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/EntityReferencePropertyFields.tsx +46 -0
  84. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/PropertyAdditionalFields.tsx +52 -0
  85. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/StringPropertyFields.tsx +98 -0
  86. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/index.ts +1 -0
  87. package/src/lib/Property/UpsertProperty/index.ts +2 -0
  88. package/src/lib/Property/UpsertProperty/useCustomFields.ts +22 -0
  89. package/src/lib/Property/ViewPropertiesList/ViewPropertiesList.tsx +50 -0
  90. package/src/lib/Property/ViewPropertiesList/index.ts +1 -0
  91. package/src/lib/Property/ViewProperty/EntityPropertiesShortView.tsx +41 -0
  92. package/src/lib/Property/ViewProperty/EntityPropertiesView.tsx +48 -0
  93. package/src/lib/Property/ViewProperty/PropertyDataTable.tsx +139 -0
  94. package/src/lib/Property/ViewProperty/PropertyItem.tsx +46 -0
  95. package/src/lib/Property/ViewProperty/ViewProperty.tsx +52 -0
  96. package/src/lib/Property/ViewProperty/index.ts +1 -0
  97. package/src/lib/Property/index.ts +4 -0
  98. package/src/lib/Status/Status.tsx +15 -0
  99. package/src/lib/Status/index.ts +1 -0
  100. package/src/lib/Status/styles.ts +14 -0
  101. package/src/lib/Table/Table.tsx +116 -0
  102. package/src/lib/Table/TableColumnMenu.tsx +12 -0
  103. package/src/lib/Table/TablePagination.tsx +42 -0
  104. package/src/lib/Table/index.ts +1 -0
  105. package/src/lib/Table/styles.ts +59 -0
  106. package/src/lib/Table/usePagination.ts +15 -0
  107. package/src/lib/Table/useTableQueryPagination.ts +49 -0
  108. package/src/lib/Table/useTableQuerySorting.ts +52 -0
  109. package/src/lib/Tabs/RouteTabs.tsx +54 -0
  110. package/src/lib/Tabs/TabPanel.tsx +42 -0
  111. package/src/lib/Tabs/index.ts +2 -0
  112. package/src/lib/TemplateContent/ExpressionDecorator.tsx +7 -0
  113. package/src/lib/TemplateContent/TemplateContentEditor.tsx +144 -0
  114. package/src/lib/TemplateContent/index.ts +1 -0
  115. package/src/lib/index.ts +14 -0
  116. package/src/utils/common.ts +68 -0
  117. package/src/utils/dem.ts +78 -0
  118. package/src/utils/hooks.ts +41 -0
  119. package/src/utils/index.ts +5 -0
  120. package/src/utils/ui-utils.tsx +71 -0
  121. package/src/utils/validators.ts +130 -0
  122. package/tsconfig.json +24 -0
  123. package/tsconfig.lib.json +22 -0
  124. package/tsconfig.spec.json +19 -0
@@ -0,0 +1,131 @@
1
+ import Grid from '@material-ui/core/Grid';
2
+ import Button from '@material-ui/core/Button';
3
+ import Typography from '@material-ui/core/Typography';
4
+ import Accordion from '@material-ui/core/Accordion';
5
+ import AccordionSummary from '@material-ui/core/AccordionSummary';
6
+ import AccordionDetails from '@material-ui/core/AccordionDetails';
7
+ import AccordionActions from '@material-ui/core/AccordionActions';
8
+ import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
9
+ import CreatePropertyFormFields from './CreatePropertyFormFields';
10
+
11
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
12
+ import { useController, useFormContext, useWatch } from 'react-hook-form';
13
+ import { removeArrayItem } from '../../../utils';
14
+ import { CustomPropertyFieldProps } from '../../../interfaces';
15
+
16
+ type Props = {
17
+ parentFieldName?: string;
18
+ hideAddButton?: boolean;
19
+ focusOnIndex?: number;
20
+ required?: boolean;
21
+ entityDefinition?: boolean;
22
+ globalParameter?: boolean;
23
+ customPropertyFields?: CustomPropertyFieldProps[];
24
+ };
25
+
26
+ const defaultPropertyValues = {
27
+ key: '',
28
+ propertyType: '',
29
+ name: '',
30
+ defaultValue: '',
31
+ defaultValues: [],
32
+ isRequired: true,
33
+ isMultiple: false,
34
+ sortOrder: 0,
35
+ isEnabled: true,
36
+ executeValue: '',
37
+ uiSettings: '',
38
+ };
39
+
40
+ export const CreatePropertiesList = ({
41
+ parentFieldName,
42
+ hideAddButton,
43
+ focusOnIndex,
44
+ required,
45
+ entityDefinition = false,
46
+ globalParameter = false,
47
+ customPropertyFields = [],
48
+ }: Props) => {
49
+ const fieldName = useMemo(
50
+ () => (parentFieldName ? `${parentFieldName}.properties` : `properties`),
51
+ [parentFieldName]
52
+ );
53
+
54
+ const { setValue, clearErrors, control } = useFormContext();
55
+ const {
56
+ fieldState: { error },
57
+ } = useController({ control, name: fieldName, rules: { required: required && 'Please, add properties' } });
58
+ const properties = useWatch({ control, name: fieldName });
59
+
60
+ const refs = useRef([]);
61
+
62
+ useEffect(() => {
63
+ if (typeof focusOnIndex === 'number' && refs.current[focusOnIndex]) {
64
+ refs.current[focusOnIndex].scrollIntoView({
65
+ behavior: 'smooth',
66
+ block: 'start',
67
+ });
68
+ }
69
+ }, [focusOnIndex, refs]);
70
+
71
+ const handleAddParameter = useCallback(() => {
72
+ if (properties) {
73
+ setValue(`${fieldName}.${properties.length}`, defaultPropertyValues);
74
+ } else {
75
+ setValue(fieldName, [defaultPropertyValues]);
76
+ }
77
+ clearErrors(fieldName);
78
+ }, [properties, fieldName]);
79
+
80
+ const handleRemoveParameter = useCallback(
81
+ (index) => {
82
+ setValue(`${fieldName}`, removeArrayItem(properties, index));
83
+ },
84
+ [properties, fieldName]
85
+ );
86
+
87
+ return (
88
+ <>
89
+ {error && error.message && (
90
+ <Grid item sm={12} md={8} lg={6}>
91
+ <Typography color="secondary">{error.message}</Typography>
92
+ </Grid>
93
+ )}
94
+ {properties &&
95
+ properties.map((property, index) => (
96
+ <Grid item key={index} sm={12} md={8} lg={6} innerRef={(ref) => (refs.current[index] = ref)}>
97
+ <Accordion defaultExpanded elevation={3}>
98
+ <AccordionSummary expandIcon={<ExpandMoreIcon />}>
99
+ <Typography color={error && error[index] ? 'secondary' : 'initial'} style={{ wordBreak: 'break-word' }}>
100
+ {property.name || `Property ${index + 1}`}
101
+ </Typography>
102
+ </AccordionSummary>
103
+ <AccordionDetails>
104
+ <CreatePropertyFormFields
105
+ propertyFieldName={`${fieldName}.${index}`}
106
+ entityDefinition={entityDefinition}
107
+ globalParameter={globalParameter}
108
+ customPropertyFields={customPropertyFields}
109
+ />
110
+ </AccordionDetails>
111
+ <AccordionActions>
112
+ <Button variant="contained" size="small" color="secondary" onClick={() => handleRemoveParameter(index)}>
113
+ Remove
114
+ </Button>
115
+ </AccordionActions>
116
+ </Accordion>
117
+ </Grid>
118
+ ))}
119
+
120
+ {!hideAddButton && (
121
+ <Grid item xs={12}>
122
+ <Button variant="contained" size="small" color="primary" onClick={handleAddParameter}>
123
+ Add property
124
+ </Button>
125
+ </Grid>
126
+ )}
127
+ </>
128
+ );
129
+ };
130
+
131
+ export default CreatePropertiesList;
@@ -0,0 +1,147 @@
1
+ import Grid from '@material-ui/core/Grid';
2
+ import {
3
+ ControlCheckbox,
4
+ ControlAutocomplete,
5
+ ControlNumberInput,
6
+ ControlAceEditor,
7
+ ControlDebouncedInput,
8
+ } from '../../Forms';
9
+ import { PropertyAdditionalFields } from './PropertyAdditionalFields';
10
+ import { PropertyValueField } from '../PropertyValueField';
11
+ import CustomPropertyField from './CustomPropertyField';
12
+
13
+ import { useMemo } from 'react';
14
+ import { useFormContext, useWatch } from 'react-hook-form';
15
+ import useCustomFields from './useCustomFields';
16
+
17
+ import { CustomPropertyFieldProps, PropertyType } from '../../../interfaces';
18
+
19
+ type Props = {
20
+ propertyFieldName: string;
21
+ entityDefinition?: boolean;
22
+ globalParameter?: boolean;
23
+ customPropertyFields?: CustomPropertyFieldProps[];
24
+ };
25
+
26
+ const propertyTypes = Object.values(PropertyType)
27
+ .sort((a, b) => a.localeCompare(b))
28
+ .map((propType) => ({
29
+ value: propType,
30
+ label: propType
31
+ .replace('_', ' ')
32
+ .toLowerCase()
33
+ .replace(/(^\w)|([-\s]\w)/g, (c) => c.toUpperCase()),
34
+ }));
35
+
36
+ const CreatePropertyFormFields = ({
37
+ propertyFieldName,
38
+ entityDefinition = false,
39
+ globalParameter = false,
40
+ customPropertyFields = [],
41
+ }: Props) => {
42
+ const { control, setValue } = useFormContext();
43
+ const propertyType = useWatch({ control, name: `${propertyFieldName}.propertyType` });
44
+ const isMultiple = useWatch({ control, name: `${propertyFieldName}.isMultiple` });
45
+ const isRequired = useWatch({ control, name: `${propertyFieldName}.isRequired` });
46
+
47
+ const { customCheckboxes, customFields } = useCustomFields(customPropertyFields);
48
+
49
+ const valueLabel = useMemo(() => {
50
+ let label = globalParameter ? 'Value' : 'Default Value';
51
+ if (isMultiple) {
52
+ label += 's';
53
+ }
54
+ return label;
55
+ }, [globalParameter, isMultiple]);
56
+
57
+ const handlePropertyTypeChange = (fieldName, value) => {
58
+ const valueFieldName = `${propertyFieldName}.${globalParameter ? 'value' : 'defaultValue'}`;
59
+ if (isMultiple) {
60
+ setValue(valueFieldName, []);
61
+ } else {
62
+ setValue(valueFieldName, null);
63
+ }
64
+ setValue(fieldName, value);
65
+ };
66
+
67
+ return (
68
+ <Grid container direction="column" spacing={2}>
69
+ <Grid item>
70
+ <ControlDebouncedInput required control={control} name={`${propertyFieldName}.key`} label="Key" />
71
+ </Grid>
72
+ <Grid item>
73
+ <ControlDebouncedInput required control={control} name={`${propertyFieldName}.name`} label="Name" />
74
+ </Grid>
75
+ <Grid item>
76
+ <ControlAutocomplete
77
+ required
78
+ control={control}
79
+ name={`${propertyFieldName}.propertyType`}
80
+ label="Type"
81
+ options={propertyTypes}
82
+ onChange={handlePropertyTypeChange}
83
+ />
84
+ </Grid>
85
+ <Grid item>
86
+ <ControlNumberInput required control={control} name={`${propertyFieldName}.sortOrder`} label="Sort Order" />
87
+ </Grid>
88
+
89
+ <Grid item>
90
+ <ControlAceEditor control={control} name={`${propertyFieldName}.uiSettings`} label="UI Settings" validateJson />
91
+ </Grid>
92
+ <Grid item>
93
+ <ControlCheckbox control={control} name={`${propertyFieldName}.isMultiple`} label="Multiple" />
94
+ <ControlCheckbox control={control} name={`${propertyFieldName}.isEnabled`} label="Enabled" />
95
+ <ControlCheckbox control={control} name={`${propertyFieldName}.isRequired`} label="Required" />
96
+ {entityDefinition && (
97
+ <ControlCheckbox
98
+ control={control}
99
+ name={`${propertyFieldName}.isViewableInList`}
100
+ label="Is viewable in list"
101
+ />
102
+ )}
103
+ {customCheckboxes.length ? (
104
+ <>
105
+ {customCheckboxes.map((field, index) => (
106
+ <ControlCheckbox
107
+ key={index}
108
+ control={control}
109
+ name={`${propertyFieldName}.${field.name}`}
110
+ label={field.label}
111
+ />
112
+ ))}
113
+ </>
114
+ ) : null}
115
+ </Grid>
116
+ {propertyType && (
117
+ <>
118
+ <PropertyAdditionalFields
119
+ propertyType={typeof propertyType === 'string' ? propertyType : propertyType.value}
120
+ propertyFieldName={propertyFieldName}
121
+ globalParameter={globalParameter}
122
+ entityDefinition={entityDefinition}
123
+ />
124
+ <Grid item>
125
+ <PropertyValueField
126
+ propertyFieldName={propertyFieldName}
127
+ name={`${propertyFieldName}.${globalParameter ? 'value' : 'defaultValue'}`}
128
+ label={valueLabel}
129
+ required={globalParameter ? isRequired : false}
130
+ />
131
+ </Grid>
132
+ </>
133
+ )}
134
+ {customFields.length ? (
135
+ <>
136
+ {customFields.map((field, index) => (
137
+ <Grid item key={index}>
138
+ <CustomPropertyField {...field} propertyFieldName={propertyFieldName} />
139
+ </Grid>
140
+ ))}
141
+ </>
142
+ ) : null}
143
+ </Grid>
144
+ );
145
+ };
146
+
147
+ export default CreatePropertyFormFields;
@@ -0,0 +1,40 @@
1
+ import { useMemo } from 'react';
2
+ import { useFormContext } from 'react-hook-form';
3
+ import { CustomPropertyFieldProps } from '../../../interfaces';
4
+ import { ControlAceEditor, ControlAutocomplete, ControlInput, ControlNumberInput, ControlSelect } from '../../Forms';
5
+
6
+ type Props = CustomPropertyFieldProps & { propertyFieldName: string };
7
+
8
+ export const CustomPropertyField = ({
9
+ name,
10
+ label = '',
11
+ propertyFieldName,
12
+ type,
13
+ decimal = false,
14
+ options = [],
15
+ required = false,
16
+ }: Props) => {
17
+ const { control } = useFormContext();
18
+ const fieldName = useMemo(() => `${propertyFieldName}.${name}`, [name, propertyFieldName]);
19
+
20
+ switch (type) {
21
+ case 'text':
22
+ return <ControlInput control={control} name={fieldName} label={label} required={required} />;
23
+ case 'number':
24
+ return (
25
+ <ControlNumberInput control={control} name={fieldName} label={label} decimal={decimal} required={required} />
26
+ );
27
+ case 'select':
28
+ return <ControlSelect control={control} name={fieldName} label={label} options={options} required={required} />;
29
+ case 'autocomplete':
30
+ return (
31
+ <ControlAutocomplete control={control} name={fieldName} label={label} options={options} required={required} />
32
+ );
33
+ case 'json':
34
+ return <ControlAceEditor control={control} name={fieldName} label={label} mode="json" required={required} />;
35
+ default:
36
+ return null;
37
+ }
38
+ };
39
+
40
+ export default CustomPropertyField;
@@ -0,0 +1,41 @@
1
+ import Grid from '@material-ui/core/Grid';
2
+ import { ControlNumberInput, ControlSelect } from '../../../Forms';
3
+ import { RoundingMode } from '../../../../interfaces';
4
+
5
+ import { useFormContext } from 'react-hook-form';
6
+
7
+ type Props = {
8
+ propertyFieldName: string;
9
+ };
10
+
11
+ const roundingModes = Object.values(RoundingMode).sort((a, b) => a.localeCompare(b));
12
+
13
+ const BigDecimalPropertyFields = ({ propertyFieldName }: Props) => {
14
+ const { control } = useFormContext();
15
+
16
+ return (
17
+ <>
18
+ <Grid item>
19
+ <ControlNumberInput
20
+ required
21
+ control={control}
22
+ defaultValue={2}
23
+ name={`${propertyFieldName}.precisionScale`}
24
+ label="Precision Scale"
25
+ />
26
+ </Grid>
27
+ <Grid item>
28
+ <ControlSelect
29
+ required
30
+ control={control}
31
+ name={`${propertyFieldName}.roundingMode`}
32
+ label="Rounding Mode"
33
+ defaultValue={RoundingMode.HALF_UP}
34
+ options={roundingModes}
35
+ />
36
+ </Grid>
37
+ </>
38
+ );
39
+ };
40
+
41
+ export default BigDecimalPropertyFields;
@@ -0,0 +1,27 @@
1
+ import Grid from '@material-ui/core/Grid';
2
+ import { ControlInput } from '../../../Forms';
3
+
4
+ import { useFormContext } from 'react-hook-form';
5
+
6
+ type Props = {
7
+ propertyFieldName: string;
8
+ defaultValue?: string;
9
+ };
10
+
11
+ const DateAdditionalFields = ({ propertyFieldName, defaultValue = '' }: Props) => {
12
+ const { control } = useFormContext();
13
+
14
+ return (
15
+ <Grid item>
16
+ <ControlInput
17
+ required
18
+ control={control}
19
+ defaultValue={defaultValue}
20
+ name={`${propertyFieldName}.format`}
21
+ label="Format"
22
+ />
23
+ </Grid>
24
+ );
25
+ };
26
+
27
+ export default DateAdditionalFields;
@@ -0,0 +1,133 @@
1
+ import Grid from '@material-ui/core/Grid';
2
+ import Button from '@material-ui/core/Button';
3
+ import Typography from '@material-ui/core/Typography';
4
+ import Dialog from '@material-ui/core/Dialog';
5
+ import DialogTitle from '@material-ui/core/DialogTitle';
6
+ import DialogContent from '@material-ui/core/DialogContent';
7
+ import DialogActions from '@material-ui/core/DialogActions';
8
+ import Stepper from '@material-ui/core/Stepper';
9
+ import Step from '@material-ui/core/Step';
10
+ import StepLabel from '@material-ui/core/StepLabel';
11
+ import StepContent from '@material-ui/core/StepContent';
12
+ import CreatePropertiesList from '../CreatePropertiesList';
13
+ import EntityPropertiesShortView from '../../ViewProperty/EntityPropertiesShortView';
14
+
15
+ import { useCallback, useState } from 'react';
16
+ import { useFormContext, useWatch } from 'react-hook-form';
17
+ import { useToggle } from '../../../../utils';
18
+
19
+ type Props = {
20
+ parentPropertyFieldName: string;
21
+ entityDefinition?: boolean;
22
+ globalParameter?: boolean;
23
+ };
24
+
25
+ const defaultPropertyValues = {
26
+ key: '',
27
+ propertyType: '',
28
+ name: '',
29
+ defaultValue: '',
30
+ isRequired: true,
31
+ isMultiple: false,
32
+ sortOrder: 0,
33
+ isEnabled: true,
34
+ };
35
+
36
+ const EntityAdditionalFields = ({
37
+ parentPropertyFieldName,
38
+ entityDefinition = false,
39
+ globalParameter = false,
40
+ }: Props) => {
41
+ const { control, setValue, getValues, trigger } = useFormContext();
42
+ const properties = useWatch({
43
+ control,
44
+ name: `${parentPropertyFieldName}.properties`,
45
+ defaultValue: getValues(`${parentPropertyFieldName}.properties`) || [],
46
+ });
47
+
48
+ const parentPropertyName = useWatch({ control, name: `${parentPropertyFieldName}.name` });
49
+
50
+ const { open: parametersModalOpen, onClose: onParametersModalClose, onOpen: onParametersModalOpen } = useToggle();
51
+
52
+ const [focusedProperty, setFocusedProperty] = useState(0);
53
+
54
+ const handleAddParameter = useCallback(() => {
55
+ if (properties) {
56
+ setValue(`${parentPropertyFieldName}.properties.${properties.length}`, defaultPropertyValues);
57
+ } else {
58
+ setValue(`${parentPropertyFieldName}.properties`, [defaultPropertyValues]);
59
+ }
60
+ }, [properties, parentPropertyFieldName, setValue]);
61
+
62
+ const handleStepperClick = (index) => setFocusedProperty(index);
63
+
64
+ const handleSubmitClick = async () => {
65
+ const isValid = await trigger(`${parentPropertyFieldName}.properties`);
66
+ if (isValid) {
67
+ onParametersModalClose();
68
+ }
69
+ };
70
+
71
+ return (
72
+ <>
73
+ <Grid item>
74
+ <Typography variant="h6">Properties</Typography>
75
+ </Grid>
76
+ <Grid item>
77
+ <EntityPropertiesShortView properties={properties} showName showType />
78
+ </Grid>
79
+ <Grid item>
80
+ <Button variant="contained" color="primary" onClick={onParametersModalOpen}>
81
+ Edit properties
82
+ </Button>
83
+ </Grid>
84
+
85
+ <Dialog disableEscapeKeyDown open={parametersModalOpen} onClose={handleSubmitClick} fullWidth maxWidth="md">
86
+ <DialogTitle>{parentPropertyName || 'Entity'} Properties</DialogTitle>
87
+ <DialogContent style={{ height: '500px', overflow: 'hidden' }}>
88
+ <Grid container direction="row" spacing={2} style={{ height: '100%' }}>
89
+ <Grid item xs={3} style={{ backgroundColor: '#f9f9f9' }}>
90
+ <Stepper nonLinear activeStep={focusedProperty} orientation="vertical" style={{ paddingLeft: '4px' }}>
91
+ {properties.map((property, index) => (
92
+ <Step key={index} onClick={() => handleStepperClick(index)} style={{ cursor: 'pointer' }}>
93
+ <StepLabel StepIconProps={{ icon: '' }} style={{ wordBreak: 'break-word' }}>
94
+ {property.name || '(no name)'}
95
+ </StepLabel>
96
+ <StepContent></StepContent>
97
+ </Step>
98
+ ))}
99
+ </Stepper>
100
+ <Button variant="contained" size="small" color="primary" onClick={handleAddParameter}>
101
+ Add property
102
+ </Button>
103
+ </Grid>
104
+ <Grid
105
+ item
106
+ container
107
+ wrap="nowrap"
108
+ direction="column"
109
+ xs={9}
110
+ spacing={2}
111
+ style={{ height: '100%', overflowY: 'auto' }}
112
+ >
113
+ <CreatePropertiesList
114
+ hideAddButton
115
+ parentFieldName={parentPropertyFieldName}
116
+ focusOnIndex={focusedProperty}
117
+ entityDefinition={entityDefinition}
118
+ globalParameter={globalParameter}
119
+ />
120
+ </Grid>
121
+ </Grid>
122
+ </DialogContent>
123
+ <DialogActions>
124
+ <Button variant="contained" color="primary" onClick={handleSubmitClick}>
125
+ Ok
126
+ </Button>
127
+ </DialogActions>
128
+ </Dialog>
129
+ </>
130
+ );
131
+ };
132
+
133
+ export default EntityAdditionalFields;
@@ -0,0 +1,46 @@
1
+ import Grid from '@material-ui/core/Grid';
2
+ import { ControlInput } from '../../../Forms';
3
+
4
+ import { useFormContext } from 'react-hook-form';
5
+
6
+ type Props = {
7
+ propertyFieldName: string;
8
+ };
9
+
10
+ const EntityReferencePropertyFields = ({ propertyFieldName }: Props) => {
11
+ const { control } = useFormContext();
12
+
13
+ return (
14
+ <>
15
+ <Grid item>
16
+ <ControlInput required control={control} name={`${propertyFieldName}.definitionCode`} label="Definition Code" />
17
+ </Grid>
18
+ <Grid item>
19
+ <ControlInput
20
+ required
21
+ control={control}
22
+ name={`${propertyFieldName}.definitionVersion`}
23
+ label="Definition Version"
24
+ />
25
+ </Grid>
26
+ <Grid item>
27
+ <ControlInput
28
+ required
29
+ control={control}
30
+ name={`${propertyFieldName}.labelPropertyCode`}
31
+ label="Label Property Code"
32
+ />
33
+ </Grid>
34
+ <Grid item>
35
+ <ControlInput
36
+ required
37
+ control={control}
38
+ name={`${propertyFieldName}.valuePropertyCode`}
39
+ label="Value Property Code"
40
+ />
41
+ </Grid>
42
+ </>
43
+ );
44
+ };
45
+
46
+ export default EntityReferencePropertyFields;
@@ -0,0 +1,52 @@
1
+ import {
2
+ PropertyType,
3
+ DATE_DEFAULT_FORMAT,
4
+ DATE_TIME_DEFAULT_FORMAT,
5
+ TIME_DEFAULT_FORMAT,
6
+ } from '../../../../interfaces';
7
+ import BigDecimalPropertyFields from './BigDecimalPropertyFields';
8
+ import DateAdditionalFields from './DateAdditionalFields';
9
+ import EntityAdditionalFields from './EntityAdditionalFields';
10
+ import EntityReferencePropertyFields from './EntityReferencePropertyFields';
11
+ import StringPropertyFields from './StringPropertyFields';
12
+
13
+ type Props = {
14
+ propertyType: PropertyType;
15
+ propertyFieldName: string;
16
+ entityDefinition?: boolean;
17
+ globalParameter?: boolean;
18
+ };
19
+
20
+ export const PropertyAdditionalFields = ({
21
+ propertyType,
22
+ propertyFieldName,
23
+ entityDefinition = false,
24
+ globalParameter = false,
25
+ }: Props) => {
26
+ switch (propertyType) {
27
+ case PropertyType.STRING:
28
+ return <StringPropertyFields propertyFieldName={propertyFieldName} />;
29
+ case PropertyType.BIG_DECIMAL:
30
+ return <BigDecimalPropertyFields propertyFieldName={propertyFieldName} />;
31
+ case PropertyType.DATE:
32
+ return <DateAdditionalFields propertyFieldName={propertyFieldName} defaultValue={DATE_DEFAULT_FORMAT} />;
33
+ case PropertyType.TIME:
34
+ return <DateAdditionalFields propertyFieldName={propertyFieldName} defaultValue={TIME_DEFAULT_FORMAT} />;
35
+ case PropertyType.DATE_TIME:
36
+ return <DateAdditionalFields propertyFieldName={propertyFieldName} defaultValue={DATE_TIME_DEFAULT_FORMAT} />;
37
+ case PropertyType.ENTITY_REFERENCE:
38
+ return <EntityReferencePropertyFields propertyFieldName={propertyFieldName} />;
39
+ case PropertyType.ENTITY:
40
+ return (
41
+ <EntityAdditionalFields
42
+ parentPropertyFieldName={propertyFieldName}
43
+ globalParameter={globalParameter}
44
+ entityDefinition={entityDefinition}
45
+ />
46
+ );
47
+ default:
48
+ return null;
49
+ }
50
+ };
51
+
52
+ export default PropertyAdditionalFields;