dce-reactkit 3.4.0-beta.9 → 3.4.0

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 (128) hide show
  1. package/.eslintrc.js +0 -2
  2. package/dist/cjs/index.js +190 -36371
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/types/helpers/abbreviate.test.d.ts +5 -0
  5. package/dist/cjs/types/helpers/avg.test.d.ts +5 -0
  6. package/dist/cjs/types/helpers/canReviewLogs.d.ts +5 -0
  7. package/dist/cjs/types/helpers/canReviewLogs.test.d.ts +5 -0
  8. package/dist/cjs/types/helpers/ceilToNumDecimals.test.d.ts +5 -0
  9. package/dist/cjs/types/helpers/compareArraysByProp.test.d.ts +5 -0
  10. package/dist/cjs/types/helpers/extractProp.test.d.ts +5 -0
  11. package/dist/cjs/types/helpers/floorToNumDecimals.test.d.ts +5 -0
  12. package/dist/cjs/types/helpers/forceNumIntoBounds.test.d.ts +5 -0
  13. package/dist/cjs/types/helpers/genCSV.test.d.ts +5 -0
  14. package/dist/cjs/types/helpers/genCommaList.d.ts +12 -0
  15. package/dist/cjs/types/helpers/genCommaList.test.d.ts +1 -0
  16. package/dist/cjs/types/helpers/getHumanReadableDate.test.d.ts +5 -0
  17. package/dist/cjs/types/helpers/getLocalTimeInfo.test.d.ts +6 -0
  18. package/dist/cjs/types/helpers/getMonthName.test.d.ts +5 -0
  19. package/dist/cjs/types/helpers/getOrdinal.test.d.ts +5 -0
  20. package/dist/cjs/types/helpers/getPartOfDay.test.d.ts +5 -0
  21. package/dist/cjs/types/helpers/getTimeInfoInET.test.d.ts +5 -0
  22. package/dist/cjs/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
  23. package/dist/cjs/types/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
  24. package/dist/cjs/types/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
  25. package/dist/cjs/types/helpers/validators/validateEmail.d.ts +11 -0
  26. package/dist/cjs/types/helpers/validators/validateEmail.test.d.ts +1 -0
  27. package/dist/cjs/types/helpers/validators/validatePhoneNumber.d.ts +11 -0
  28. package/dist/cjs/types/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
  29. package/dist/cjs/types/helpers/validators/validateString.d.ts +22 -0
  30. package/dist/cjs/types/helpers/validators/validateString.test.d.ts +1 -0
  31. package/dist/cjs/types/index.d.ts +1 -6
  32. package/dist/esm/index.js +419 -36579
  33. package/dist/esm/index.js.map +1 -1
  34. package/dist/esm/types/helpers/abbreviate.test.d.ts +5 -0
  35. package/dist/esm/types/helpers/avg.test.d.ts +5 -0
  36. package/dist/esm/types/helpers/canReviewLogs.d.ts +5 -0
  37. package/dist/esm/types/helpers/canReviewLogs.test.d.ts +5 -0
  38. package/dist/esm/types/helpers/ceilToNumDecimals.test.d.ts +5 -0
  39. package/dist/esm/types/helpers/compareArraysByProp.test.d.ts +5 -0
  40. package/dist/esm/types/helpers/extractProp.test.d.ts +5 -0
  41. package/dist/esm/types/helpers/floorToNumDecimals.test.d.ts +5 -0
  42. package/dist/esm/types/helpers/forceNumIntoBounds.test.d.ts +5 -0
  43. package/dist/esm/types/helpers/genCSV.test.d.ts +5 -0
  44. package/dist/esm/types/helpers/genCommaList.d.ts +12 -0
  45. package/dist/esm/types/helpers/genCommaList.test.d.ts +1 -0
  46. package/dist/esm/types/helpers/getHumanReadableDate.test.d.ts +5 -0
  47. package/dist/esm/types/helpers/getLocalTimeInfo.test.d.ts +6 -0
  48. package/dist/esm/types/helpers/getMonthName.test.d.ts +5 -0
  49. package/dist/esm/types/helpers/getOrdinal.test.d.ts +5 -0
  50. package/dist/esm/types/helpers/getPartOfDay.test.d.ts +5 -0
  51. package/dist/esm/types/helpers/getTimeInfoInET.test.d.ts +5 -0
  52. package/dist/esm/types/helpers/validators/shared/constants/ERROR_MESSAGES.d.ts +10 -0
  53. package/dist/esm/types/helpers/validators/shared/helpers/validateRegex.d.ts +19 -0
  54. package/dist/esm/types/helpers/validators/shared/types/ValidationResult.d.ts +12 -0
  55. package/dist/esm/types/helpers/validators/validateEmail.d.ts +11 -0
  56. package/dist/esm/types/helpers/validators/validateEmail.test.d.ts +1 -0
  57. package/dist/esm/types/helpers/validators/validatePhoneNumber.d.ts +11 -0
  58. package/dist/esm/types/helpers/validators/validatePhoneNumber.test.d.ts +1 -0
  59. package/dist/esm/types/helpers/validators/validateString.d.ts +22 -0
  60. package/dist/esm/types/helpers/validators/validateString.test.d.ts +1 -0
  61. package/dist/esm/types/index.d.ts +1 -6
  62. package/dist/index.d.ts +35 -166
  63. package/package.json +13 -17
  64. package/src/client/initClient.tsx +20 -12
  65. package/src/components/AppWrapper.tsx +1 -1
  66. package/src/components/ItemPicker/index.test.tsx +10 -10
  67. package/src/helpers/abbreviate.test.ts +26 -0
  68. package/src/helpers/avg.test.ts +24 -0
  69. package/src/helpers/canReviewLogs.test.ts +67 -0
  70. package/src/helpers/canReviewLogs.ts +20 -0
  71. package/src/helpers/ceilToNumDecimals.test.ts +39 -0
  72. package/src/helpers/compareArraysByProp.test.ts +102 -0
  73. package/src/helpers/extractProp.test.ts +34 -0
  74. package/src/helpers/floorToNumDecimals.test.ts +39 -0
  75. package/src/helpers/forceNumIntoBounds.test.ts +34 -0
  76. package/src/helpers/genCSV.test.ts +61 -0
  77. package/src/helpers/genCSV.ts +5 -2
  78. package/src/helpers/genCommaList.test.ts +57 -0
  79. package/src/helpers/genCommaList.ts +21 -0
  80. package/src/helpers/getHumanReadableDate.test.ts +29 -0
  81. package/src/helpers/getLocalTimeInfo.test.ts +48 -0
  82. package/src/helpers/getMonthName.test.ts +79 -0
  83. package/src/helpers/getOrdinal.test.ts +84 -0
  84. package/src/helpers/{getOrdinal.tsx → getOrdinal.ts} +1 -0
  85. package/src/helpers/getPartOfDay.test.ts +56 -0
  86. package/src/helpers/getTimeInfoInET.test.ts +72 -0
  87. package/src/helpers/validators/shared/constants/ERROR_MESSAGES.ts +18 -0
  88. package/src/helpers/validators/shared/helpers/validateRegex.ts +47 -0
  89. package/src/helpers/validators/shared/types/ValidationResult.ts +20 -0
  90. package/src/helpers/validators/validateEmail.test.ts +110 -0
  91. package/src/helpers/validators/validateEmail.ts +47 -0
  92. package/src/helpers/validators/validatePhoneNumber.test.ts +94 -0
  93. package/src/helpers/validators/validatePhoneNumber.ts +49 -0
  94. package/src/helpers/validators/validateString.test.ts +175 -0
  95. package/src/helpers/validators/validateString.ts +171 -0
  96. package/src/index.ts +10 -12
  97. package/tsconfig.json +6 -2
  98. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +0 -10
  99. package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +0 -34
  100. package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +0 -9
  101. package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +0 -25
  102. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +0 -8
  103. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +0 -49
  104. package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +0 -12
  105. package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +0 -40
  106. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +0 -10
  107. package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +0 -34
  108. package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +0 -9
  109. package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +0 -25
  110. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +0 -8
  111. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +0 -49
  112. package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +0 -12
  113. package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +0 -40
  114. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.tsx +0 -286
  115. package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/index.tsx +0 -722
  116. package/src/components/DBEntryManagerPanel/helpers/generateEndpointPath.ts +0 -15
  117. package/src/components/DBEntryManagerPanel/index.tsx +0 -511
  118. package/src/components/DBEntryManagerPanel/types/DBEntry.ts +0 -7
  119. package/src/components/DBEntryManagerPanel/types/DBEntryField.ts +0 -94
  120. package/src/components/DBEntryManagerPanel/types/DBEntryFieldType.ts +0 -18
  121. package/src/helpers/addDBEditorEndpoints.ts +0 -124
  122. /package/src/helpers/{abbreviate.tsx → abbreviate.ts} +0 -0
  123. /package/src/helpers/{avg.tsx → avg.ts} +0 -0
  124. /package/src/helpers/{ceilToNumDecimals.tsx → ceilToNumDecimals.ts} +0 -0
  125. /package/src/helpers/{floorToNumDecimals.tsx → floorToNumDecimals.ts} +0 -0
  126. /package/src/helpers/{forceNumIntoBounds.tsx → forceNumIntoBounds.ts} +0 -0
  127. /package/src/helpers/{getLocalTimeInfo.tsx → getLocalTimeInfo.ts} +0 -0
  128. /package/src/helpers/{getTimeInfoInET.tsx → getTimeInfoInET.ts} +0 -0
