admin_lsac 1.3.2 → 1.4.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/.eslintrc.cjs +18 -0
- package/README.md +162 -162
- package/dist/src/App.d.ts +7 -0
- package/dist/src/App.js +10 -0
- package/dist/src/components/AdminPage.d.ts +8 -0
- package/dist/{esm/components/Page.js → src/components/AdminPage.js} +35 -43
- package/dist/src/components/GenericForm.d.ts +8 -0
- package/dist/src/components/GenericForm.js +151 -0
- package/dist/src/main.d.ts +1 -0
- package/dist/src/main.js +7 -0
- package/dist/{App.d.ts → src/schema.d.ts} +53 -76
- package/dist/src/testSchemas/event.d.ts +2 -0
- package/dist/src/testSchemas/event.js +86 -0
- package/dist/src/utils/websockets.d.ts +1 -0
- package/dist/{esm → src}/utils/websockets.js +5 -5
- package/index.html +13 -0
- package/package.json +42 -73
- package/tsconfig.app.json +27 -0
- package/tsconfig.json +11 -31
- package/tsconfig.node.json +13 -0
- package/vite.config.ts +7 -0
- package/dist/App.js +0 -12
- package/dist/cjs/App.js +0 -12
- package/dist/cjs/components/GenericForm.js +0 -305
- package/dist/cjs/components/Page.js +0 -119
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/pages/event.js +0 -134
- package/dist/cjs/pages/page.js +0 -375
- package/dist/cjs/reportWebVitals.js +0 -38
- package/dist/cjs/schema/schema.config.js +0 -9
- package/dist/cjs/schema/schema.js +0 -2
- package/dist/cjs/setupTests.js +0 -7
- package/dist/cjs/utils/websockets.js +0 -22
- package/dist/components/GenericForm.js +0 -305
- package/dist/components/Page.js +0 -119
- package/dist/esm/App.js +0 -10
- package/dist/esm/components/GenericForm.js +0 -275
- package/dist/esm/index.js +0 -13
- package/dist/esm/pages/event.js +0 -128
- package/dist/esm/pages/page.js +0 -349
- package/dist/esm/reportWebVitals.js +0 -13
- package/dist/esm/schema/schema.config.js +0 -6
- package/dist/esm/setupTests.js +0 -5
- package/dist/index.js +0 -18
- package/dist/pages/event.js +0 -134
- package/dist/pages/page.js +0 -375
- package/dist/reportWebVitals.js +0 -38
- package/dist/schema/schema.config.js +0 -9
- package/dist/schema/schema.js +0 -2
- package/dist/setupTests.js +0 -7
- package/dist/utils/websockets.js +0 -22
- package/public/favicon.ico +0 -0
- package/public/index.html +0 -43
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/server/.env.example +0 -3
- package/server/deploy.js +0 -29
- package/server/package-lock.json +0 -712
- package/server/package.json +0 -18
- package/src/App.css +0 -38
- package/src/App.tsx +0 -50
- package/src/components/GenericForm.tsx +0 -308
- package/src/components/Page.tsx +0 -243
- package/src/index.css +0 -13
- package/src/index.tsx +0 -20
- package/src/logo.svg +0 -1
- package/src/pages/event.ts +0 -93
- package/src/pages/page.ts +0 -336
- package/src/react-app-env.d.ts +0 -1
- package/src/reportWebVitals.ts +0 -15
- package/src/schema/schema.config.ts +0 -8
- package/src/schema/schema.ts +0 -63
- package/src/setupTests.ts +0 -5
- package/src/utils/websockets.tsx +0 -17
- package/tsconfig.esm.json +0 -7
- package/webpack.config.js +0 -22
- /package/dist/{esm/schema → src}/schema.js +0 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: { browser: true, es2020: true },
|
|
4
|
+
extends: [
|
|
5
|
+
'eslint:recommended',
|
|
6
|
+
'plugin:@typescript-eslint/recommended',
|
|
7
|
+
'plugin:react-hooks/recommended',
|
|
8
|
+
],
|
|
9
|
+
ignorePatterns: ['dist', '.eslintrc.cjs'],
|
|
10
|
+
parser: '@typescript-eslint/parser',
|
|
11
|
+
plugins: ['react-refresh'],
|
|
12
|
+
rules: {
|
|
13
|
+
'react-refresh/only-export-components': [
|
|
14
|
+
'warn',
|
|
15
|
+
{ allowConstantExport: true },
|
|
16
|
+
],
|
|
17
|
+
},
|
|
18
|
+
}
|
package/README.md
CHANGED
|
@@ -1,162 +1,162 @@
|
|
|
1
|
-
# Generic Admin Panel
|
|
2
|
-
|
|
3
|
-
For configuring your own admin panel, follow the next instructions.
|
|
4
|
-
|
|
5
|
-
### `npm install admin_lsac`
|
|
6
|
-
|
|
7
|
-
This command will download and install the specified package and its dependencies into your project's node_modules directory, making it available for use in your project.
|
|
8
|
-
|
|
9
|
-
### `npm install export-to-csv@1.2.1`
|
|
10
|
-
|
|
11
|
-
Export-to-csv package latest version is not working properly, so make sure you have the last functional version of this package install.
|
|
12
|
-
|
|
13
|
-
## What do you need to import?
|
|
14
|
-
|
|
15
|
-
### `import { ChakraProvider } from '@chakra-ui/react'`
|
|
16
|
-
|
|
17
|
-
### `import { pageToUrl } from 'admin_lsac'`
|
|
18
|
-
|
|
19
|
-
### `import { AdminPage } from 'admin_lsac'`
|
|
20
|
-
|
|
21
|
-
You can import these in App.js / App.ts. If your project is TypeScript-based, you need to write the following line as well:
|
|
22
|
-
|
|
23
|
-
### `import { PageSchema } from 'admin_lsac'`
|
|
24
|
-
|
|
25
|
-
* Import the component from above where you want to write your schemas. (See below for details about schemas)
|
|
26
|
-
|
|
27
|
-
You need to create an array of schemas for your own admin panel. You can write the following inside your Routes component from App.js / App.ts:
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
{your_array.map((page) => (
|
|
31
|
-
<Route
|
|
32
|
-
path={`${your_url_to_admin_panel}/${pageToUrl(page)}`}
|
|
33
|
-
element={
|
|
34
|
-
<AdminPage
|
|
35
|
-
pages={your_array}
|
|
36
|
-
selectedPage={page}
|
|
37
|
-
basePath={your_url_to_admin_panel}
|
|
38
|
-
/>
|
|
39
|
-
}
|
|
40
|
-
/>
|
|
41
|
-
))}
|
|
42
|
-
{your_array[0] ? (
|
|
43
|
-
<Route
|
|
44
|
-
path={`${your_url_to_admin_panel}/*`}
|
|
45
|
-
element={
|
|
46
|
-
<AdminPage
|
|
47
|
-
pages={your_array}
|
|
48
|
-
selectedPage={your_array[0]}
|
|
49
|
-
basePath={your_url_to_admin_panel}
|
|
50
|
-
/>
|
|
51
|
-
}
|
|
52
|
-
/>
|
|
53
|
-
) : null}
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
#### ⚠️ Don't forget to wrap the Router component into a ChakraProvider component.
|
|
57
|
-
|
|
58
|
-
## What is a schema?
|
|
59
|
-
|
|
60
|
-
```
|
|
61
|
-
export interface PageSchema {
|
|
62
|
-
name: string;
|
|
63
|
-
actions: Action[];
|
|
64
|
-
rowActions: RowAction[];
|
|
65
|
-
getRequest: () => Promise<any[]>;
|
|
66
|
-
tableFields: TableField[];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export interface TableField {
|
|
70
|
-
name: string;
|
|
71
|
-
access: (obj: any) => string | number | React.ReactElement;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface SimpleField {
|
|
75
|
-
name: string;
|
|
76
|
-
label: string;
|
|
77
|
-
type: "string" | "number" | "file";
|
|
78
|
-
validationSchema: any;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export interface Option {
|
|
82
|
-
value: string | number | boolean;
|
|
83
|
-
display: string;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface DropdownField {
|
|
87
|
-
name: string;
|
|
88
|
-
label: string;
|
|
89
|
-
type: "dropdown";
|
|
90
|
-
options?: Option[] | undefined;
|
|
91
|
-
getOptions: () => Promise<Option[]>;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export interface ObjectField {
|
|
95
|
-
name: string;
|
|
96
|
-
label: string;
|
|
97
|
-
type: "object";
|
|
98
|
-
fields: FormField[];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface ArrayField {
|
|
102
|
-
name: string;
|
|
103
|
-
label: string;
|
|
104
|
-
type: "array";
|
|
105
|
-
element: Exclude<FormField, ArrayField>;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
|
|
109
|
-
|
|
110
|
-
export interface Action {
|
|
111
|
-
name: string;
|
|
112
|
-
fields?: FormField[];
|
|
113
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface RowAction {
|
|
117
|
-
name: string;
|
|
118
|
-
fields?: FormField[];
|
|
119
|
-
initialise?: (obj: any) => any;
|
|
120
|
-
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
A page schema is based on these interfaces, which can be imported into your files. A page schema describes how one table of your admin panel would need to be structured to accomplish what the user needs regarding an entity. (i.e. users, teams, companies, quizzes)
|
|
125
|
-
|
|
126
|
-
#### An array of schemas would be defined as follows:
|
|
127
|
-
|
|
128
|
-
```
|
|
129
|
-
const your_array = [
|
|
130
|
-
{
|
|
131
|
-
// schema 1
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
// schema 2
|
|
135
|
-
},
|
|
136
|
-
...
|
|
137
|
-
];
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
* In TypeScript, it would slightly change:
|
|
141
|
-
|
|
142
|
-
```
|
|
143
|
-
const your_array: PageSchema[] = [
|
|
144
|
-
{
|
|
145
|
-
// schema 1
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
// schema 2
|
|
149
|
-
},
|
|
150
|
-
...
|
|
151
|
-
];
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## Other Specifications
|
|
155
|
-
|
|
156
|
-
Due to some corrupt dependencies, you need a Node version >= 20.5.0 to use this package in a Vite app.
|
|
157
|
-
|
|
158
|
-
For every entity you describe through a page schema, getRequest and onSubmit functions will use routes created for the entity. `getRequest` function will make a GET request, while `onSumbit` will probably make a POST, PATCH or DELETE request.
|
|
159
|
-
|
|
160
|
-
## Learn More
|
|
161
|
-
|
|
162
|
-
For more details, especially about page schemas, contact the owner. :)
|
|
1
|
+
# Generic Admin Panel
|
|
2
|
+
|
|
3
|
+
For configuring your own admin panel, follow the next instructions.
|
|
4
|
+
|
|
5
|
+
### `npm install admin_lsac`
|
|
6
|
+
|
|
7
|
+
This command will download and install the specified package and its dependencies into your project's node_modules directory, making it available for use in your project.
|
|
8
|
+
|
|
9
|
+
### `npm install export-to-csv@1.2.1`
|
|
10
|
+
|
|
11
|
+
Export-to-csv package latest version is not working properly, so make sure you have the last functional version of this package install.
|
|
12
|
+
|
|
13
|
+
## What do you need to import?
|
|
14
|
+
|
|
15
|
+
### `import { ChakraProvider } from '@chakra-ui/react'`
|
|
16
|
+
|
|
17
|
+
### `import { pageToUrl } from 'admin_lsac'`
|
|
18
|
+
|
|
19
|
+
### `import { AdminPage } from 'admin_lsac'`
|
|
20
|
+
|
|
21
|
+
You can import these in App.js / App.ts. If your project is TypeScript-based, you need to write the following line as well:
|
|
22
|
+
|
|
23
|
+
### `import { PageSchema } from 'admin_lsac'`
|
|
24
|
+
|
|
25
|
+
* Import the component from above where you want to write your schemas. (See below for details about schemas)
|
|
26
|
+
|
|
27
|
+
You need to create an array of schemas for your own admin panel. You can write the following inside your Routes component from App.js / App.ts:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
{your_array.map((page) => (
|
|
31
|
+
<Route
|
|
32
|
+
path={`${your_url_to_admin_panel}/${pageToUrl(page)}`}
|
|
33
|
+
element={
|
|
34
|
+
<AdminPage
|
|
35
|
+
pages={your_array}
|
|
36
|
+
selectedPage={page}
|
|
37
|
+
basePath={your_url_to_admin_panel}
|
|
38
|
+
/>
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
))}
|
|
42
|
+
{your_array[0] ? (
|
|
43
|
+
<Route
|
|
44
|
+
path={`${your_url_to_admin_panel}/*`}
|
|
45
|
+
element={
|
|
46
|
+
<AdminPage
|
|
47
|
+
pages={your_array}
|
|
48
|
+
selectedPage={your_array[0]}
|
|
49
|
+
basePath={your_url_to_admin_panel}
|
|
50
|
+
/>
|
|
51
|
+
}
|
|
52
|
+
/>
|
|
53
|
+
) : null}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
#### ⚠️ Don't forget to wrap the Router component into a ChakraProvider component.
|
|
57
|
+
|
|
58
|
+
## What is a schema?
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
export interface PageSchema {
|
|
62
|
+
name: string;
|
|
63
|
+
actions: Action[];
|
|
64
|
+
rowActions: RowAction[];
|
|
65
|
+
getRequest: () => Promise<any[]>;
|
|
66
|
+
tableFields: TableField[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface TableField {
|
|
70
|
+
name: string;
|
|
71
|
+
access: (obj: any) => string | number | React.ReactElement;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface SimpleField {
|
|
75
|
+
name: string;
|
|
76
|
+
label: string;
|
|
77
|
+
type: "string" | "number" | "file";
|
|
78
|
+
validationSchema: any;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface Option {
|
|
82
|
+
value: string | number | boolean;
|
|
83
|
+
display: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface DropdownField {
|
|
87
|
+
name: string;
|
|
88
|
+
label: string;
|
|
89
|
+
type: "dropdown";
|
|
90
|
+
options?: Option[] | undefined;
|
|
91
|
+
getOptions: () => Promise<Option[]>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface ObjectField {
|
|
95
|
+
name: string;
|
|
96
|
+
label: string;
|
|
97
|
+
type: "object";
|
|
98
|
+
fields: FormField[];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface ArrayField {
|
|
102
|
+
name: string;
|
|
103
|
+
label: string;
|
|
104
|
+
type: "array";
|
|
105
|
+
element: Exclude<FormField, ArrayField>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
|
|
109
|
+
|
|
110
|
+
export interface Action {
|
|
111
|
+
name: string;
|
|
112
|
+
fields?: FormField[];
|
|
113
|
+
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface RowAction {
|
|
117
|
+
name: string;
|
|
118
|
+
fields?: FormField[];
|
|
119
|
+
initialise?: (obj: any) => any;
|
|
120
|
+
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
A page schema is based on these interfaces, which can be imported into your files. A page schema describes how one table of your admin panel would need to be structured to accomplish what the user needs regarding an entity. (i.e. users, teams, companies, quizzes)
|
|
125
|
+
|
|
126
|
+
#### An array of schemas would be defined as follows:
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
const your_array = [
|
|
130
|
+
{
|
|
131
|
+
// schema 1
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
// schema 2
|
|
135
|
+
},
|
|
136
|
+
...
|
|
137
|
+
];
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
* In TypeScript, it would slightly change:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
const your_array: PageSchema[] = [
|
|
144
|
+
{
|
|
145
|
+
// schema 1
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
// schema 2
|
|
149
|
+
},
|
|
150
|
+
...
|
|
151
|
+
];
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Other Specifications
|
|
155
|
+
|
|
156
|
+
Due to some corrupt dependencies, you need a Node version >= 20.5.0 to use this package in a Vite app.
|
|
157
|
+
|
|
158
|
+
For every entity you describe through a page schema, getRequest and onSubmit functions will use routes created for the entity. `getRequest` function will make a GET request, while `onSumbit` will probably make a POST, PATCH or DELETE request.
|
|
159
|
+
|
|
160
|
+
## Learn More
|
|
161
|
+
|
|
162
|
+
For more details, especially about page schemas, contact the owner. :)
|
package/dist/src/App.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ChakraProvider } from "@chakra-ui/react";
|
|
3
|
+
import { BrowserRouter, Route, Routes } from "react-router-dom";
|
|
4
|
+
import { AdminPage } from "./components/AdminPage";
|
|
5
|
+
import { pageToUrl } from "./components/AdminPage";
|
|
6
|
+
import './App.css';
|
|
7
|
+
function App({ pages, basePath, }) {
|
|
8
|
+
return (_jsx(ChakraProvider, { children: _jsx(BrowserRouter, { children: _jsxs(Routes, { children: [pages.map((page) => (_jsx(Route, { path: `${basePath}/${pageToUrl(page)}`, element: _jsx(AdminPage, { pages: pages, selectedPage: page, basePath: basePath, apiURL: "http://localhost:3001/" }) }))), pages[0] ? (_jsx(Route, { path: `${basePath}/*`, element: _jsx(AdminPage, { pages: pages, selectedPage: pages[0], basePath: basePath, apiURL: "http://localhost:3001/" }) })) : null] }) }) }));
|
|
9
|
+
}
|
|
10
|
+
export default App;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PageSchema } from "../schema";
|
|
2
|
+
export declare function pageToUrl(page: PageSchema): string;
|
|
3
|
+
export declare function AdminPage({ pages, selectedPage, basePath, apiURL }: {
|
|
4
|
+
pages: PageSchema[];
|
|
5
|
+
selectedPage: PageSchema;
|
|
6
|
+
basePath: string;
|
|
7
|
+
apiURL?: string;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -12,41 +12,37 @@ import MenuItem from "@mui/material/MenuItem";
|
|
|
12
12
|
import { io } from "socket.io-client";
|
|
13
13
|
import { newSocket } from "../utils/websockets";
|
|
14
14
|
export function pageToUrl(page) {
|
|
15
|
-
return
|
|
15
|
+
return `${page.name.toLowerCase().replace(" ", "_")}`;
|
|
16
16
|
}
|
|
17
|
-
function Header(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var filename = prompt("Enter filename:");
|
|
17
|
+
function Header({ pages, data, basePath, }) {
|
|
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", children: pages.map((p) => (_jsx(Box, { as: "a", href: `${basePath}/${pageToUrl(p)}`, children: p.name }))) }), _jsx(Stack, { direction: "row", children: _jsx(Button, { colorScheme: "red", onClick: () => {
|
|
19
|
+
const filename = prompt("Enter filename:");
|
|
21
20
|
if (filename)
|
|
22
21
|
exportToCSV(data, filename);
|
|
23
22
|
}, children: "Export Data" }) })] }) }));
|
|
24
23
|
}
|
|
25
24
|
function exportToCSV(data, filename) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const formatImageData = (obj) => {
|
|
26
|
+
const formattedObj = {};
|
|
27
|
+
for (const key in obj) {
|
|
29
28
|
if (typeof obj[key] !== "object") {
|
|
30
29
|
formattedObj[key] = obj[key];
|
|
31
30
|
}
|
|
32
31
|
else if (typeof obj[key] === "object" && obj[key] != null) {
|
|
33
|
-
Object.keys(obj[key]).forEach(
|
|
34
|
-
formattedObj[
|
|
32
|
+
Object.keys(obj[key]).forEach((k) => {
|
|
33
|
+
formattedObj[`${key}.${k}`] = obj[key][k];
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
};
|
|
38
|
-
for (var key in obj) {
|
|
39
|
-
_loop_1(key);
|
|
40
36
|
}
|
|
41
37
|
return formattedObj;
|
|
42
38
|
};
|
|
43
|
-
|
|
44
|
-
|
|
39
|
+
const formattedData = data.map(formatImageData);
|
|
40
|
+
const csvConfig = mkConfig({
|
|
45
41
|
useKeysAsHeaders: true,
|
|
46
42
|
filename: filename,
|
|
47
43
|
});
|
|
48
44
|
if (formattedData.length > 0) {
|
|
49
|
-
|
|
45
|
+
const csv = generateCsv(csvConfig)(formattedData);
|
|
50
46
|
download(csvConfig)(csv);
|
|
51
47
|
}
|
|
52
48
|
else {
|
|
@@ -56,55 +52,51 @@ function exportToCSV(data, filename) {
|
|
|
56
52
|
});
|
|
57
53
|
}
|
|
58
54
|
}
|
|
59
|
-
export function AdminPage(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var _j = useState(false), refetch = _j[0], setRefetch = _j[1];
|
|
68
|
-
var _k = useState(io), socket = _k[0], setSocket = _k[1];
|
|
55
|
+
export function AdminPage({ pages, selectedPage, basePath, apiURL = '' }) {
|
|
56
|
+
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
57
|
+
const [selectedAction, setSelectedAction] = useState({});
|
|
58
|
+
const [data, setData] = useState([]);
|
|
59
|
+
const [displayData, setDisplayData] = useState([]);
|
|
60
|
+
const [rowId, setRowId] = useState();
|
|
61
|
+
const [refetch, setRefetch] = useState(false);
|
|
62
|
+
const [socket, setSocket] = useState(io);
|
|
69
63
|
newSocket(setSocket, apiURL);
|
|
70
|
-
useEffect(
|
|
71
|
-
selectedPage.getRequest().then(
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
selectedPage.getRequest().then((resArray) => {
|
|
72
66
|
setData(resArray);
|
|
73
67
|
setRefetch(false);
|
|
74
68
|
});
|
|
75
69
|
}, [refetch]); // Do not remove 'refetch' from here !!!
|
|
76
|
-
useEffect(
|
|
77
|
-
socket.on("updateData",
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
socket.on("updateData", (message) => {
|
|
78
72
|
console.log("Message emitted from socket: " + message);
|
|
79
73
|
setRefetch(true);
|
|
80
|
-
|
|
74
|
+
const rowActionsMenu = document.querySelector(".MuiPaper-root.MuiPopover-paper.MuiMenu-paper");
|
|
81
75
|
if (rowActionsMenu) {
|
|
82
76
|
rowActionsMenu.remove();
|
|
83
77
|
}
|
|
84
78
|
});
|
|
85
79
|
}, [socket, selectedPage]);
|
|
86
|
-
useEffect(
|
|
87
|
-
setDisplayData(data.map(
|
|
88
|
-
return selectedPage.tableFields.map(function (field) { return field.access(table_data); });
|
|
89
|
-
}));
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
setDisplayData(data.map((table_data) => selectedPage.tableFields.map((field) => field.access(table_data))));
|
|
90
82
|
}, [data]);
|
|
91
|
-
return (_jsxs(_Fragment, { children: [_jsx(Header, { pages: pages, data: data, basePath: basePath }), _jsx(ThemeProvider, { theme: createTheme(), children: _jsx(MaterialReactTable, { columns: selectedPage.tableFields.map(
|
|
92
|
-
accessorFn:
|
|
83
|
+
return (_jsxs(_Fragment, { children: [_jsx(Header, { pages: pages, data: data, basePath: basePath }), _jsx(ThemeProvider, { theme: createTheme(), children: _jsx(MaterialReactTable, { columns: selectedPage.tableFields.map((field, index) => ({
|
|
84
|
+
accessorFn: (row) => row[index],
|
|
93
85
|
header: field.name,
|
|
94
|
-
})
|
|
86
|
+
})), data: displayData, muiTableContainerProps: { sx: { maxHeight: "70vh" } }, enableColumnResizing: true, enableColumnPinning: true, enableGlobalFilterModes: true, enablePagination: true, paginationDisplayMode: "pages", enableRowVirtualization: true, rowVirtualizerOptions: { overscan: 20 }, renderTopToolbarCustomActions: () => (_jsx(ChakraProvider, { children: _jsx(Stack, { margin: 0, padding: 3, direction: "row", children: selectedPage.actions.map((action) => (_jsx(Button, { colorScheme: "blue", onClick: () => {
|
|
95
87
|
setSelectedAction(action);
|
|
96
88
|
onOpen();
|
|
97
|
-
}, children: action.name }))
|
|
98
|
-
return selectedPage.rowActions.map(
|
|
89
|
+
}, children: action.name }))) }) })), enableRowActions: true, renderRowActionMenuItems: (obj) => {
|
|
90
|
+
return selectedPage.rowActions.map((rowAction) => (_jsx(MenuItem, { onClick: () => {
|
|
99
91
|
setSelectedAction(rowAction);
|
|
100
92
|
setRowId(obj.row.original[0]);
|
|
101
93
|
onOpen();
|
|
102
|
-
|
|
94
|
+
const rowActionsMenu = document.querySelector(".MuiPaper-root.MuiPopover-paper.MuiMenu-paper");
|
|
103
95
|
if (rowActionsMenu) {
|
|
104
96
|
rowActionsMenu.remove();
|
|
105
97
|
}
|
|
106
|
-
}, children: rowAction.name + " " + obj.row.original[0] }))
|
|
107
|
-
} }) }), _jsxs(Modal, { size: "6xl", isOpen: isOpen, onClose: onClose, children: [_jsx(ModalOverlay, {}), _jsxs(ModalContent, { children: [_jsx(ModalHeader, { children: selectedAction.name }), _jsx(ModalCloseButton, {}), _jsxs(ModalBody, { children: [selectedAction.fields &&
|
|
98
|
+
}, children: rowAction.name + " " + obj.row.original[0] })));
|
|
99
|
+
} }) }), _jsxs(Modal, { size: "6xl", isOpen: isOpen, onClose: onClose, children: [_jsx(ModalOverlay, {}), _jsxs(ModalContent, { children: [_jsx(ModalHeader, { children: selectedAction.name }), _jsx(ModalCloseButton, {}), _jsxs(ModalBody, { children: [selectedAction.fields && selectedAction.fields?.length > 0 ? (_jsx(GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId })) : (_jsx(Button, { colorScheme: "blue", mr: 3, onClick: () => {
|
|
108
100
|
selectedAction.onSubmit(rowId);
|
|
109
101
|
onClose();
|
|
110
102
|
}, children: "Confirm Action" })), _jsx(Button, { colorScheme: "red", mr: 3, onClick: onClose, children: "Close" })] })] })] })] }));
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Action, RowAction } from "../schema";
|
|
2
|
+
interface GenericFormProps {
|
|
3
|
+
action: Action | RowAction;
|
|
4
|
+
onClose?: () => void;
|
|
5
|
+
rowId?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function GenericForm({ action, onClose, rowId }: GenericFormProps): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|