admin_lsac 1.2.7 → 1.2.9
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/App.js +3 -3
- package/dist/cjs/App.js +3 -3
- package/dist/cjs/components/GenericForm.js +40 -8
- package/dist/cjs/components/Page.js +23 -8
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/pages/event.js +25 -1
- package/dist/cjs/utils/websockets.js +22 -0
- package/dist/components/GenericForm.js +40 -8
- package/dist/components/Page.js +23 -8
- package/dist/esm/App.js +3 -3
- package/dist/esm/components/GenericForm.js +40 -8
- package/dist/esm/components/Page.js +23 -8
- package/dist/esm/index.js +3 -3
- package/dist/esm/pages/event.js +25 -1
- package/dist/esm/utils/websockets.js +15 -0
- package/dist/index.js +2 -2
- package/dist/pages/event.js +25 -1
- package/dist/utils/websockets.js +22 -0
- package/package.json +2 -1
- package/src/App.tsx +50 -110
- package/src/components/GenericForm.tsx +308 -281
- package/src/components/Page.tsx +243 -223
- package/src/index.tsx +20 -20
- package/src/pages/event.ts +93 -69
- package/src/pages/page.ts +336 -336
- package/src/schema/schema.config.ts +8 -8
- package/src/schema/schema.ts +63 -64
- package/src/utils/websockets.tsx +17 -0
package/src/components/Page.tsx
CHANGED
|
@@ -1,223 +1,243 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
2
|
-
import { ChakraProvider } from "@chakra-ui/react";
|
|
3
|
-
import { PageSchema, Action } from "../schema/schema";
|
|
4
|
-
import {
|
|
5
|
-
Button,
|
|
6
|
-
Modal,
|
|
7
|
-
ModalHeader,
|
|
8
|
-
ModalBody,
|
|
9
|
-
useDisclosure,
|
|
10
|
-
ModalOverlay,
|
|
11
|
-
ModalContent,
|
|
12
|
-
ModalCloseButton,
|
|
13
|
-
Box,
|
|
14
|
-
Stack,
|
|
15
|
-
} from "@chakra-ui/react";
|
|
16
|
-
import { GenericForm } from "./GenericForm";
|
|
17
|
-
import { ThemeProvider } from "@emotion/react";
|
|
18
|
-
import { createTheme } from "@mui/material/styles";
|
|
19
|
-
import { MaterialReactTable } from "material-react-table";
|
|
20
|
-
import { mkConfig, generateCsv, download } from "export-to-csv";
|
|
21
|
-
import Swal from "sweetalert2";
|
|
22
|
-
import MenuItem from "@mui/material/MenuItem";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
)
|
|
127
|
-
);
|
|
128
|
-
}, [
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
</
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { ChakraProvider } from "@chakra-ui/react";
|
|
3
|
+
import { PageSchema, Action } from "../schema/schema";
|
|
4
|
+
import {
|
|
5
|
+
Button,
|
|
6
|
+
Modal,
|
|
7
|
+
ModalHeader,
|
|
8
|
+
ModalBody,
|
|
9
|
+
useDisclosure,
|
|
10
|
+
ModalOverlay,
|
|
11
|
+
ModalContent,
|
|
12
|
+
ModalCloseButton,
|
|
13
|
+
Box,
|
|
14
|
+
Stack,
|
|
15
|
+
} from "@chakra-ui/react";
|
|
16
|
+
import { GenericForm } from "./GenericForm";
|
|
17
|
+
import { ThemeProvider } from "@emotion/react";
|
|
18
|
+
import { createTheme } from "@mui/material/styles";
|
|
19
|
+
import { MaterialReactTable } from "material-react-table";
|
|
20
|
+
import { mkConfig, generateCsv, download } from "export-to-csv";
|
|
21
|
+
import Swal from "sweetalert2";
|
|
22
|
+
import MenuItem from "@mui/material/MenuItem";
|
|
23
|
+
import { io } from "socket.io-client";
|
|
24
|
+
import { newSocket } from "../utils/websockets";
|
|
25
|
+
|
|
26
|
+
export function pageToUrl(page: PageSchema): string {
|
|
27
|
+
return `${page.name.toLowerCase().replace(" ", "_")}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function Header({
|
|
31
|
+
pages,
|
|
32
|
+
data,
|
|
33
|
+
basePath,
|
|
34
|
+
}: {
|
|
35
|
+
pages: PageSchema[];
|
|
36
|
+
data: any[];
|
|
37
|
+
basePath: string;
|
|
38
|
+
}) {
|
|
39
|
+
return (
|
|
40
|
+
<Box background="blue.50" padding={1}>
|
|
41
|
+
<Stack
|
|
42
|
+
margin={3}
|
|
43
|
+
direction="row"
|
|
44
|
+
justifyContent="space-between"
|
|
45
|
+
alignItems="center"
|
|
46
|
+
>
|
|
47
|
+
<Stack margin={4} gap={10} direction="row" alignItems="center">
|
|
48
|
+
{pages.map((p) => (
|
|
49
|
+
<Box as="a" href={`${basePath}/${pageToUrl(p)}`}>
|
|
50
|
+
{p.name}
|
|
51
|
+
</Box>
|
|
52
|
+
))}
|
|
53
|
+
</Stack>
|
|
54
|
+
<Stack direction="row">
|
|
55
|
+
<Button
|
|
56
|
+
colorScheme="red"
|
|
57
|
+
onClick={() => {
|
|
58
|
+
const filename = prompt("Enter filename:");
|
|
59
|
+
if (filename) exportToCSV(data, filename);
|
|
60
|
+
}}
|
|
61
|
+
>
|
|
62
|
+
Export Data
|
|
63
|
+
</Button>
|
|
64
|
+
</Stack>
|
|
65
|
+
</Stack>
|
|
66
|
+
</Box>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function exportToCSV(data: any[], filename: string) {
|
|
71
|
+
const formatImageData = (obj: any) => {
|
|
72
|
+
const formattedObj: any = {};
|
|
73
|
+
for (const key in obj) {
|
|
74
|
+
if (typeof obj[key] !== "object") {
|
|
75
|
+
formattedObj[key] = obj[key];
|
|
76
|
+
} else if (typeof obj[key] === "object" && obj[key] != null) {
|
|
77
|
+
Object.keys(obj[key]).forEach((k: any) => {
|
|
78
|
+
formattedObj[`${key}.${k}`] = obj[key][k];
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return formattedObj;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const formattedData = data.map(formatImageData);
|
|
86
|
+
|
|
87
|
+
const csvConfig = mkConfig({
|
|
88
|
+
useKeysAsHeaders: true,
|
|
89
|
+
filename: filename,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (formattedData.length > 0) {
|
|
93
|
+
const csv = generateCsv(csvConfig)(formattedData);
|
|
94
|
+
download(csvConfig)(csv);
|
|
95
|
+
} else {
|
|
96
|
+
Swal.fire({
|
|
97
|
+
title: "Error while exporting CSV!",
|
|
98
|
+
text: "There is no data to export.",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function AdminPage({
|
|
104
|
+
pages,
|
|
105
|
+
selectedPage,
|
|
106
|
+
basePath,
|
|
107
|
+
apiURL=''
|
|
108
|
+
}: {
|
|
109
|
+
pages: PageSchema[];
|
|
110
|
+
selectedPage: PageSchema;
|
|
111
|
+
basePath: string;
|
|
112
|
+
apiURL?: string;
|
|
113
|
+
}) {
|
|
114
|
+
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
115
|
+
const [selectedAction, setSelectedAction] = useState({} as Action);
|
|
116
|
+
const [data, setData] = useState<any[]>([]);
|
|
117
|
+
const [displayData, setDisplayData] = useState<any[][]>([]);
|
|
118
|
+
const [rowId, setRowId] = useState<number>();
|
|
119
|
+
const [refetch, setRefetch] = useState<boolean>(false);
|
|
120
|
+
const [socket, setSocket] = useState(io);
|
|
121
|
+
newSocket(setSocket, apiURL);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
selectedPage.getRequest().then((resArray) => {
|
|
125
|
+
setData(resArray);
|
|
126
|
+
setRefetch(false);
|
|
127
|
+
});
|
|
128
|
+
}, [refetch]); // Do not remove 'refetch' from here !!!
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
socket.on("updateData", (message) => {
|
|
132
|
+
console.log("Message emitted from socket: " + message);
|
|
133
|
+
setRefetch(true);
|
|
134
|
+
const rowActionsMenu = document.querySelector(
|
|
135
|
+
".MuiPaper-root.MuiPopover-paper.MuiMenu-paper"
|
|
136
|
+
);
|
|
137
|
+
if (rowActionsMenu) {
|
|
138
|
+
rowActionsMenu.remove();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}, [socket, selectedPage]);
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
setDisplayData(
|
|
145
|
+
data.map((table_data) =>
|
|
146
|
+
selectedPage.tableFields.map((field) => field.access(table_data))
|
|
147
|
+
)
|
|
148
|
+
);
|
|
149
|
+
}, [data]);
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<>
|
|
153
|
+
<Header pages={pages} data={data} basePath={basePath} />
|
|
154
|
+
|
|
155
|
+
<ThemeProvider theme={createTheme()}>
|
|
156
|
+
<MaterialReactTable
|
|
157
|
+
columns={selectedPage.tableFields.map((field, index) => ({
|
|
158
|
+
accessorFn: (row: any) => row[index],
|
|
159
|
+
header: field.name,
|
|
160
|
+
}))}
|
|
161
|
+
data={displayData}
|
|
162
|
+
muiTableContainerProps={{ sx: { maxHeight: "70vh" } }}
|
|
163
|
+
enableColumnResizing
|
|
164
|
+
enableColumnPinning
|
|
165
|
+
enableGlobalFilterModes
|
|
166
|
+
enablePagination={true}
|
|
167
|
+
paginationDisplayMode="pages"
|
|
168
|
+
enableRowVirtualization
|
|
169
|
+
rowVirtualizerOptions={{ overscan: 20 }}
|
|
170
|
+
renderTopToolbarCustomActions={() => (
|
|
171
|
+
<ChakraProvider>
|
|
172
|
+
<Stack margin={0} padding={3} direction="row">
|
|
173
|
+
{selectedPage.actions.map((action) => (
|
|
174
|
+
<Button
|
|
175
|
+
colorScheme="blue"
|
|
176
|
+
onClick={() => {
|
|
177
|
+
setSelectedAction(action);
|
|
178
|
+
onOpen();
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
{action.name}
|
|
182
|
+
</Button>
|
|
183
|
+
))}
|
|
184
|
+
</Stack>
|
|
185
|
+
</ChakraProvider>
|
|
186
|
+
)}
|
|
187
|
+
enableRowActions
|
|
188
|
+
renderRowActionMenuItems={(obj: any) => {
|
|
189
|
+
return selectedPage.rowActions.map((rowAction) => (
|
|
190
|
+
<MenuItem
|
|
191
|
+
onClick={() => {
|
|
192
|
+
setSelectedAction(rowAction);
|
|
193
|
+
setRowId(obj.row.original[0]);
|
|
194
|
+
onOpen();
|
|
195
|
+
|
|
196
|
+
const rowActionsMenu = document.querySelector(
|
|
197
|
+
".MuiPaper-root.MuiPopover-paper.MuiMenu-paper"
|
|
198
|
+
);
|
|
199
|
+
if (rowActionsMenu) {
|
|
200
|
+
rowActionsMenu.remove();
|
|
201
|
+
}
|
|
202
|
+
}}
|
|
203
|
+
>
|
|
204
|
+
{rowAction.name + " " + obj.row.original[0]}
|
|
205
|
+
</MenuItem>
|
|
206
|
+
));
|
|
207
|
+
}}
|
|
208
|
+
/>
|
|
209
|
+
</ThemeProvider>
|
|
210
|
+
|
|
211
|
+
<Modal size={"6xl"} isOpen={isOpen} onClose={onClose}>
|
|
212
|
+
<ModalOverlay />
|
|
213
|
+
<ModalContent>
|
|
214
|
+
<ModalHeader>{selectedAction.name}</ModalHeader>
|
|
215
|
+
<ModalCloseButton />
|
|
216
|
+
<ModalBody>
|
|
217
|
+
{selectedAction.fields && selectedAction.fields?.length > 0 ? (
|
|
218
|
+
<GenericForm
|
|
219
|
+
action={selectedAction}
|
|
220
|
+
onClose={onClose}
|
|
221
|
+
rowId={rowId}
|
|
222
|
+
/>
|
|
223
|
+
) : (
|
|
224
|
+
<Button
|
|
225
|
+
colorScheme="blue"
|
|
226
|
+
mr={3}
|
|
227
|
+
onClick={() => {
|
|
228
|
+
selectedAction.onSubmit(rowId);
|
|
229
|
+
onClose();
|
|
230
|
+
}}
|
|
231
|
+
>
|
|
232
|
+
Confirm Action
|
|
233
|
+
</Button>
|
|
234
|
+
)}
|
|
235
|
+
<Button colorScheme="red" mr={3} onClick={onClose}>
|
|
236
|
+
Close
|
|
237
|
+
</Button>
|
|
238
|
+
</ModalBody>
|
|
239
|
+
</ModalContent>
|
|
240
|
+
</Modal>
|
|
241
|
+
</>
|
|
242
|
+
);
|
|
243
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import ReactDOM from "react-dom/client";
|
|
3
|
-
import "./index.css";
|
|
4
|
-
import
|
|
5
|
-
import reportWebVitals from "./reportWebVitals";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
const root = ReactDOM.createRoot(
|
|
9
|
-
document.getElementById("root") as HTMLElement
|
|
10
|
-
);
|
|
11
|
-
root.render(
|
|
12
|
-
<React.StrictMode>
|
|
13
|
-
<
|
|
14
|
-
</React.StrictMode>
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// If you want to start measuring performance in your app, pass a function
|
|
18
|
-
// to log results (for example: reportWebVitals(console.log))
|
|
19
|
-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
20
|
-
reportWebVitals();
|
|
1
|
+
import React from "react";
|
|
2
|
+
import ReactDOM from "react-dom/client";
|
|
3
|
+
import "./index.css";
|
|
4
|
+
import App from "./App";
|
|
5
|
+
import reportWebVitals from "./reportWebVitals";
|
|
6
|
+
import { pages } from "./schema/schema.config";
|
|
7
|
+
|
|
8
|
+
const root = ReactDOM.createRoot(
|
|
9
|
+
document.getElementById("root") as HTMLElement
|
|
10
|
+
);
|
|
11
|
+
root.render(
|
|
12
|
+
<React.StrictMode>
|
|
13
|
+
<App pages={pages} basePath="" />
|
|
14
|
+
</React.StrictMode>
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// If you want to start measuring performance in your app, pass a function
|
|
18
|
+
// to log results (for example: reportWebVitals(console.log))
|
|
19
|
+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
20
|
+
reportWebVitals();
|