dce-reactkit 3.4.1 → 3.5.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.
Files changed (113) hide show
  1. package/.vscode/settings.json +1 -0
  2. package/dist/cjs/index.js +36477 -247
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/client/initClient.d.ts +1 -1
  5. package/dist/cjs/types/components/AppWrapper.d.ts +6 -6
  6. package/dist/cjs/types/components/ButtonInputGroup.d.ts +1 -1
  7. package/dist/cjs/types/components/CSVDownloadButton.d.ts +1 -1
  8. package/dist/cjs/types/components/CheckboxButton.d.ts +1 -1
  9. package/dist/cjs/types/components/CopiableBox.d.ts +1 -1
  10. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +16 -0
  11. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +35 -0
  12. package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +9 -0
  13. package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +36 -0
  14. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
  15. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
  16. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
  17. package/dist/cjs/types/components/Drawer.d.ts +1 -1
  18. package/dist/cjs/types/components/ErrorBox.d.ts +1 -1
  19. package/dist/cjs/types/components/IntelliTable.d.ts +1 -1
  20. package/dist/cjs/types/components/ItemPicker/NestableItemList.d.ts +1 -1
  21. package/dist/cjs/types/components/ItemPicker/index.d.ts +1 -1
  22. package/dist/cjs/types/components/ItemPicker/types/PickableItem.d.ts +1 -1
  23. package/dist/cjs/types/components/LogReviewer.d.ts +1 -1
  24. package/dist/cjs/types/components/Modal.d.ts +1 -1
  25. package/dist/cjs/types/components/PopFailureMark.d.ts +1 -1
  26. package/dist/cjs/types/components/PopPendingMark.d.ts +1 -1
  27. package/dist/cjs/types/components/PopSuccessMark.d.ts +1 -1
  28. package/dist/cjs/types/components/RadioButton.d.ts +1 -1
  29. package/dist/cjs/types/components/SimpleDateChooser.d.ts +1 -1
  30. package/dist/cjs/types/components/TabBox.d.ts +1 -1
  31. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +41 -0
  32. package/dist/cjs/types/helpers/compareArraysByProp.d.ts +3 -2
  33. package/dist/cjs/types/helpers/genRouteHandler.d.ts +7 -7
  34. package/dist/cjs/types/helpers/getHumanReadableDate.d.ts +1 -1
  35. package/dist/cjs/types/helpers/getLocalTimeInfo.d.ts +1 -1
  36. package/dist/cjs/types/helpers/getTimeInfoInET.d.ts +1 -1
  37. package/dist/cjs/types/helpers/parallelLimit.d.ts +1 -1
  38. package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +1 -1
  39. package/dist/cjs/types/index.d.ts +7 -2
  40. package/dist/cjs/types/server/initServer.d.ts +1 -1
  41. package/dist/cjs/types/types/IntelliTableColumn.d.ts +1 -1
  42. package/dist/cjs/types/types/Log/LogMainInfo.d.ts +1 -1
  43. package/dist/cjs/types/types/Log/LogSourceSpecificInfo.d.ts +1 -1
  44. package/dist/cjs/types/types/Log/LogTypeSpecificInfo.d.ts +1 -1
  45. package/dist/cjs/types/types/Log/index.d.ts +1 -1
  46. package/dist/cjs/types/types/LogFunction.d.ts +1 -1
  47. package/dist/cjs/types/types/LogMetadataContextMap.d.ts +1 -1
  48. package/dist/cjs/types/types/LogMetadataTagMap.d.ts +1 -1
  49. package/dist/cjs/types/types/LogMetadataTargetMap.d.ts +1 -1
  50. package/dist/cjs/types/types/LogMetadataType.d.ts +1 -1
  51. package/dist/esm/index.js +36692 -483
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/types/client/initClient.d.ts +1 -1
  54. package/dist/esm/types/components/AppWrapper.d.ts +6 -6
  55. package/dist/esm/types/components/ButtonInputGroup.d.ts +1 -1
  56. package/dist/esm/types/components/CSVDownloadButton.d.ts +1 -1
  57. package/dist/esm/types/components/CheckboxButton.d.ts +1 -1
  58. package/dist/esm/types/components/CopiableBox.d.ts +1 -1
  59. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +16 -0
  60. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +35 -0
  61. package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +9 -0
  62. package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +36 -0
  63. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
  64. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
  65. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
  66. package/dist/esm/types/components/Drawer.d.ts +1 -1
  67. package/dist/esm/types/components/ErrorBox.d.ts +1 -1
  68. package/dist/esm/types/components/IntelliTable.d.ts +1 -1
  69. package/dist/esm/types/components/ItemPicker/NestableItemList.d.ts +1 -1
  70. package/dist/esm/types/components/ItemPicker/index.d.ts +1 -1
  71. package/dist/esm/types/components/ItemPicker/types/PickableItem.d.ts +1 -1
  72. package/dist/esm/types/components/LogReviewer.d.ts +1 -1
  73. package/dist/esm/types/components/Modal.d.ts +1 -1
  74. package/dist/esm/types/components/PopFailureMark.d.ts +1 -1
  75. package/dist/esm/types/components/PopPendingMark.d.ts +1 -1
  76. package/dist/esm/types/components/PopSuccessMark.d.ts +1 -1
  77. package/dist/esm/types/components/RadioButton.d.ts +1 -1
  78. package/dist/esm/types/components/SimpleDateChooser.d.ts +1 -1
  79. package/dist/esm/types/components/TabBox.d.ts +1 -1
  80. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +41 -0
  81. package/dist/esm/types/helpers/compareArraysByProp.d.ts +3 -2
  82. package/dist/esm/types/helpers/genRouteHandler.d.ts +7 -7
  83. package/dist/esm/types/helpers/getHumanReadableDate.d.ts +1 -1
  84. package/dist/esm/types/helpers/getLocalTimeInfo.d.ts +1 -1
  85. package/dist/esm/types/helpers/getTimeInfoInET.d.ts +1 -1
  86. package/dist/esm/types/helpers/parallelLimit.d.ts +1 -1
  87. package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +1 -1
  88. package/dist/esm/types/index.d.ts +7 -2
  89. package/dist/esm/types/server/initServer.d.ts +1 -1
  90. package/dist/esm/types/types/IntelliTableColumn.d.ts +1 -1
  91. package/dist/esm/types/types/Log/LogMainInfo.d.ts +1 -1
  92. package/dist/esm/types/types/Log/LogSourceSpecificInfo.d.ts +1 -1
  93. package/dist/esm/types/types/Log/LogTypeSpecificInfo.d.ts +1 -1
  94. package/dist/esm/types/types/Log/index.d.ts +1 -1
  95. package/dist/esm/types/types/LogFunction.d.ts +1 -1
  96. package/dist/esm/types/types/LogMetadataContextMap.d.ts +1 -1
  97. package/dist/esm/types/types/LogMetadataTagMap.d.ts +1 -1
  98. package/dist/esm/types/types/LogMetadataTargetMap.d.ts +1 -1
  99. package/dist/esm/types/types/LogMetadataType.d.ts +1 -1
  100. package/dist/index.d.ts +229 -85
  101. package/package.json +7 -2
  102. package/src/client/initClient.tsx +23 -31
  103. package/src/components/AppWrapper.tsx +1 -1
  104. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.tsx +303 -0
  105. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/index.tsx +737 -0
  106. package/src/components/DBEntryManagerPanel/helpers/generateEndpointPath.ts +16 -0
  107. package/src/components/DBEntryManagerPanel/index.tsx +522 -0
  108. package/src/components/DBEntryManagerPanel/types/DBEntry.ts +7 -0
  109. package/src/components/DBEntryManagerPanel/types/DBEntryField.ts +94 -0
  110. package/src/components/DBEntryManagerPanel/types/DBEntryFieldType.ts +18 -0
  111. package/src/helpers/addDBEditorEndpoints.ts +128 -0
  112. package/src/helpers/compareArraysByProp.ts +41 -19
  113. package/src/index.ts +11 -1
