admin_lsac 2.0.20 → 2.0.21
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/README.md +1 -1
- package/admin_lsac.d.ts +1 -1
- package/dist/esm/src/admin_lsac.d.ts +1 -1
- package/dist/esm/src/components/AdminPage.js +16 -4
- package/dist/esm/src/components/GenericForm.js +22 -17
- package/dist/esm/src/schema.d.ts +1 -1
- package/dist/esm/src/testSchemas/event.js +4 -5
- package/package.json +2 -2
package/README.md
CHANGED
package/admin_lsac.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useEffect, useState, useRef } from 'react';
|
|
3
3
|
import { ChakraProvider } from '@chakra-ui/react';
|
|
4
4
|
import { Button, Modal, ModalHeader, ModalBody, useDisclosure, ModalOverlay, ModalContent, ModalCloseButton, Box, Stack, } from '@chakra-ui/react';
|
|
5
5
|
import { GenericForm } from './GenericForm';
|
|
@@ -17,8 +17,9 @@ export function pageToUrl(page) {
|
|
|
17
17
|
function Header({ pages, data, basePath }) {
|
|
18
18
|
return (_jsx(Box, { background: "blue.50", padding: 1, children: _jsxs(Stack, { margin: 3, direction: "row", justifyContent: "space-between", alignItems: "center", children: [_jsx(Stack, { margin: 4, gap: 10, direction: "row", alignItems: "center", wrap: "wrap", children: pages.map((p, index) => (_jsx(Box, { as: "a", href: `${basePath}/${pageToUrl(p)}`, children: p.name }, index))) }), _jsx(Stack, { direction: "row", children: _jsx(Button, { colorScheme: "red", onClick: () => {
|
|
19
19
|
const filename = prompt('Enter filename: (without file extension)');
|
|
20
|
-
if (filename)
|
|
20
|
+
if (filename) {
|
|
21
21
|
exportToCSV(data, filename);
|
|
22
|
+
}
|
|
22
23
|
}, children: "Export Data" }) })] }) }));
|
|
23
24
|
}
|
|
24
25
|
function exportToCSV(data, filename) {
|
|
@@ -67,7 +68,18 @@ export function AdminPage({ pages, selectedPage, basePath, apiURL = '', }) {
|
|
|
67
68
|
useEffect(() => {
|
|
68
69
|
setDisplayData(data.map((table_data) => selectedPage.tableFields.map((field) => field.access(table_data))));
|
|
69
70
|
}, [data]);
|
|
70
|
-
|
|
71
|
+
const headerRef = useRef(null);
|
|
72
|
+
const [tableHeight, setTableHeight] = useState('80vh');
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const updateTableHeight = () => {
|
|
75
|
+
if (headerRef.current) {
|
|
76
|
+
const headerHeight = headerRef.current.clientHeight;
|
|
77
|
+
setTableHeight(`calc(88vh - ${headerHeight}px)`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
updateTableHeight();
|
|
81
|
+
}, []);
|
|
82
|
+
return (_jsxs(ChakraProvider, { children: [_jsx(Box, { ref: headerRef, children: _jsx(Header, { pages: pages, data: [selectedPage.tableFields.map((field) => field.name), ...displayData], basePath: basePath }) }), _jsx(ThemeProvider, { theme: createTheme(), children: _jsx(MaterialReactTable, { columns: selectedPage.tableFields.map((field, index) => ({
|
|
71
83
|
accessorFn: (row) => {
|
|
72
84
|
if (typeof row[index] === 'boolean') {
|
|
73
85
|
row[index] = String(row[index]);
|
|
@@ -75,7 +87,7 @@ export function AdminPage({ pages, selectedPage, basePath, apiURL = '', }) {
|
|
|
75
87
|
return row[index];
|
|
76
88
|
},
|
|
77
89
|
header: field.name,
|
|
78
|
-
})), data: displayData, muiTableContainerProps: { sx: { height:
|
|
90
|
+
})), data: displayData, muiTableContainerProps: { sx: { height: tableHeight } }, enableColumnResizing: true, enableColumnPinning: true, enableGlobalFilterModes: true, enablePagination: false, paginationDisplayMode: "pages", enableRowVirtualization: true, rowVirtualizerOptions: { overscan: 20 }, renderTopToolbarCustomActions: () => (_jsx(ChakraProvider, { children: _jsx(Stack, { margin: 0, padding: 2, direction: "row", wrap: "wrap", children: selectedPage.actions.map((action, index) => (_jsx(Button, { colorScheme: "blue", onClick: () => {
|
|
79
91
|
setSelectedAction(action);
|
|
80
92
|
onOpen();
|
|
81
93
|
}, children: action.name }, index))) }) })), enableRowActions: true, renderRowActionMenuItems: (obj) => {
|
|
@@ -36,12 +36,7 @@ function generateSingleField(formfield, fieldName, key) {
|
|
|
36
36
|
formfield.type === 'number' ||
|
|
37
37
|
formfield.type === 'date' ||
|
|
38
38
|
formfield.type === 'datetime-local' ||
|
|
39
|
-
formfield.type === 'time' ? (_jsx(Input, { ...field, value: field.value ?? '', type: formfield.type === '
|
|
40
|
-
formfield.type === 'date' ||
|
|
41
|
-
formfield.type === 'datetime-local' ||
|
|
42
|
-
formfield.type === 'time'
|
|
43
|
-
? formfield.type
|
|
44
|
-
: 'text' })) : formfield.type === 'file' ? (_jsx(Input, { type: "file", name: fieldName, onChange: (event) => {
|
|
39
|
+
formfield.type === 'time' ? (_jsx(Input, { ...field, value: field.value ?? '', type: formfield.type !== 'string' ? formfield.type : 'text' })) : formfield.type === 'file' ? (_jsx(Input, { type: "file", name: fieldName, onChange: (event) => {
|
|
45
40
|
if (event.currentTarget.files != null) {
|
|
46
41
|
form.setFieldValue(fieldName, event.currentTarget.files[0]);
|
|
47
42
|
}
|
|
@@ -87,10 +82,12 @@ function getCustomInitialValues(fields) {
|
|
|
87
82
|
return obj;
|
|
88
83
|
}
|
|
89
84
|
fields.forEach((field) => {
|
|
90
|
-
if (field.type === 'object')
|
|
85
|
+
if (field.type === 'object') {
|
|
91
86
|
obj[field.name] = getCustomInitialValues(field.fields);
|
|
92
|
-
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
93
89
|
obj[field.name] = undefined;
|
|
90
|
+
}
|
|
94
91
|
});
|
|
95
92
|
return obj;
|
|
96
93
|
}
|
|
@@ -107,12 +104,15 @@ async function setOptions(fields) {
|
|
|
107
104
|
return;
|
|
108
105
|
}
|
|
109
106
|
const promises = fields.map(async (field) => {
|
|
110
|
-
if (field.type === 'dropdown')
|
|
107
|
+
if (field.type === 'dropdown') {
|
|
111
108
|
field.options = field.options || (field.getOptions && (await field.getOptions()));
|
|
112
|
-
|
|
109
|
+
}
|
|
110
|
+
else if (field.type === 'array') {
|
|
113
111
|
await setOptions([field.element]);
|
|
114
|
-
|
|
112
|
+
}
|
|
113
|
+
else if (field.type === 'object') {
|
|
115
114
|
await setOptions(field.fields);
|
|
115
|
+
}
|
|
116
116
|
});
|
|
117
117
|
await Promise.all(promises);
|
|
118
118
|
}
|
|
@@ -131,20 +131,25 @@ export function GenericForm({ action, onClose, rowId, rowObject }) {
|
|
|
131
131
|
};
|
|
132
132
|
return (_jsx(_Fragment, { children: _jsx(Formik, { enableReinitialize: true, initialValues: initialValues, validationSchema: Yup.object(validationSchema), onReset: handleFormReset, onSubmit: async (values) => {
|
|
133
133
|
try {
|
|
134
|
-
if (rowObject !== undefined)
|
|
134
|
+
if (rowObject !== undefined) {
|
|
135
135
|
await action.onSubmit(values, rowId, rowObject);
|
|
136
|
-
|
|
136
|
+
}
|
|
137
|
+
else if (rowId !== undefined) {
|
|
137
138
|
await action.onSubmit(values, rowId);
|
|
138
|
-
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
139
141
|
await action.onSubmit(values);
|
|
140
|
-
|
|
142
|
+
}
|
|
143
|
+
if (onClose) {
|
|
141
144
|
onClose();
|
|
145
|
+
}
|
|
142
146
|
Swal.fire('Action/RowAction executed successfully');
|
|
143
147
|
}
|
|
144
148
|
catch (e) {
|
|
145
|
-
if (onClose)
|
|
146
|
-
onClose();
|
|
147
149
|
const err = e.message;
|
|
150
|
+
if (onClose) {
|
|
151
|
+
onClose();
|
|
152
|
+
}
|
|
148
153
|
Swal.fire({
|
|
149
154
|
text: 'Error: ' + err,
|
|
150
155
|
});
|
package/dist/esm/src/schema.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export const event = {
|
|
|
9
9
|
name: 'Delete Event - Variant 1', // without form
|
|
10
10
|
onSubmit: async (eventId) => {
|
|
11
11
|
// onSubmit has only param, the row's ID
|
|
12
|
-
const res = await axios.delete(domain + '/
|
|
12
|
+
const res = await axios.delete(domain + '/events/' + eventId);
|
|
13
13
|
return res.data;
|
|
14
14
|
},
|
|
15
15
|
},
|
|
@@ -53,15 +53,14 @@ export const event = {
|
|
|
53
53
|
// onSubmit has two params
|
|
54
54
|
// the first param - formValues, while the second is the row's ID
|
|
55
55
|
console.log(formValues);
|
|
56
|
-
const res = await axios.delete(domain + '/
|
|
56
|
+
const res = await axios.delete(domain + '/events/' + eventId);
|
|
57
57
|
return res.data;
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
60
|
],
|
|
61
61
|
getRequest: async () => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return [];
|
|
62
|
+
const res = await axios.get(domain + '/events');
|
|
63
|
+
return res.data;
|
|
65
64
|
},
|
|
66
65
|
tableFields: [
|
|
67
66
|
{
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "admin_lsac",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.21",
|
|
5
5
|
"description": "Generic Admin Panel created for storing events' data",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"lint-staged": "lint-staged"
|
|
13
13
|
},
|
|
14
14
|
"lint-staged": {
|
|
15
|
-
"*.{js,ts,tsx,
|
|
15
|
+
"*.{js,ts,tsx,jsx}": [
|
|
16
16
|
"eslint --quiet --fix"
|
|
17
17
|
],
|
|
18
18
|
"*.{json,md,html,js,jsx,ts,tsx}": [
|