@dartech/arsenal-ui 1.2.4 → 1.2.6

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 (271) hide show
  1. package/.babelrc +13 -0
  2. package/.eslintrc.json +22 -0
  3. package/{index.d.ts → index.ts} +5 -5
  4. package/jest.config.ts +11 -0
  5. package/package.json +3 -12
  6. package/project.json +94 -0
  7. package/rollup.config.js +146 -0
  8. package/src/assets/chevron_left_gray.svg +3 -0
  9. package/src/consts/index.ts +13 -0
  10. package/src/interfaces/common.ts +18 -0
  11. package/src/interfaces/definition.ts +143 -0
  12. package/src/interfaces/{index.d.ts → index.ts} +3 -3
  13. package/src/interfaces/ui.ts +80 -0
  14. package/src/lib/Alert/Alert.tsx +108 -0
  15. package/src/lib/Alert/index.ts +1 -0
  16. package/src/lib/Breadcrumbs/Breadcrumbs.styled.tsx +16 -0
  17. package/src/lib/Breadcrumbs/Breadcrumbs.tsx +40 -0
  18. package/src/lib/Breadcrumbs/{index.d.ts → index.ts} +1 -1
  19. package/src/lib/ContentLayout/ContentLayout.tsx +31 -0
  20. package/src/lib/ContentLayout/index.ts +1 -0
  21. package/src/lib/Definition/CreateDefinition/CreateDefinition.tsx +78 -0
  22. package/src/lib/Definition/CreateDefinition/{index.d.ts → index.ts} +1 -1
  23. package/src/lib/Definition/DefinitionFiller/DefinitionFiller.tsx +71 -0
  24. package/src/lib/Definition/DefinitionFiller/{index.d.ts → index.ts} +1 -1
  25. package/src/lib/Definition/DefinitionValueView/DefinitionValueView.tsx +54 -0
  26. package/src/lib/Definition/DefinitionValueView/PropertyDataView.tsx +67 -0
  27. package/src/lib/Definition/DefinitionValueView/{index.d.ts → index.ts} +1 -1
  28. package/src/lib/Definition/{index.d.ts → index.ts} +3 -3
  29. package/src/lib/Forms/BackButton.tsx +46 -0
  30. package/src/lib/Forms/ControlAceEditor.tsx +125 -0
  31. package/src/lib/Forms/ControlAutocomplete.tsx +145 -0
  32. package/src/lib/Forms/ControlCheckbox.tsx +113 -0
  33. package/src/lib/Forms/ControlDate.tsx +75 -0
  34. package/src/lib/Forms/ControlDateTime.tsx +77 -0
  35. package/src/lib/Forms/ControlDebouncedInput.tsx +80 -0
  36. package/src/lib/Forms/ControlInput.tsx +111 -0
  37. package/src/lib/Forms/ControlNumberInput.tsx +121 -0
  38. package/src/lib/Forms/ControlQueryAutocomplete.tsx +197 -0
  39. package/src/lib/Forms/ControlRadio.tsx +136 -0
  40. package/src/lib/Forms/ControlSelect.tsx +164 -0
  41. package/src/lib/Forms/ControlSwitch.tsx +71 -0
  42. package/src/lib/Forms/ControlTime.tsx +93 -0
  43. package/src/lib/Forms/CopyButton.tsx +46 -0
  44. package/src/lib/Forms/{index.d.ts → index.ts} +15 -15
  45. package/src/lib/Forms/useAutocomplete.tsx +47 -0
  46. package/src/lib/InfoItem/InfoItem.tsx +40 -0
  47. package/src/lib/InfoItem/{index.d.ts → index.ts} +1 -1
  48. package/src/lib/InfoItem/styles.ts +17 -0
  49. package/src/lib/JsonPathPicker/JsonPathPicker.tsx +73 -0
  50. package/src/lib/JsonPathPicker/PropertyStep.tsx +70 -0
  51. package/src/lib/JsonPathPicker/{index.d.ts → index.ts} +1 -1
  52. package/src/lib/JsonView/JsonView.tsx +41 -0
  53. package/src/lib/JsonView/{index.d.ts → index.ts} +1 -1
  54. package/src/lib/Loader/Loader.tsx +41 -0
  55. package/src/lib/Loader/{index.d.ts → index.ts} +1 -1
  56. package/src/lib/Modals/JsonModalView.tsx +53 -0
  57. package/src/lib/Modals/{index.d.ts → index.ts} +1 -1
  58. package/src/lib/Property/PropertyFiller/JsonEditor.tsx +58 -0
  59. package/src/lib/Property/PropertyFiller/MultiplePropertyFiller.tsx +129 -0
  60. package/src/lib/Property/PropertyFiller/MultiplePropertyWidget.tsx +85 -0
  61. package/src/lib/Property/PropertyFiller/PropertyFiller.tsx +199 -0
  62. package/src/lib/Property/PropertyFiller/{index.d.ts → index.ts} +2 -2
  63. package/src/lib/Property/PropertyFiller/usePropertyFiller.ts +72 -0
  64. package/src/lib/Property/PropertyFiller/useStyles.ts +12 -0
  65. package/src/lib/Property/PropertyValidator/NodeValidator.tsx +92 -0
  66. package/src/lib/Property/PropertyValidator/NodesList.tsx +26 -0
  67. package/src/lib/Property/PropertyValidator/NumericTypeValidator.tsx +59 -0
  68. package/src/lib/Property/PropertyValidator/PropertyValidator.tsx +42 -0
  69. package/src/lib/Property/PropertyValidator/PropertyValidatorContext.tsx +4 -0
  70. package/src/lib/Property/PropertyValidator/StringTypeValidator.tsx +36 -0
  71. package/src/lib/Property/PropertyValidator/ValidationNodeSelector.tsx +62 -0
  72. package/src/lib/Property/PropertyValidator/index.ts +1 -0
  73. package/src/lib/Property/PropertyValueField/BooleanValueField.tsx +49 -0
  74. package/src/lib/Property/PropertyValueField/DateTimeValueField.tsx +58 -0
  75. package/src/lib/Property/PropertyValueField/DateValueField.tsx +58 -0
  76. package/src/lib/Property/PropertyValueField/JsonValueField.tsx +65 -0
  77. package/src/lib/Property/PropertyValueField/PropertyValueField.tsx +49 -0
  78. package/src/lib/Property/PropertyValueField/StringValueField.tsx +50 -0
  79. package/src/lib/Property/PropertyValueField/TimeValueField.tsx +67 -0
  80. package/src/lib/Property/PropertyValueField/{index.d.ts → index.ts} +1 -1
  81. package/src/lib/Property/PropertyWidget/PropertyWidget.tsx +115 -0
  82. package/src/lib/Property/PropertyWidget/{index.d.ts → index.ts} +1 -1
  83. package/src/lib/Property/UpsertProperty/CreatePropertiesList.tsx +148 -0
  84. package/src/lib/Property/UpsertProperty/CreatePropertyFormFields.tsx +158 -0
  85. package/src/lib/Property/UpsertProperty/CustomPropertyField.tsx +40 -0
  86. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/BigDecimalPropertyFields.tsx +41 -0
  87. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/DateAdditionalFields.tsx +27 -0
  88. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/EntityAdditionalFields.tsx +133 -0
  89. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/EntityReferencePropertyFields.tsx +46 -0
  90. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/PropertyAdditionalFields.tsx +52 -0
  91. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/StringPropertyFields.tsx +103 -0
  92. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/{index.d.ts → index.ts} +1 -1
  93. package/src/lib/Property/UpsertProperty/{index.d.ts → index.ts} +2 -2
  94. package/src/lib/Property/UpsertProperty/useCustomFields.ts +22 -0
  95. package/src/lib/Property/ViewPropertiesList/ViewPropertiesList.tsx +37 -0
  96. package/src/lib/Property/ViewPropertiesList/{index.d.ts → index.ts} +1 -1
  97. package/src/lib/Property/ViewProperty/EntityPropertiesShortView.tsx +40 -0
  98. package/src/lib/Property/ViewProperty/EntityPropertiesView.tsx +48 -0
  99. package/src/lib/Property/ViewProperty/PropertyDataTable.tsx +148 -0
  100. package/src/lib/Property/ViewProperty/PropertyItem.tsx +43 -0
  101. package/src/lib/Property/ViewProperty/ViewProperty.tsx +52 -0
  102. package/src/lib/Property/ViewProperty/{index.d.ts → index.ts} +1 -1
  103. package/src/lib/Property/{index.d.ts → index.ts} +5 -5
  104. package/src/lib/Sidebar/Sidebar.styled.tsx +157 -0
  105. package/src/lib/Sidebar/Sidebar.tsx +27 -0
  106. package/src/lib/Sidebar/SidebarContext.tsx +37 -0
  107. package/src/lib/Sidebar/SidebarDrawer.tsx +50 -0
  108. package/src/lib/Sidebar/SidebarLink/MenuIcon.tsx +16 -0
  109. package/src/lib/Sidebar/SidebarLink/SidebarLink.tsx +54 -0
  110. package/src/lib/Sidebar/SidebarLink/SidebarLinkItem.tsx +54 -0
  111. package/src/lib/Sidebar/SidebarLink/SidebarNestedItem.tsx +62 -0
  112. package/src/lib/Sidebar/SidebarLink/{index.d.ts → index.ts} +2 -2
  113. package/src/lib/Sidebar/index.ts +2 -0
  114. package/src/lib/Status/Status.tsx +16 -0
  115. package/src/lib/Status/{index.d.ts → index.ts} +1 -1
  116. package/src/lib/Status/styles.ts +21 -0
  117. package/src/lib/StepperView/StepperView.tsx +73 -0
  118. package/src/lib/StepperView/{index.d.ts → index.ts} +1 -1
  119. package/src/lib/Table/DataGrid/JsonTypeCell.tsx +51 -0
  120. package/src/lib/Table/DataGrid/Table.tsx +117 -0
  121. package/src/lib/Table/DataGrid/TableAction.tsx +43 -0
  122. package/src/lib/Table/DataGrid/TableColumnMenu.tsx +12 -0
  123. package/src/lib/Table/DataGrid/TablePagination.tsx +42 -0
  124. package/src/lib/Table/DataGrid/index.ts +2 -0
  125. package/src/lib/Table/DataGrid/styles.ts +59 -0
  126. package/src/lib/Table/DataGrid/usePagination.ts +15 -0
  127. package/src/lib/Table/DataGrid/useTableQueryPagination.ts +47 -0
  128. package/src/lib/Table/DataGrid/useTableQuerySorting.ts +47 -0
  129. package/src/lib/Table/SimpleTable/SimpleTable.tsx +138 -0
  130. package/src/lib/Table/SimpleTable/TableActionCell.tsx +67 -0
  131. package/src/lib/Table/SimpleTable/index.ts +2 -0
  132. package/src/lib/Table/SimpleTable/useTablePagination.ts +54 -0
  133. package/src/lib/Table/SimpleTable/useTableSorting.ts +50 -0
  134. package/src/lib/Table/index.ts +2 -0
  135. package/src/lib/Tabs/RouteTabs.tsx +54 -0
  136. package/src/lib/Tabs/TabPanel.tsx +42 -0
  137. package/src/lib/Tabs/{index.d.ts → index.ts} +2 -2
  138. package/src/lib/{index.d.ts → index.ts} +16 -16
  139. package/src/theme/baseTheme.ts +128 -0
  140. package/src/theme/fonts.d.ts +2 -0
  141. package/src/theme/index.ts +126 -0
  142. package/src/theme/inputThemeOptions.ts +126 -0
  143. package/src/theme/stepperThemeOptions.ts +20 -0
  144. package/src/theme/tableThemeOptions.ts +50 -0
  145. package/src/theme/typographyThemeOptions.ts +32 -0
  146. package/src/utils/common.ts +73 -0
  147. package/src/utils/dem.ts +431 -0
  148. package/src/utils/hooks.ts +41 -0
  149. package/src/utils/{index.d.ts → index.ts} +5 -5
  150. package/src/utils/ui-utils.tsx +132 -0
  151. package/src/utils/validators.ts +14 -0
  152. package/tsconfig.json +25 -0
  153. package/tsconfig.lib.json +23 -0
  154. package/tsconfig.spec.json +20 -0
  155. package/index.js +0 -1
  156. package/src/consts/index.d.ts +0 -12
  157. package/src/interfaces/common.d.ts +0 -17
  158. package/src/interfaces/definition.d.ts +0 -107
  159. package/src/interfaces/ui.d.ts +0 -70
  160. package/src/lib/Alert/Alert.d.ts +0 -53
  161. package/src/lib/Alert/index.d.ts +0 -1
  162. package/src/lib/Breadcrumbs/Breadcrumbs.d.ts +0 -9
  163. package/src/lib/Breadcrumbs/Breadcrumbs.styled.d.ts +0 -2
  164. package/src/lib/ContentLayout/ContentLayout.d.ts +0 -9
  165. package/src/lib/ContentLayout/index.d.ts +0 -1
  166. package/src/lib/Definition/CreateDefinition/CreateDefinition.d.ts +0 -11
  167. package/src/lib/Definition/DefinitionFiller/DefinitionFiller.d.ts +0 -10
  168. package/src/lib/Definition/DefinitionValueView/DefinitionValueView.d.ts +0 -8
  169. package/src/lib/Definition/DefinitionValueView/PropertyDataView.d.ts +0 -9
  170. package/src/lib/Forms/BackButton.d.ts +0 -7
  171. package/src/lib/Forms/ControlAceEditor.d.ts +0 -24
  172. package/src/lib/Forms/ControlAutocomplete.d.ts +0 -69
  173. package/src/lib/Forms/ControlCheckbox.d.ts +0 -51
  174. package/src/lib/Forms/ControlDate.d.ts +0 -18
  175. package/src/lib/Forms/ControlDateTime.d.ts +0 -18
  176. package/src/lib/Forms/ControlDebouncedInput.d.ts +0 -4
  177. package/src/lib/Forms/ControlInput.d.ts +0 -59
  178. package/src/lib/Forms/ControlNumberInput.d.ts +0 -51
  179. package/src/lib/Forms/ControlQueryAutocomplete.d.ts +0 -16
  180. package/src/lib/Forms/ControlRadio.d.ts +0 -66
  181. package/src/lib/Forms/ControlSelect.d.ts +0 -67
  182. package/src/lib/Forms/ControlSwitch.d.ts +0 -19
  183. package/src/lib/Forms/ControlTime.d.ts +0 -18
  184. package/src/lib/Forms/CopyButton.d.ts +0 -20
  185. package/src/lib/Forms/useAutocomplete.d.ts +0 -10
  186. package/src/lib/InfoItem/InfoItem.d.ts +0 -10
  187. package/src/lib/InfoItem/styles.d.ts +0 -12
  188. package/src/lib/JsonPathPicker/JsonPathPicker.d.ts +0 -10
  189. package/src/lib/JsonPathPicker/PropertyStep.d.ts +0 -11
  190. package/src/lib/JsonView/JsonView.d.ts +0 -7
  191. package/src/lib/Loader/Loader.d.ts +0 -21
  192. package/src/lib/Modals/JsonModalView.d.ts +0 -10
  193. package/src/lib/Property/PropertyFiller/JsonEditor.d.ts +0 -10
  194. package/src/lib/Property/PropertyFiller/MultiplePropertyFiller.d.ts +0 -12
  195. package/src/lib/Property/PropertyFiller/MultiplePropertyWidget.d.ts +0 -11
  196. package/src/lib/Property/PropertyFiller/PropertyFiller.d.ts +0 -12
  197. package/src/lib/Property/PropertyFiller/usePropertyFiller.d.ts +0 -24
  198. package/src/lib/Property/PropertyFiller/useStyles.d.ts +0 -12
  199. package/src/lib/Property/PropertyValidator/NodeValidator.d.ts +0 -6
  200. package/src/lib/Property/PropertyValidator/NodesList.d.ts +0 -6
  201. package/src/lib/Property/PropertyValidator/NumericTypeValidator.d.ts +0 -8
  202. package/src/lib/Property/PropertyValidator/PropertyValidator.d.ts +0 -6
  203. package/src/lib/Property/PropertyValidator/PropertyValidatorContext.d.ts +0 -3
  204. package/src/lib/Property/PropertyValidator/StringTypeValidator.d.ts +0 -8
  205. package/src/lib/Property/PropertyValidator/ValidationNodeSelector.d.ts +0 -7
  206. package/src/lib/Property/PropertyValidator/index.d.ts +0 -1
  207. package/src/lib/Property/PropertyValueField/BooleanValueField.d.ts +0 -7
  208. package/src/lib/Property/PropertyValueField/DateTimeValueField.d.ts +0 -9
  209. package/src/lib/Property/PropertyValueField/DateValueField.d.ts +0 -9
  210. package/src/lib/Property/PropertyValueField/JsonValueField.d.ts +0 -10
  211. package/src/lib/Property/PropertyValueField/PropertyValueField.d.ts +0 -9
  212. package/src/lib/Property/PropertyValueField/StringValueField.d.ts +0 -9
  213. package/src/lib/Property/PropertyValueField/TimeValueField.d.ts +0 -9
  214. package/src/lib/Property/PropertyWidget/PropertyWidget.d.ts +0 -13
  215. package/src/lib/Property/UpsertProperty/CreatePropertiesList.d.ts +0 -13
  216. package/src/lib/Property/UpsertProperty/CreatePropertyFormFields.d.ts +0 -10
  217. package/src/lib/Property/UpsertProperty/CustomPropertyField.d.ts +0 -7
  218. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/BigDecimalPropertyFields.d.ts +0 -6
  219. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/DateAdditionalFields.d.ts +0 -7
  220. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/EntityAdditionalFields.d.ts +0 -8
  221. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/EntityReferencePropertyFields.d.ts +0 -6
  222. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/PropertyAdditionalFields.d.ts +0 -10
  223. package/src/lib/Property/UpsertProperty/PropertyAdditionalFields/StringPropertyFields.d.ts +0 -6
  224. package/src/lib/Property/UpsertProperty/useCustomFields.d.ts +0 -6
  225. package/src/lib/Property/ViewPropertiesList/ViewPropertiesList.d.ts +0 -8
  226. package/src/lib/Property/ViewProperty/EntityPropertiesShortView.d.ts +0 -7
  227. package/src/lib/Property/ViewProperty/EntityPropertiesView.d.ts +0 -8
  228. package/src/lib/Property/ViewProperty/PropertyDataTable.d.ts +0 -7
  229. package/src/lib/Property/ViewProperty/PropertyItem.d.ts +0 -9
  230. package/src/lib/Property/ViewProperty/ViewProperty.d.ts +0 -9
  231. package/src/lib/Sidebar/Sidebar.d.ts +0 -10
  232. package/src/lib/Sidebar/Sidebar.styled.d.ts +0 -117
  233. package/src/lib/Sidebar/SidebarContext.d.ts +0 -11
  234. package/src/lib/Sidebar/SidebarDrawer.d.ts +0 -9
  235. package/src/lib/Sidebar/SidebarLink/MenuIcon.d.ts +0 -7
  236. package/src/lib/Sidebar/SidebarLink/SidebarLink.d.ts +0 -7
  237. package/src/lib/Sidebar/SidebarLink/SidebarLinkItem.d.ts +0 -8
  238. package/src/lib/Sidebar/SidebarLink/SidebarNestedItem.d.ts +0 -10
  239. package/src/lib/Sidebar/index.d.ts +0 -2
  240. package/src/lib/Status/Status.d.ts +0 -8
  241. package/src/lib/Status/styles.d.ts +0 -12
  242. package/src/lib/StepperView/StepperView.d.ts +0 -11
  243. package/src/lib/Table/DataGrid/JsonTypeCell.d.ts +0 -7
  244. package/src/lib/Table/DataGrid/Table.d.ts +0 -49
  245. package/src/lib/Table/DataGrid/TableAction.d.ts +0 -13
  246. package/src/lib/Table/DataGrid/TableColumnMenu.d.ts +0 -3
  247. package/src/lib/Table/DataGrid/TablePagination.d.ts +0 -3
  248. package/src/lib/Table/DataGrid/index.d.ts +0 -2
  249. package/src/lib/Table/DataGrid/styles.d.ts +0 -12
  250. package/src/lib/Table/DataGrid/usePagination.d.ts +0 -5
  251. package/src/lib/Table/DataGrid/useTableQueryPagination.d.ts +0 -11
  252. package/src/lib/Table/DataGrid/useTableQuerySorting.d.ts +0 -6
  253. package/src/lib/Table/SimpleTable/SimpleTable.d.ts +0 -17
  254. package/src/lib/Table/SimpleTable/TableActionCell.d.ts +0 -10
  255. package/src/lib/Table/SimpleTable/index.d.ts +0 -2
  256. package/src/lib/Table/SimpleTable/useTablePagination.d.ts +0 -7
  257. package/src/lib/Table/SimpleTable/useTableSorting.d.ts +0 -6
  258. package/src/lib/Table/index.d.ts +0 -2
  259. package/src/lib/Tabs/RouteTabs.d.ts +0 -11
  260. package/src/lib/Tabs/TabPanel.d.ts +0 -25
  261. package/src/theme/baseTheme.d.ts +0 -2
  262. package/src/theme/index.d.ts +0 -1
  263. package/src/theme/inputThemeOptions.d.ts +0 -117
  264. package/src/theme/stepperThemeOptions.d.ts +0 -16
  265. package/src/theme/tableThemeOptions.d.ts +0 -47
  266. package/src/theme/typographyThemeOptions.d.ts +0 -29
  267. package/src/utils/common.d.ts +0 -7
  268. package/src/utils/dem.d.ts +0 -27
  269. package/src/utils/hooks.d.ts +0 -7
  270. package/src/utils/ui-utils.d.ts +0 -8
  271. package/src/utils/validators.d.ts +0 -5