@@ -0,0 +1,128 @@
1
+ // Import express
2
+ import express from 'express';
3
+
4
+ // Import shared helpers
5
+ import genRouteHandler from './genRouteHandler';
6
+ import generateEndpointPath from '../components/DBEntryManagerPanel/helpers/generateEndpointPath';
7
+
8
+ // Import shared types
9
+ import ParamType from '../types/ParamType';
10
+
11
+ /**
12
+ * Interface for a collection in the database
13
+ * @author Yuen Ler Chow
14
+ */
15
+ type DCEMangoCollection = {
16
+ /**
17
+ * Find all items in the collection that match the filter query
18
+ * @param filterQuery
19
+ * @returns list of items that match the filter query
20
+ */
21
+ find: (filterQuery: any) => Promise<any[]>,
22
+ /**
23
+ * Insert an item into the collection
24
+ * @param item the item to insert
25
+ */
26
+ insert: (item: any) => Promise<void>,
27
+ /**
28
+ * Delete an item in the collection
29
+ * @param id the id of the item to delete
30
+ */
31
+ delete: (filterQuery: { id: string }) => Promise<void>,
32
+ };
33
+
34
+ /**
35
+ * Add all routes for the DBEditor
36
+ * @author Yuen Ler Chow
37
+ * @param opts object containing all arguments
38
+ * @param opts.app express app to add routes too
39
+ * @param opts.collectionName the name of the collection
40
+ * @param opts.adminsOnly true if the endpoint is for admins only
41
+ * @param opts.collection dce-mango db collection
42
+ */
43
+ const addDBEditorEndpoints = (
44
+ opts: {
45
+ app: express.Application,
46
+ collectionName: string,
47
+ adminsOnly: boolean,
48
+ collection: DCEMangoCollection,
49
+ },
50
+ ) => {
51
+ const {
52
+ app,
53
+ collectionName,
54
+ adminsOnly,
55
+ collection,
56
+ } = opts;
57
+
58
+ // Generate the endpoint path
59
+ const endpointPath = generateEndpointPath(collectionName, adminsOnly);
60
+
61
+ /**
62
+ * List all items in the collection
63
+ * @author Yuen Ler Chow
64
+ * @returns {any[]} the list of items in the collection
65
+ */
66
+ app.get(
67
+ endpointPath,
68
+ genRouteHandler({
69
+ paramTypes: {
70
+ filterQuery: ParamType.JSONOptional,
71
+ },
72
+ handler: async ({ params }) => {
73
+ const filterQuery = params.filterQuery ?? {};
74
+ const categories = await collection.find(filterQuery);
75
+ return categories;
76
+ },
77
+ }),
78
+ );
79
+
80
+ /**
81
+ * Create a new item in the collection
82
+ * @author Yuen Ler Chow
83
+ * @param {any} item the item to create
84
+ */
85
+ app.post(
86
+ endpointPath,
87
+ genRouteHandler({
88
+ paramTypes: {
89
+ item: ParamType.JSON,
90
+ },
91
+ handler: async ({
92
+ params,
93
+ }) => {
94
+ // Destructure params
95
+ const {
96
+ item,
97
+ } = params;
98
+
99
+ await collection.insert(item);
100
+ },
101
+ }),
102
+ );
103
+
104
+ /**
105
+ * Remove an item from the collection by id
106
+ * @author Yuen Ler Chow
107
+ */
108
+ app.delete(
109
+ `${endpointPath}/:id`,
110
+ genRouteHandler({
111
+ paramTypes: {
112
+ id: ParamType.String,
113
+ },
114
+ handler: async ({
115
+ params,
116
+ }) => {
117
+ // Destructure params
118
+ const {
119
+ id,
120
+ } = params;
121
+
122
+ await collection.delete({ id });
123
+ },
124
+ }),
125
+ );
126
+ };
127
+
128
+ export default addDBEditorEndpoints;
@@ -7,31 +7,53 @@ import extractProp from './extractProp';
7
7
  * @author Gabe Abrams
