dce-reactkit 3.3.5 → 3.4.0-beta.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.
- package/dist/cjs/index.js +37524 -380
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +10 -0
- package/dist/cjs/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +33 -0
- package/dist/cjs/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +8 -0
- package/dist/cjs/types/components/DBEntryManagerPanel/index.d.ts +25 -0
- package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
- package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
- package/dist/cjs/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
- package/dist/cjs/types/helpers/addDBEditorEndpoints.d.ts +40 -0
- package/dist/cjs/types/index.d.ts +6 -1
- package/dist/esm/index.js +37698 -575
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.d.ts +10 -0
- package/dist/esm/types/components/DBEntryManagerPanel/AddOrEditDBEntry/index.d.ts +33 -0
- package/dist/esm/types/components/DBEntryManagerPanel/helpers/generateEndpointPath.d.ts +8 -0
- package/dist/esm/types/components/DBEntryManagerPanel/index.d.ts +25 -0
- package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntry.d.ts +8 -0
- package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryField.d.ts +49 -0
- package/dist/esm/types/components/DBEntryManagerPanel/types/DBEntryFieldType.d.ts +12 -0
- package/dist/esm/types/helpers/addDBEditorEndpoints.d.ts +40 -0
- package/dist/esm/types/index.d.ts +6 -1
- package/dist/index.d.ts +166 -35
- package/package.json +8 -3
- package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/CreatableMultiselect.tsx +290 -0
- package/src/components/DBEntryManagerPanel/AddOrEditDBEntry/index.tsx +699 -0
- package/src/components/DBEntryManagerPanel/helpers/generateEndpointPath.ts +15 -0
- package/src/components/DBEntryManagerPanel/index.tsx +511 -0
- package/src/components/DBEntryManagerPanel/types/DBEntry.ts +7 -0
- package/src/components/DBEntryManagerPanel/types/DBEntryField.ts +94 -0
- package/src/components/DBEntryManagerPanel/types/DBEntryFieldType.ts +18 -0
- package/src/helpers/addDBEditorEndpoints.ts +121 -0
- package/src/helpers/getLocalTimeInfo.tsx +4 -1
- package/src/index.ts +11 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
|
|
3
|
+
// Import dce-reactkit
|
|
4
|
+
import { genRouteHandler, ParamType } from 'dce-reactkit';
|
|
5
|
+
import generateEndpointPath from '../components/DBEntryManagerPanel/helpers/generateEndpointPath';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Interface for a collection in the database
|
|
9
|
+
* @author Yuen Ler Chow
|
|
10
|
+
*/
|
|
11
|
+
interface Collection {
|
|
12
|
+
/**
|
|
13
|
+
* Find all items in the collection that match the filter query
|
|
14
|
+
* @param filterQuery
|
|
15
|
+
* @returns list of items that match the filter query
|
|
16
|
+
*/
|
|
17
|
+
find: (filterQuery: any) => Promise<any[]>,
|
|
18
|
+
/**
|
|
19
|
+
* Insert an item into the collection
|
|
20
|
+
* @param item the item to insert
|
|
21
|
+
*/
|
|
22
|
+
insert: (item: any) => Promise<void>,
|
|
23
|
+
/**
|
|
24
|
+
* Delete an item in the collection
|
|
25
|
+
* @param id the id of the item to delete
|
|
26
|
+
*/
|
|
27
|
+
delete: (filterQuery: { id: string }) => Promise<void>,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Add all routes for the DBEditor
|
|
32
|
+
* @author Yuen Ler Chow
|
|
33
|
+
* @param opts object containing all arguments
|
|
34
|
+
* @param opts.app express app to add routes too
|
|
35
|
+
* @param opts.collectionName the name of the collection
|
|
36
|
+
* @param opts.adminsOnly true if the endpoint is for admins only
|
|
37
|
+
*/
|
|
38
|
+
const addDBEditorEndpoints = (opts: {
|
|
39
|
+
app: express.Application,
|
|
40
|
+
collectionName: string,
|
|
41
|
+
adminsOnly: boolean,
|
|
42
|
+
collection: Collection
|
|
43
|
+
},
|
|
44
|
+
) => {
|
|
45
|
+
const {
|
|
46
|
+
app,
|
|
47
|
+
collectionName,
|
|
48
|
+
adminsOnly,
|
|
49
|
+
collection,
|
|
50
|
+
} = opts;
|
|
51
|
+
|
|
52
|
+
const endpointPath = generateEndpointPath(collectionName, adminsOnly);
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* List all items in the collection
|
|
56
|
+
* @author Yuen Ler Chow
|
|
57
|
+
* @returns {any[]} the list of items in the collection
|
|
58
|
+
*/
|
|
59
|
+
app.get(
|
|
60
|
+
endpointPath,
|
|
61
|
+
genRouteHandler({
|
|
62
|
+
paramTypes: {
|
|
63
|
+
filterQuery: ParamType.JSONOptional,
|
|
64
|
+
},
|
|
65
|
+
handler: async ({ params }) => {
|
|
66
|
+
const filterQuery = params.filterQuery ?? {};
|
|
67
|
+
const categories = await collection.find(filterQuery);
|
|
68
|
+
return categories;
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Create a new item in the collection
|
|
75
|
+
* @author Yuen Ler Chow
|
|
76
|
+
* @param {any} item the item to create
|
|
77
|
+
*/
|
|
78
|
+
app.post(
|
|
79
|
+
endpointPath,
|
|
80
|
+
genRouteHandler({
|
|
81
|
+
paramTypes: {
|
|
82
|
+
item: ParamType.JSON,
|
|
83
|
+
},
|
|
84
|
+
handler: async ({
|
|
85
|
+
params,
|
|
86
|
+
}) => {
|
|
87
|
+
// Destructure params
|
|
88
|
+
const {
|
|
89
|
+
item,
|
|
90
|
+
} = params;
|
|
91
|
+
|
|
92
|
+
await collection.insert(item);
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Remove an item from the collection by id
|
|
99
|
+
* @author Yuen Ler Chow
|
|
100
|
+
*/
|
|
101
|
+
app.delete(
|
|
102
|
+
`${endpointPath}/:id`,
|
|
103
|
+
genRouteHandler({
|
|
104
|
+
paramTypes: {
|
|
105
|
+
id: ParamType.String,
|
|
106
|
+
},
|
|
107
|
+
handler: async ({
|
|
108
|
+
params,
|
|
109
|
+
}) => {
|
|
110
|
+
// Destructure params
|
|
111
|
+
const {
|
|
112
|
+
id,
|
|
113
|
+
} = params;
|
|
114
|
+
|
|
115
|
+
await collection.delete({ id });
|
|
116
|
+
},
|
|
117
|
+
}),
|
|
118
|
+
);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export default addDBEditorEndpoints;
|
|
@@ -36,7 +36,10 @@ const getLocalTimeInfo = (dateOrTimestamp?: Date | number): {
|
|
|
36
36
|
const day = d.getDate();
|
|
37
37
|
const hour = d.getHours();
|
|
38
38
|
const isPM = hour >= 12;
|
|
39
|
-
|
|
39
|
+
let hour12 = hour % 12;
|
|
40
|
+
if (hour12 === 0) {
|
|
41
|
+
hour12 = 12;
|
|
42
|
+
}
|
|
40
43
|
const minute = d.getMinutes();
|
|
41
44
|
|
|
42
45
|
// Return
|
package/src/index.ts
CHANGED
|
@@ -17,7 +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
|
-
|
|
20
|
+
import DBEntryManagerPanel from './components/DBEntryManagerPanel';
|
|
21
21
|
// Import errors
|
|
22
22
|
import ErrorWithCode from './errors/ErrorWithCode';
|
|
23
23
|
|
|
@@ -64,6 +64,7 @@ import isMobileOrTablet from './helpers/isMobileOrTablet';
|
|
|
64
64
|
import extractProp from './helpers/extractProp';
|
|
65
65
|
import compareArraysByProp from './helpers/compareArraysByProp';
|
|
66
66
|
import getLocalTimeInfo from './helpers/getLocalTimeInfo';
|
|
67
|
+
import addDBEditorEndpoints from './helpers/addDBEditorEndpoints';
|
|
67
68
|
|
|
68
69
|
// Import types
|
|
69
70
|
import ModalButtonType from './types/ModalButtonType';
|
|
@@ -83,6 +84,10 @@ import IntelliTableColumn from './types/IntelliTableColumn';
|
|
|
83
84
|
|
|
84
85
|
// Component-specific-types
|
|
85
86
|
import PickableItem from './components/ItemPicker/types/PickableItem';
|
|
87
|
+
import DBEntry from './components/DBEntryManagerPanel/types/DBEntry';
|
|
88
|
+
import DBEntryField from './components/DBEntryManagerPanel/types/DBEntryField';
|
|
89
|
+
import DBEntryFieldType from './components/DBEntryManagerPanel/types/DBEntryFieldType';
|
|
90
|
+
|
|
86
91
|
|
|
87
92
|
// Export each item
|
|
88
93
|
export {
|
|
@@ -105,6 +110,7 @@ export {
|
|
|
105
110
|
LogReviewer,
|
|
106
111
|
IntelliTable,
|
|
107
112
|
CSVDownloadButton,
|
|
113
|
+
DBEntryManagerPanel,
|
|
108
114
|
// Global functions
|
|
109
115
|
alert,
|
|
110
116
|
confirm,
|
|
@@ -154,6 +160,7 @@ export {
|
|
|
154
160
|
handleError,
|
|
155
161
|
handleSuccess,
|
|
156
162
|
initLogCollection,
|
|
163
|
+
addDBEditorEndpoints,
|
|
157
164
|
// Types
|
|
158
165
|
ModalButtonType,
|
|
159
166
|
ModalSize,
|
|
@@ -170,6 +177,9 @@ export {
|
|
|
170
177
|
IntelliTableColumn,
|
|
171
178
|
// Component-specific-types
|
|
172
179
|
PickableItem,
|
|
180
|
+
DBEntry,
|
|
181
|
+
DBEntryField,
|
|
182
|
+
DBEntryFieldType,
|
|
173
183
|
// Server types
|
|
174
184
|
ParamType,
|
|
175
185
|
};
|