@@ -0,0 +1,431 @@
1
+ import {
2
+ PropertyType,
3
+ EntityTypeProperty,
4
+ PropertiesArrayType,
5
+ PropertyUnion,
6
+ PropertiesObjectType,
7
+ PropertyFillType,
8
+ } from '../interfaces';
9
+ import { sortArrayOfObjects } from './common';
10
+ import { format } from 'date-fns';
11
+
12
+ export const isPropertyValueEmpty = (value: unknown): boolean => {
13
+ if (value || value === 0 || value === false) {
14
+ return false;
15
+ }
16
+ return true;
17
+ };
18
+
19
+ const formatPropertyValue = (
20
+ propertyType: PropertyType,
21
+ value: unknown,
22
+ params?: {
23
+ formatText?: string;
24
+ properties?: PropertiesArrayType;
25
+ }
26
+ ) => {
27
+ if ((value === null || value === undefined) && propertyType !== PropertyType.BOOLEAN) {
28
+ return null;
29
+ }
30
+ let parsedValue: unknown = value;
31
+
32
+ switch (propertyType) {
33
+ case PropertyType.BOOLEAN:
34
+ if (value) {
35
+ parsedValue = true;
36
+ } else {
37
+ parsedValue = false;
38
+ }
39
+ break;
40
+ case PropertyType.INTEGER:
41
+ case PropertyType.BIG_INTEGER:
42
+ case PropertyType.BIG_DECIMAL:
43
+ case PropertyType.FLOAT:
44
+ case PropertyType.LONG:
45
+ case PropertyType.DOUBLE:
46
+ parsedValue = Number(value);
47
+ break;
48
+ case PropertyType.DATE:
49
+ case PropertyType.DATE_TIME:
50
+ case PropertyType.TIME:
51
+ parsedValue = format(new Date(value.toString()), params.formatText);
52
+ break;
53
+ case PropertyType.JSON:
54
+ case PropertyType.ANY:
55
+ try {
56
+ if (typeof value !== 'string') {
57
+ parsedValue = JSON.stringify(value);
58
+ }
59
+ parsedValue = JSON.parse(parsedValue as string);
60
+ } catch (e) {
61
+ console.log(e);
62
+ parsedValue = null;
63
+ }
64
+ break;
65
+ case PropertyType.ENTITY:
66
+ parsedValue = formatDefinitionData(params.properties, value);
67
+ break;
68
+ default:
69
+ break;
70
+ }
71
+
72
+ return parsedValue;
73
+ };
74
+
75
+ export const formatDefinitionData = (properties: PropertiesArrayType<unknown>, data: unknown) => {
76
+ if (data) {
77
+ const formattedData = {};
78
+
79
+ properties.forEach((property) => {
80
+ const { key, propertyType } = property;
81
+ const value = data[key];
82
+
83
+ if (Array.isArray(value)) {
84
+ formattedData[key] = value.map((val) =>
85
+ formatPropertyValue(propertyType, val, {
86
+ formatText: property['format'],
87
+ properties: property['properties'],
88
+ })
89
+ );
90
+ } else {
91
+ formattedData[key] = formatPropertyValue(propertyType, value, {
92
+ formatText: property['format'],
93
+ properties: property['properties'],
94
+ });
95
+ }
96
+ });
97
+
98
+ return formattedData;
99
+ }
100
+ return null;
101
+ };
102
+
103
+ const getPropertyValue = (property: PropertyUnion & { [key: string]: unknown }, isGlobalParameter: boolean) => {
104
+ const valueObject = {};
105
+ let value;
106
+ let key = '';
107
+
108
+ if (isGlobalParameter) {
109
+ if (property.isMultiple) {
110
+ key = 'values';
111
+ value = property['value'];
112
+ } else {
113
+ key = 'value';
114
+ value = property['value'];
115
+ }
116
+ } else {
117
+ if (property.isMultiple) {
118
+ key = 'defaultValues';
119
+ value = property['defaultValue'];
120
+ } else {
121
+ key = 'defaultValue';
122
+ value = property['defaultValue'];
123
+ }
124
+ }
125
+
126
+ if (Array.isArray(value)) {
127
+ valueObject[key] = value.map((val) =>
128
+ formatPropertyValue(property.propertyType, val, {
129
+ formatText: property['format'] as string,
130
+ properties: property['properties'] as PropertiesArrayType,
131
+ })
132
+ );
133
+ } else {
134
+ valueObject[key] = formatPropertyValue(property.propertyType, value, {
135
+ formatText: property['format'] as string,
136
+ properties: property['properties'] as PropertiesArrayType,
137
+ });
138
+ }
139
+
140
+ return valueObject;
141
+ };
142
+
143
+ export const propertiesArrayToObject = (properties, isGlobalParameter?: boolean): PropertiesObjectType<any> => {
144
+ const propertiesObject = {};
145
+
146
+ properties.forEach((property) => {
147
+ const { key, name, isRequired, isMultiple, sortOrder, isEnabled, uiSettings, validationNode } = property;
148
+ const propertyType =
149
+ typeof property.propertyType === 'string' ? property.propertyType : property.propertyType.value;
150
+
151
+ const resultProperty = {
152
+ name,
153
+ propertyType,
154
+ isRequired,
155
+ isMultiple,
156
+ sortOrder,
157
+ isEnabled,
158
+ validationNode,
159
+ uiSettings,
160
+ ...getPropertyValue({ ...property, propertyType }, isGlobalParameter),
161
+ };
162
+
163
+ if ('isViewableInList' in property) {
164
+ resultProperty['isViewableInList'] = property.isViewableInList;
165
+ }
166
+
167
+ if (uiSettings) {
168
+ try {
169
+ resultProperty.uiSettings = JSON.parse(uiSettings);
170
+ } catch (e) {
171
+ console.log(e);
172
+ }
173
+ } else {
174
+ resultProperty.uiSettings = null;
175
+ }
176
+
177
+ if (propertyType === PropertyType.BIG_DECIMAL) {
178
+ resultProperty['precisionScale'] = property.precisionScale;
179
+ resultProperty['roundingMode'] = property.roundingMode;
180
+ }
181
+
182
+ if (
183
+ propertyType === PropertyType.DATE ||
184
+ propertyType === PropertyType.TIME ||
185
+ propertyType === PropertyType.DATE_TIME
186
+ ) {
187
+ resultProperty['format'] = property.format;
188
+ }
189
+
190
+ if (propertyType === PropertyType.STRING) {
191
+ resultProperty['restrictedValues'] = property.restrictedValues;
192
+ }
193
+
194
+ if (propertyType === PropertyType.ENTITY_REFERENCE) {
195
+ resultProperty['definitionCode'] = property.definitionCode;
196
+ resultProperty['definitionVersion'] = property.definitionVersion;
197
+ resultProperty['labelPropertyCode'] = property.labelPropertyCode;
198
+ resultProperty['valuePropertyCode'] = property.valuePropertyCode;
199
+ }
200
+
201
+ if (propertyType === PropertyType.ENTITY) {
202
+ resultProperty['properties'] = propertiesArrayToObject(property.properties, isGlobalParameter);
203
+ }
204
+
205
+ propertiesObject[key] = resultProperty;
206
+ });
207
+
208
+ return propertiesObject;
209
+ };
210
+
211
+ export function propertiesObjectToArray(properties, fields?: { [key: string]: unknown }) {
212
+ return Object.keys(properties)
213
+ .map((key) => {
214
+ const propObj = { key, ...properties[key], ...(fields ? fields : {}) };
215
+ if (propObj['propertyType'] === PropertyType.ENTITY) {
216
+ propObj['properties'] = propertiesObjectToArray(propObj['properties'], fields);
217
+ }
218
+
219
+ if (propObj['propertyType'] === PropertyType.JSON) {
220
+ try {
221
+ if (propObj.defaultValue == null) {
222
+ propObj.defaultValue = '';
223
+ } else {
224
+ propObj.defaultValue = JSON.stringify(propObj.defaultValue, null, 2);
225
+ }
226
+ } catch (error) {
227
+ propObj.defaultValue = '';
228
+ }
229
+ }
230
+
231
+ if (propObj['uiSettings']) {
232
+ try {
233
+ propObj.uiSettings = JSON.stringify(propObj.uiSettings, null, 2);
234
+ } catch (error) {
235
+ propObj.uiSettings = '';
236
+ }
237
+ }
238
+
239
+ if (propObj['isMultiple']) {
240
+ if ('defaultValues' in propObj) {
241
+ propObj['defaultValue'] = propObj.defaultValues;
242
+ }
243
+ if ('values' in propObj) {
244
+ propObj['value'] = propObj.values;
245
+ }
246
+ }
247
+
248
+ return propObj;
249
+ })
250
+ .sort((a, b) => sortArrayOfObjects(a, b, 'sortOrder'));
251
+ }
252
+
253
+ export const getDemPropertyDateFormat = (defaultFormat: string, propertyFormat: string) => {
254
+ if (propertyFormat) {
255
+ try {
256
+ const correctFormat = propertyFormat.replace(/Z/g, 'XXX');
257
+ format(new Date(), correctFormat);
258
+ return correctFormat;
259
+ } catch (e) {
260
+ console.error('Incorrect format', e);
261
+ return defaultFormat;
262
+ }
263
+ }
264
+ return defaultFormat;
265
+ };
266
+
267
+ export const getEntityStarterValue = (property: EntityTypeProperty) => {
268
+ let properties: PropertiesArrayType = [];
269
+ if (Array.isArray(property.properties)) {
270
+ properties = property.properties;
271
+ } else {
272
+ properties = propertiesObjectToArray(property.properties);
273
+ }
274
+
275
+ return properties.reduce((value, property) => {
276
+ const result = JSON.parse(JSON.stringify(value));
277
+ if (property.propertyType === PropertyType.ENTITY) {
278
+ result[property.key] = getEntityStarterValue(property);
279
+ } else {
280
+ result[property.key] = property.propertyType;
281
+ }
282
+ return result;
283
+ }, {});
284
+ };
285
+
286
+ export const getMultiplePropertyFillOptions = ({
287
+ propertyType,
288
+ useExpression,
289
+ required,
290
+ }: {
291
+ propertyType: PropertyType;
292
+ required: boolean;
293
+ useExpression?: boolean;
294
+ }): { value: PropertyFillType; label: string; sortOrder: number }[] => {
295
+ let options: { value: PropertyFillType; label: string; sortOrder: number }[] = [
296
+ {
297
+ value: 'widget',
298
+ label: 'Fill array (widget)',
299
+ sortOrder: 1,
300
+ },
301
+ ];
302
+
303
+ if (!required) {
304
+ options.push({
305
+ value: 'null',
306
+ label: 'NULL',
307
+ sortOrder: 0,
308
+ });
309
+ }
310
+
311
+ if (useExpression) {
312
+ if (
313
+ propertyType === PropertyType.JSON ||
314
+ propertyType === PropertyType.ENTITY ||
315
+ propertyType === PropertyType.ANY
316
+ ) {
317
+ options.push({ value: 'expression', label: 'Expression (JSON editor)', sortOrder: 3 });
318
+ } else {
319
+ options.push({
320
+ value: 'expression',
321
+ label: 'Expression',
322
+ sortOrder: 3,
323
+ });
324
+ }
325
+ }
326
+
327
+ if (propertyType === PropertyType.JSON || propertyType === PropertyType.ANY || propertyType === PropertyType.ENTITY) {
328
+ options.push({
329
+ value: 'json_valid',
330
+ label: 'JSON editor',
331
+ sortOrder: 2,
332
+ });
333
+ }
334
+
335
+ options = options.sort((a, b) => sortArrayOfObjects(a, b, 'sortOrder'));
336
+ return options;
337
+ };
338
+
339
+ export const getSinglePropertyFillOptions = ({
340
+ propertyType,
341
+ useExpression,
342
+ required,
343
+ }: {
344
+ propertyType: PropertyType;
345
+ required: boolean;
346
+ useExpression?: boolean;
347
+ }): { value: PropertyFillType; label: string; sortOrder: number }[] => {
348
+ let options: { value: PropertyFillType; label: string; sortOrder: number }[] = [
349
+ {
350
+ value: 'widget',
351
+ label: 'Widget',
352
+ sortOrder: 1,
353
+ },
354
+ ];
355
+
356
+ if (!required) {
357
+ options.push({
358
+ value: 'null',
359
+ label: 'NULL',
360
+ sortOrder: 0,
361
+ });
362
+ }
363
+
364
+ if (useExpression) {
365
+ if (
366
+ propertyType === PropertyType.JSON ||
367
+ propertyType === PropertyType.ENTITY ||
368
+ propertyType === PropertyType.ANY
369
+ ) {
370
+ options.push({ value: 'expression', label: 'Expression (JSON editor)', sortOrder: 3 });
371
+ } else {
372
+ options.push({
373
+ value: 'expression',
374
+ label: 'Expression',
375
+ sortOrder: 3,
376
+ });
377
+ }
378
+ }
379
+
380
+ if (propertyType === PropertyType.JSON) {
381
+ options.push({
382
+ value: 'dem_builder',
383
+ label: 'DEM Builder',
384
+ sortOrder: 2,
385
+ });
386
+ }
387
+
388
+ // WIDGET LABEL SET
389
+ switch (propertyType) {
390
+ case PropertyType.STRING:
391
+ options[0].label = 'Text input';
392
+ break;
393
+ case PropertyType.INTEGER:
394
+ case PropertyType.BIG_INTEGER:
395
+ case PropertyType.BIG_DECIMAL:
396
+ case PropertyType.FLOAT:
397
+ case PropertyType.LONG:
398
+ case PropertyType.DOUBLE:
399
+ options[0].label = 'Number input';
400
+ break;
401
+ case PropertyType.BOOLEAN:
402
+ options[0].label = 'Switch';
403
+ break;
404
+ case PropertyType.ENTITY_REFERENCE:
405
+ options[0].label = 'Entity reference fields';
406
+ break;
407
+ case PropertyType.JSON:
408
+ options[0].label = 'JSON editor';
409
+ break;
410
+ case PropertyType.DATE:
411
+ options[0].label = 'Date picker';
412
+ options.push({ value: 'string', label: 'Text input', sortOrder: 2 });
413
+ break;
414
+ case PropertyType.DATE_TIME:
415
+ options[0].label = 'Date & Time picker';
416
+ options.push({ value: 'string', label: 'Text input', sortOrder: 2 });
417
+ break;
418
+ case PropertyType.TIME:
419
+ options[0].label = 'Time picker';
420
+ options.push({ value: 'string', label: 'Text input', sortOrder: 2 });
421
+ break;
422
+ case PropertyType.ANY:
423
+ options[0].label = 'Textarea';
424
+ break;
425
+ default:
426
+ break;
427
+ }
428
+
429
+ options = options.sort((a, b) => sortArrayOfObjects(a, b, 'sortOrder'));
430
+ return options;
431
+ };
@@ -0,0 +1,41 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+
3
+ export function useDebounce(func: (args?: any) => void, delay: number) {
4
+ const timer = useRef<any>();
5
+
6
+ useEffect(() => {
7
+ return () => {
8
+ if (!timer.current) return;
9
+ clearTimeout(timer.current);
10
+ };
11
+ }, []);
12
+
13
+ const debounceFunction = (...args) => {
14
+ clearTimeout(timer.current);
15
+ timer.current = setTimeout(() => {
16
+ func(...args);
17
+ }, delay);
18
+ };
19
+
20
+ return debounceFunction;
21
+ }
22
+
23
+
24
+ export const useToggle = () => {
25
+ const [open, setOpen] = useState(false);
26
+
27
+ const toggle = () => {
28
+ setOpen((prevState) => !prevState);
29
+ };
30
+
31
+ const onClose = () => {
32
+ setOpen(false);
33
+ };
34
+
35
+ const onOpen = () => {
36
+ setOpen(true);
37
+ };
38
+
39
+ return { open, toggle, onClose, onOpen };
40
+ };
41
+
@@ -1,5 +1,5 @@
1
- export * from './common';
2
- export * from './ui-utils';
3
- export * from './hooks';
4
- export * from './validators';
5
- export * from './dem';
1
+ export * from './common';
2
+ export * from './ui-utils';
3
+ export * from './hooks';
4
+ export * from './validators';
5
+ export * from './dem';
@@ -0,0 +1,132 @@
1
+ import Box from '@mui/material/Box';
2
+ import SvgIcon from '@mui/material/SvgIcon';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import { CopyButton, Status } from '../lib';
5
+ import { format } from 'date-fns';
6
+ import { StatusVariant } from '../interfaces';
7
+ import JsonTypeCell from '../lib/Table/DataGrid/JsonTypeCell';
8
+
9
+ export const formatTableRowValue = ({
10
+ value,
11
+ canCopy,
12
+ copyValue,
13
+ shortId,
14
+ fullText,
15
+ textParams: { displayAs = 'text', dateFormat, statusVariant },
16
+ }: {
17
+ value: any;
18
+ canCopy?: boolean;
19
+ copyValue?: string;
20
+ shortId?: boolean;
21
+ fullText?: boolean;
22
+ textParams?: {
23
+ displayAs?:
24
+ | 'text'
25
+ | 'boolean'
26
+ | 'date'
27
+ | 'status'
28
+ | 'json_text'
29
+ | 'json_code'
30
+ | 'array'
31
+ | 'number';
32
+ dateFormat?: string[];
33
+ statusVariant?: StatusVariant;
34
+ };
35
+ }) => {
36
+ switch (displayAs) {
37
+ case 'boolean':
38
+ return value ? (
39
+ <SvgIcon color="primary" fontSize="small">
40
+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
41
+ </SvgIcon>
42
+ ) : (
43
+ <SvgIcon fontSize="small">
44
+ <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8 0-1.85.63-3.55 1.69-4.9L16.9 18.31C15.55 19.37 13.85 20 12 20zm6.31-3.1L7.1 5.69C8.45 4.63 10.15 4 12 4c4.42 0 8 3.58 8 8 0 1.85-.63 3.55-1.69 4.9z" />
45
+ </SvgIcon>
46
+ );
47
+ case 'date':
48
+ return value ? (
49
+ dateFormat ? (
50
+ <Box>
51
+ {dateFormat.map((formatString) => (
52
+ <Box>{format(new Date(value as string), formatString)}</Box>
53
+ ))}
54
+ </Box>
55
+ ) : (
56
+ <Box>
57
+ <Box>{format(new Date(value as string), 'dd.MM.yyyy')}</Box>
58
+ <Box>{format(new Date(value as string), 'HH:mm:ss')}</Box>
59
+ </Box>
60
+ )
61
+ ) : (
62
+ ''
63
+ );
64
+ case 'status':
65
+ return (
66
+ <Status
67
+ text={value as string}
68
+ status={statusVariant ? statusVariant : 'default'}
69
+ />
70
+ );
71
+ case 'json_text':
72
+ return <JsonTypeCell value={value} textField />;
73
+ case 'json_code':
74
+ return <JsonTypeCell value={value} copyButton />;
75
+ case 'array':
76
+ return (
77
+ <Box>
78
+ {(value as string[]).map((val, index) => (
79
+ <Box key={index}>{val}</Box>
80
+ ))}
81
+ </Box>
82
+ );
83
+ case 'number':
84
+ return (
85
+ <Box display="flex" justifyContent="flex-end">
86
+ <Box>
87
+ {value.toLocaleString('ru-Ru', { minimumFractionDigits: 2 })}
88
+ </Box>
89
+ </Box>
90
+ );
91
+ case 'text':
92
+ default:
93
+ return value ? (
94
+ <Box display="flex" alignItems="center" width="100%">
95
+ {shortId ? (
96
+ <Tooltip title={value}>
97
+ <Box mr="auto">
98
+ {value
99
+ ? `${(value as string).slice(0, 6)}...${(
100
+ value as string
101
+ ).slice(-6)}`
102
+ : '...'}
103
+ </Box>
104
+ </Tooltip>
105
+ ) : fullText ? (
106
+ <Box sx={{ whiteSpace: 'normal' }} title={value}>
107
+ {typeof value === 'string' ? value : JSON.stringify(value)}
108
+ </Box>
109
+ ) : (
110
+ <Tooltip title={value}>
111
+ <Box className="MuiDataGrid-cellContent" title={value}>
112
+ {typeof value === 'string' ? value : JSON.stringify(value)}
113
+ </Box>
114
+ </Tooltip>
115
+ )}
116
+ {canCopy && (
117
+ <CopyButton
118
+ copyText={
119
+ copyValue
120
+ ? typeof copyValue === 'string'
121
+ ? copyValue
122
+ : JSON.stringify(copyValue)
123
+ : value
124
+ }
125
+ />
126
+ )}
127
+ </Box>
128
+ ) : (
129
+ ''
130
+ );
131
+ }
132
+ };
@@ -0,0 +1,14 @@
1
+ import { PropertyType } from '../interfaces';
2
+
3
+ export const digitsOnly = new RegExp('^[-+]?[0-9]+$');
4
+ export const floatsOnly = new RegExp(/^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$/);
5
+
6
+ export const isExpression = (value: unknown): boolean => {
7
+ return typeof value === 'string' ? value.includes('$(') : false;
8
+ };
9
+
10
+ export const isDateType = (propertyType: PropertyType) => {
11
+ return (
12
+ propertyType === PropertyType.DATE || propertyType === PropertyType.DATE_TIME || propertyType === PropertyType.TIME
13
+ );
14
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "jsx": "react-jsx",
5
+ "allowJs": true,
6
+ "esModuleInterop": true,
7
+ "allowSyntheticDefaultImports": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "noImplicitOverride": true,
10
+ "noPropertyAccessFromIndexSignature": true,
11
+ "noImplicitReturns": true,
12
+ "noFallthroughCasesInSwitch": true
13
+ },
14
+ "files": [],
15
+ "include": [],
16
+ "references": [
17
+ {
18
+ "path": "./tsconfig.lib.json"
19
+ },
20
+ {
21
+ "path": "./tsconfig.spec.json"
22
+ }
23
+ ],
24
+ "extends": "../../tsconfig.base.json"
25
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "types": ["node"]
6
+ },
7
+ "files": [
8
+ "../../node_modules/@nrwl/react/typings/cssmodule.d.ts",
9
+ "../../node_modules/@nrwl/react/typings/image.d.ts"
10
+ ],
11
+ "exclude": [
12
+ "jest.config.ts",
13
+ "src/**/*.spec.ts",
14
+ "src/**/*.test.ts",
15
+ "src/**/*.spec.tsx",
16
+ "src/**/*.test.tsx",
17
+ "src/**/*.spec.js",
18
+ "src/**/*.test.js",
19
+ "src/**/*.spec.jsx",
20
+ "src/**/*.test.jsx"
21
+ ],
22
+ "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts"]
23
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../dist/out-tsc",
5
+ "module": "commonjs",
6
+ "types": ["jest", "node"]
7
+ },
8
+ "include": [
9
+ "jest.config.ts",
10
+ "src/**/*.test.ts",
11
+ "src/**/*.spec.ts",
12
+ "src/**/*.test.tsx",
13
+ "src/**/*.spec.tsx",
14
+ "src/**/*.test.js",
15
+ "src/**/*.spec.js",
16
+ "src/**/*.test.jsx",
17
+ "src/**/*.spec.jsx",
18
+ "src/**/*.d.ts"
19
+ ]
20
+ }