8
8
  * @param a the first array
9
9
  * @param b the second array
10
- * @param prop the property to compare with
10
+ * @param prop the property to compare with, or an array of props to compare
11
+ * with (if array, all values associated with those props must match)
11
12
  * @returns true if the arrays contain the same objects as determined by
12
13
  * the values associated with each object's prop
13
14
  */
14
- const compareArraysByProp = (a: any[], b: any[], prop: string): boolean => {
15
- // Extract values for comparison
16
- const aVals = new Set(extractProp(a, prop));
17
- const bVals = new Set(extractProp(b, prop));
18
-
19
- // Compare sizes first
20
- if (aVals.size !== bVals.size) {
15
+ const compareArraysByProp = (
16
+ a: any[],
17
+ b: any[],
18
+ prop: string | string[],
19
+ ): boolean => {
20
+ // Immediately return if size of arrays is different
21
+ if (a.length !== b.length) {
21
22
  return false;
22
23
  }
23
24
 
24
- // Same number of items. Make sure every object in aVals appears in bVals
25
- // (if so, they should be equivalent since the sizes are the same)
26
- // > Create map of items in bVals
27
- const inBVals: { [k: string]: boolean } = {}; // item => true if in bVals
28
- Array.from(bVals.values()).forEach((item) => {
29
- inBVals[item] = true;
30
- });
31
- // > Loop through aVals and make sure every item is in bVals
32
- return Array.from(aVals.values()).every((item) => {
33
- return inBVals[item];
34
- });
25
+ // Get all props
26
+ const props = (Array.isArray(prop) ? prop : [prop]);
27
+
28
+ // Clone second array so we can work on it
29
+ const bCloned = [...b];
30
+
31
+ // Remove elements from b as we find them in a
32
+ for (let i = 0; i < a.length; i++) {
33
+ // Find matching element in b
34
+ const matchingIndex = bCloned.findIndex((bItem) => {
35
+ // Compare based on all props
36
+ return props.every((propToCompareBy) => {
37
+ const aVal = extractProp(a[i], propToCompareBy);
38
+ const bVal = extractProp(bItem, propToCompareBy);
39
+ return aVal === bVal;
40
+ });
41
+ });
42
+
43
+ // Check if no match
44
+ const noMatch = (matchingIndex < 0);
45
+
46
+ // If no match, there's no corresponding element in b
47
+ if (noMatch) {
48
+ return false;
49
+ }
50
+
51
+ // Remove the matching element
52
+ bCloned.splice(matchingIndex, 1);
53
+ }
54
+
55
+ // If we made it here, all elements in a have a corresponding element in b
56
+ return true;
35
57
  };
36
58
 
37
59
  export default compareArraysByProp;
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ import ItemPicker from './components/ItemPicker';
17
17
  import LogReviewer from './components/LogReviewer';
18
18
  import IntelliTable from './components/IntelliTable';
19
19
  import CSVDownloadButton from './components/CSVDownloadButton';
20
+ import DBEntryManagerPanel from './components/DBEntryManagerPanel';
20
21
 
21
22
  // Import errors
22
23
  import ErrorWithCode from './errors/ErrorWithCode';
@@ -63,11 +64,12 @@ import canReviewLogs from './helpers/canReviewLogs';
63
64
  import isMobileOrTablet from './helpers/isMobileOrTablet';
64
65
  import extractProp from './helpers/extractProp';
65
66
  import compareArraysByProp from './helpers/compareArraysByProp';
67
+ import getLocalTimeInfo from './helpers/getLocalTimeInfo';
68
+ import addDBEditorEndpoints from './helpers/addDBEditorEndpoints';
66
69
  import genCommaList from './helpers/genCommaList';
67
70
  import validateEmail from './helpers/validators/validateEmail';
68
71
  import validatePhoneNumber from './helpers/validators/validatePhoneNumber';
69
72
  import validateString from './helpers/validators/validateString';
70
- import getLocalTimeInfo from './helpers/getLocalTimeInfo';
71
73
 
72
74
  // Import types
73
75
  import ModalButtonType from './types/ModalButtonType';
@@ -87,6 +89,9 @@ import IntelliTableColumn from './types/IntelliTableColumn';
87
89
 
88
90
  // Component-specific-types
89
91
  import PickableItem from './components/ItemPicker/types/PickableItem';
92
+ import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
93
+ import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
94
+ import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
90
95
 
91
96
  // Export each item
92
97
  export {
@@ -109,6 +114,7 @@ export {
109
114
  LogReviewer,
110
115
  IntelliTable,
111
116
  CSVDownloadButton,
117
+ DBEntryManagerPanel,
112
118
  // Global functions
113
119
  alert,
114
120
  confirm,
@@ -162,6 +168,7 @@ export {
162
168
  handleError,
163
169
  handleSuccess,
164
170
  initLogCollection,
171
+ addDBEditorEndpoints,
165
172
  // Types
166
173
  ModalButtonType,
167
174
  ModalSize,
@@ -178,6 +185,9 @@ export {
178
185
  IntelliTableColumn,
179
186
  // Component-specific-types
180
187
  PickableItem,
188
+ DBEntry,
189
+ DBEntryField,
190
+ DBEntryFieldType,
181
191
  // Server types
182
192
  ParamType,
183
193
  };