@@ -1,15 +0,0 @@
1
- /**
2
- * Generates the endpoint path for the given collection name
3
- * @author Yuen Ler Chow
4
- * @param collectionName the name of the collection
5
- * @param [adminsOnly] true if the endpoint is for admins only
6
- * @returns the endpoint path
7
- */
8
- const generateEndpointPath = (collectionName: string, adminsOnly?: boolean) => {
9
- // Determine prefix based on whether the endpoint is for admins only
10
- const userPath = adminsOnly ? 'admin' : 'ttm';
11
-
12
- // Return the endpoint path
13
- return `/api/${userPath}/dce-reactkit/dbeditor/${collectionName}`;
14
- };
15
- export default generateEndpointPath;
@@ -1,511 +0,0 @@
1
- /**
2
- * DB Entry Manager Panel
3
- * @author Yuen Ler Chow
4
- */
5
-
6
- // Import React
7
- import React, { useReducer, useEffect } from 'react';
8
-
9
- // Import FontAwesome
10
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
11
- import { faPlus, faTrash, faCog } from '@fortawesome/free-solid-svg-icons';
12
-
13
- // Import shared components
14
- import TabBox from '../TabBox';
15
- import visitServerEndpoint from '../../helpers/visitServerEndpoint';
16
- import { showFatalError, confirm } from '../AppWrapper';
17
- import LoadingSpinner from '../LoadingSpinner';
18
-
19
- // Import types
20
- import DBEntry from './types/DBEntry';
21
- import DBEntryField from './types/DBEntryField';
22
-
23
- // Import other components
24
- import AddOrEditDBEntry from './AddOrEditDBEntry';
25
- import generateEndpointPath from './helpers/generateEndpointPath';
26
-
27
- /*------------------------------------------------------------------------*/
28
- /* -------------------------------- Types ------------------------------- */
29
- /*------------------------------------------------------------------------*/
30
-
31
- // Props definition
32
- type Props = {
33
- // List of db entry fields
34
- entryFields: DBEntryField[],
35
- // a prop that is unique to each item
36
- idPropName: string,
37
- // the prop that you want to show up as the title of each item
38
- titlePropName: string,
39
- // The prop that you want in parentheses after the title
40
- descriptionPropName: string,
41
- // the title of the tabBox
42
- itemListTitle: string,
43
- // the phrase you want when you say "add a new [itemName]"
44
- itemName: string,
45
- // Function to validate the db entry before sending to the server
46
- validateEntry?: (dbEntry: DBEntry) => Promise<void>,
47
- // Function to modify the db entry before sending to the server
48
- modifyEntry?: (dbEntry: DBEntry) => Promise<DBEntry>,
49
- // True if editing is disabled
50
- disableEdit?: boolean,
51
- // Name of the collection in the database
52
- collectionName: string,
53
- // True if only admins can access this page
54
- adminsOnly?: boolean,
55
- // the query to filter the db entries
56
- filterQuery?: { [k: string]: any },
57
- };
58
-
59
- /*------------------------------------------------------------------------*/
60
- /* -------------------------------- State ------------------------------- */
61
- /*------------------------------------------------------------------------*/
62
-
63
- /* -------- State Definition -------- */
64
-
65
- type State = {
66
- // List of db items
67
- dbEntries: DBEntry[],
68
- // True if adding a new db item
69
- adding: boolean,
70
- // Db item to edit
71
- dbEntryToEdit?: DBEntry,
72
- // True if loading
73
- loading: boolean,
74
- };
75
-
76
- /* ------------- Actions ------------ */
77
-
78
- // Types of actions
79
- enum ActionType {
80
- // Show adder
81
- ShowAdder = 'ShowAdder',
82
- // Show editor
83
- ShowEditor = 'ShowEditor',
84
- // Finish adding
85
- FinishAdd = 'FinishAdd',
86
- // Finish loading
87
- FinishLoading = 'FinishLoading',
88
- // Start deletion process
89
- StartDelete = 'StartDelete',
90
- // Finish deletion process
91
- FinishDelete = 'FinishDelete',
92
- }
93
-
94
- // Action definitions
95
- type Action = (
96
- | {
97
- // Action type
98
- type: ActionType.FinishLoading,
99
- // db entry list
100
- dbEntries: DBEntry[],
101
- }
102
- | {
103
- // Action type
104
- type: ActionType.ShowEditor,
105
- // db item to edit
106
- dbEntry: DBEntry,
107
- }
108
- | {
109
- // Action type
110
- type: (
111
- | ActionType.ShowAdder
112
- ),
113
- }
114
- | {
115
- // Action type
116
- type: ActionType.FinishAdd,
117
- // DB entry that was added
118
- dbEntry?: DBEntry,
119
- idPropName: string,
120
- }
121
- | {
122
- // Action type
123
- type: ActionType.StartDelete,
124
- }
125
- | {
126
- // Action type
127
- type: ActionType.FinishDelete,
128
- // db entry that was deleted
129
- dbEntry: DBEntry,
130
- // unique id prop name
131
- idPropName: string,
132
- }
133
- );
134
-
135
- /**
136
- * Reducer that executes actions
137
- * @author Yuen Ler Chow
138
- * @param state current state
139
- * @param action action to execute
140
- */
141
- const reducer = (state: State, action: Action): State => {
142
- switch (action.type) {
143
- case ActionType.FinishLoading: {
144
- return {
145
- ...state,
146
- loading: false,
147
- dbEntries: action.dbEntries,
148
- };
149
- }
150
- case ActionType.ShowAdder: {
151
- return {
152
- ...state,
153
- adding: true,
154
- dbEntryToEdit: undefined,
155
- };
156
- }
157
- case ActionType.ShowEditor: {
158
- return {
159
- ...state,
160
- adding: false,
161
- dbEntryToEdit: action.dbEntry,
162
- };
163
- }
164
- case ActionType.FinishAdd: {
165
- // Handle cancel
166
- const finishedEntry = action.dbEntry;
167
- if (!finishedEntry) {
168
- return {
169
- ...state,
170
- adding: false,
171
- dbEntryToEdit: undefined,
172
- };
173
- }
174
-
175
- // Create an updated list of DB entries
176
- let updatedDbEntries: DBEntry[];
177
- if (state.adding) {
178
- updatedDbEntries = [...state.dbEntries, finishedEntry];
179
- } else {
180
- updatedDbEntries = state.dbEntries.map((existingDbEntry) => {
181
- if (state.dbEntryToEdit && state.dbEntryToEdit[action.idPropName] === existingDbEntry[action.idPropName]) {
182
- // This is the entry being edited! Replace
183
- return finishedEntry;
184
- }
185
- // This is not the entry being edited
186
- return existingDbEntry;
187
- });
188
- }
189
-
190
- // Update the state
191
- return {
192
- ...state,
193
- adding: false,
194
- dbEntryToEdit: undefined,
195
- dbEntries: updatedDbEntries,
196
- };
197
- }
198
- case ActionType.StartDelete: {
199
- return {
200
- ...state,
201
- loading: true,
202
- };
203
- }
204
- case ActionType.FinishDelete: {
205
- return {
206
- ...state,
207
- loading: false,
208
- // Remove the deleted entry from the list
209
- dbEntries: state.dbEntries.filter((entry: DBEntry) => {
210
- return (
211
- entry[action.idPropName] !== action.dbEntry[action.idPropName]
212
- );
213
- }),
214
- };
215
- }
216
- default: {
217
- return state;
218
- }
219
- }
220
- };
221
-
222
- /*------------------------------------------------------------------------*/
223
- /* ------------------------------ Component ----------------------------- */
224
- /*------------------------------------------------------------------------*/
225
-
226
- const DBEntryManagerPanel: React.FC<Props> = (props) => {
227
- // Destructure all props
228
- const {
229
- entryFields,
230
- titlePropName,
231
- descriptionPropName,
232
- idPropName,
233
- itemListTitle,
234
- itemName,
235
- validateEntry,
236
- modifyEntry,
237
- disableEdit,
238
- collectionName,
239
- adminsOnly,
240
- filterQuery,
241
- } = props;
242
-
243
- /* -------------- State ------------- */
244
-
245
- // Initial state
246
- const initialState: State = {
247
- dbEntries: [],
248
- adding: false,
249
- loading: true,
250
- };
251
-
252
- // Initialize state
253
- const [state, dispatch] = useReducer(reducer, initialState);
254
-
255
- // Destructure common state
256
- const {
257
- adding,
258
- dbEntryToEdit,
259
- dbEntries,
260
- loading,
261
- } = state;
262
-
263
- /*------------------------------------------------------------------------*/
264
- /* ------------------------- Component Functions ------------------------ */
265
- /*------------------------------------------------------------------------*/
266
-
267
- // Generate the endpoint path
268
- const endpoint = generateEndpointPath(collectionName, adminsOnly);
269
-
270
- /**
271
- * Delete a database entry
272
- * @author Yuen Ler Chow
273
- * @param entry the database entry to delete
274
- */
275
- const deleteEntry = async (entry: DBEntry) => {
276
- // Confirm
277
- const confirmed = await confirm(
278
- 'Remove?',
279
- `Are you sure you want to remove this ${itemName}?`,
280
- {
281
- confirmButtonText: 'Remove Item',
282
- },
283
- );
284
-
285
- // Skip if cancelled
286
- if (!confirmed) {
287
- return;
288
- }
289
-
290
- // Remove the entry
291
- try {
292
- // Start loader
293
- dispatch({
294
- type: ActionType.StartDelete,
295
- });
296
-
297
- // Perform deletion
298
- await visitServerEndpoint({
299
- path: `${endpoint}/${entry[idPropName]}`,
300
- method: 'DELETE',
301
- });
302
-
303
- // Finish loader
304
- dispatch({
305
- type: ActionType.FinishDelete,
306
- dbEntry: entry,
307
- idPropName,
308
- });
309
- } catch (err) {
310
- return showFatalError(err);
311
- }
312
- };
313
-
314
- /*------------------------------------------------------------------------*/
315
- /* ------------------------- Lifecycle Functions ------------------------ */
316
- /*------------------------------------------------------------------------*/
317
-
318
- /**
319
- * Mount
320
- * @author Yuen Ler Chow
321
- */
322
- useEffect(
323
- () => {
324
- (async () => {
325
- // Load list of database entries
326
- try {
327
- const data = await visitServerEndpoint({
328
- path: endpoint,
329
- method: 'GET',
330
- params: {
331
- filterQuery: JSON.stringify(filterQuery),
332
- },
333
- });
334
-
335
- // Save loaded data
336
- dispatch({
337
- type: ActionType.FinishLoading,
338
- dbEntries: data,
339
- });
340
- } catch (err) {
341
- return showFatalError(err);
342
- }
343
- })();
344
- },
345
- [],
346
- );
347
-
348
- /*------------------------------------------------------------------------*/
349
- /* ------------------------------- Render ------------------------------- */
350
- /*------------------------------------------------------------------------*/
351
-
352
- /*----------------------------------------*/
353
- /* ---------------- Views --------------- */
354
- /*----------------------------------------*/
355
-
356
- let body: React.ReactNode;
357
-
358
- /* ------------- Loading ------------ */
359
-
360
- if (loading) {
361
- body = (
362
- <LoadingSpinner />
363
- );
364
- }
365
-
366
- /* ------------- List of entries ------------ */
367
-
368
- if (!loading && !adding && !dbEntryToEdit) {
369
- // Create body
370
- body = (
371
- <div>
372
- <TabBox
373
- title={itemListTitle}
374
- >
375
- {/* List of DB entries */}
376
- {dbEntries.map((entry) => {
377
- return (
378
- <div
379
- key={entry[idPropName]}
380
- className="alert alert-secondary p-2 mb-2 d-flex align-items-center justify-content-center mb-1"
381
- >
382
- {/* Title */}
383
- <div className="flex-grow-1">
384
- <h4 className="m-0">
385
- <span className="fw-bold">
386
- {entry[titlePropName]}
387
- </span>
388
- <span className="small">
389
- {' '}
390
- (
391
- {entry[descriptionPropName]}
392
- )
393
- </span>
394
- </h4>
395
- </div>
396
-
397
- {/* Buttons */}
398
- <div className="d-flex align-items-center">
399
- {/* Remove Button */}
400
- <button
401
- type="button"
402
- id={`DBEntryManagerPanel-remove-entry-with-id-${entry[idPropName]}`}
403
- className="btn btn-secondary me-1"
404
- aria-label={`remove database entry: ${entry[titlePropName]}`}
405
- onClick={() => {
406
- deleteEntry(entry);
407
- }}
408
- >
409
- <FontAwesomeIcon
410
- icon={faTrash}
411
- />
412
- <span className="d-none d-md-inline ms-1">
413
- Remove
414
- </span>
415
- </button>
416
-
417
- {/* Edit Button */}
418
- {!disableEdit && (
419
- <button
420
- type="button"
421
- id={`DBEntryManagerPanel-edit-with-id-${entry[idPropName]}`}
422
- className="btn btn-primary"
423
- aria-label={`edit db entry: ${entry[titlePropName]}`}
424
- onClick={() => {
425
- dispatch({
426
- type: ActionType.ShowEditor,
427
- dbEntry: entry,
428
- });
429
- }}
430
- >
431
- <FontAwesomeIcon
432
- icon={faCog}
433
- />
434
- <span className="d-none d-md-inline ms-1">
435
- Edit
436
- </span>
437
- </button>
438
- )}
439
- </div>
440
- </div>
441
- );
442
- })}
443
-
444
- {/* Add DB entry Button */}
445
- <div className="d-grid">
446
- <button
447
- type="button"
448
- id="DBEntryManagerPanel-add-entry"
449
- className="btn btn-lg btn-primary"
450
- aria-label={`add a new ${itemName} entry to the list of entries`}
451
- onClick={() => {
452
- dispatch({
453
- type: ActionType.ShowAdder,
454
- });
455
- }}
456
- >
457
- <FontAwesomeIcon
458
- icon={faPlus}
459
- className="me-2"
460
- />
461
- Add
462
- {' '}
463
- {itemName}
464
- </button>
465
- </div>
466
- </TabBox>
467
- </div>
468
- );
469
- }
470
-
471
- /* --------- Create or edit entry -------- */
472
-
473
- if (!loading && (adding || dbEntryToEdit)) {
474
- body = (
475
- <AddOrEditDBEntry
476
- saveEndpointPath={endpoint}
477
- validateEntry={validateEntry}
478
- modifyEntry={modifyEntry}
479
- entryFields={entryFields}
480
- dbEntryToEdit={dbEntryToEdit}
481
- idPropName={idPropName}
482
- entries={dbEntries}
483
- itemName={itemName}
484
- onFinished={(entry?: DBEntry) => {
485
- dispatch({
486
- type: ActionType.FinishAdd,
487
- dbEntry: entry,
488
- idPropName,
489
- });
490
- }}
491
- />
492
- );
493
- }
494
-
495
- /*----------------------------------------*/
496
- /* --------------- Main UI -------------- */
497
- /*----------------------------------------*/
498
-
499
- return (
500
- <div>
501
- {body}
502
- </div>
503
- );
504
- };
505
-
506
- /*------------------------------------------------------------------------*/
507
- /* ------------------------------- Wrap Up ------------------------------ */
508
- /*------------------------------------------------------------------------*/
509
-
510
- // Export component
511
- export default DBEntryManagerPanel;
@@ -1,7 +0,0 @@
1
- /**
2
- * Generic type for an object
3
- * @author Yuen Ler Chow
4
- */
5
- type DBEntry = { [k: string]: any };
6
-
7
- export default DBEntry;
@@ -1,94 +0,0 @@
1
- import DBEntryFieldType from './DBEntryFieldType';
2
-
3
- /**
4
- * A database entry input field
5
- * @author Yuen Ler Chow
6
- */
7
- type DBEntryField = (
8
- {
9
- // The label of the field
10
- label: string,
11
- // The key/prop this corresponds to in the DBEntry
12
- objectKey: string,
13
- // The placeholder text
14
- placeholder: string,
15
- // If true, only allow the user to edit when creating (not when editing)
16
- lockAfterCreation?: boolean,
17
- // If true, the field is required
18
- required?: boolean,
19
- } & (
20
- // A string input field
21
- | {
22
- // The type of the field
23
- type: DBEntryFieldType.String,
24
- // The required minimum number of characters
25
- minNumChars?: number,
26
- // The required maximum number of characters
27
- maxNumChars?: number,
28
- // The default value for the field
29
- defaultValue?: string,
30
- // If defined, the choices the user can choose from
31
- choices?: {
32
- // The title of the choice (human-readable)
33
- title: string,
34
- // The value of the choice (what is stored in the DB)
35
- value: string,
36
- }[],
37
- }
38
- // A number input field
39
- | {
40
- // The type of the field
41
- type: DBEntryFieldType.Number,
42
- // The required minimum number
43
- minNumber?: number,
44
- // The required maximum number
45
- maxNumber?: number,
46
- // The default value for the field
47
- defaultValue?: number,
48
- }
49
- // Checkbox input field
50
- | {
51
- // The type of the field
52
- type: DBEntryFieldType.StringArray,
53
- // The required minimum number of elements
54
- minNumElements?: number,
55
- // The required maximum number of elements
56
- maxNumElements?: number,
57
- // The default value for the field
58
- defaultValue?: string[],
59
- // If defined, the choices the user can choose from
60
- choices?: {
61
- // The title of the choice (human-readable)
62
- title: string,
63
- // The value of the choice (what is stored in the DB)
64
- value: string,
65
- }[],
66
- }
67
- // A number list input field
68
- | {
69
- // The type of the field
70
- type: DBEntryFieldType.NumberArray,
71
- // The required minimum number of elements
72
- minNumElements?: number,
73
- // The required maximum number of elements
74
- maxNumElements?: number,
75
- // The required minimum number
76
- minNumber?: number,
77
- // The required maximum number
78
- maxNumber?: number,
79
- // The default value for the field
80
- defaultValue?: number[],
81
- }
82
- // Object input field
83
- | {
84
- // The type of the field
85
- type: DBEntryFieldType.Object,
86
- // The required minimum number of elements
87
- defaultValue?: { [k: string]: any },
88
- // The required minimum number of elements
89
- subfields: DBEntryField[],
90
- }
91
- )
92
- );
93
-
94
- export default DBEntryField;
@@ -1,18 +0,0 @@
1
- /**
2
- * Options for field types
3
- * @author Yuen Ler Chow
4
- */
5
- enum DBEntryFieldType {
6
- // A string input field
7
- String = 'String',
8
- // A number input field
9
- Number = 'Number',
10
- // input field with subfields that are also DBEntryFields
11
- Object = 'Object',
12
- // list of strings input field
13
- StringArray = 'StringArray',
14
- // list of numbers input field
15
- NumberArray = 'NumberArray',
16
- }
17
-
18
- export default DBEntryFieldType;