admin_lsac 1.4.8 → 1.5.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.
- package/.eslintrc.cjs +1 -1
- package/README.md +16 -14
- package/admin_lsac.d.ts +68 -0
- package/dist/esm/src/admin_lsac.d.ts +68 -0
- package/package.json +1 -1
package/.eslintrc.cjs
CHANGED
|
@@ -6,7 +6,7 @@ module.exports = {
|
|
|
6
6
|
'plugin:@typescript-eslint/recommended',
|
|
7
7
|
'plugin:react-hooks/recommended',
|
|
8
8
|
],
|
|
9
|
-
ignorePatterns: ['dist', '.eslintrc.cjs', 'src/testSchemas'],
|
|
9
|
+
ignorePatterns: ['dist', '.eslintrc.cjs', 'src/testSchemas', 'admin_lsac.d.ts'],
|
|
10
10
|
parser: '@typescript-eslint/parser',
|
|
11
11
|
plugins: ['react-refresh'],
|
|
12
12
|
rules: {
|
package/README.md
CHANGED
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
For configuring your own admin panel, follow the next instructions.
|
|
4
4
|
|
|
5
|
+
## How to install it?
|
|
6
|
+
|
|
5
7
|
### `npm install admin_lsac`
|
|
6
8
|
|
|
7
9
|
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
10
|
|
|
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
11
|
## What do you need to import?
|
|
14
12
|
|
|
15
13
|
### `import { ChakraProvider } from '@chakra-ui/react'`
|
|
@@ -18,13 +16,15 @@ Export-to-csv package latest version is not working properly, so make sure you h
|
|
|
18
16
|
|
|
19
17
|
### `import { AdminPage } from 'admin_lsac'`
|
|
20
18
|
|
|
21
|
-
You can import these in App.js / App.ts
|
|
19
|
+
You can import these in App.js / App.ts or wherever your routes to the pages are located.
|
|
22
20
|
|
|
23
21
|
### `import { PageSchema } from 'admin_lsac'`
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
If your project is TypeScript-based, you need to use the line above as well.
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
- Import the component from above where you want to write your schemas. (See below for details about schemas)
|
|
26
|
+
|
|
27
|
+
## How to add routes to the admin panel's pages?
|
|
28
28
|
|
|
29
29
|
```
|
|
30
30
|
{your_array.map((page) => (
|
|
@@ -39,7 +39,7 @@ You need to create an array of schemas for your own admin panel. You can write t
|
|
|
39
39
|
}
|
|
40
40
|
/>
|
|
41
41
|
))}
|
|
42
|
-
{your_array[0] ? (
|
|
42
|
+
{your_array[0] ? ( // recommended default route when accessing admin panel
|
|
43
43
|
<Route
|
|
44
44
|
path={`${your_url_to_admin_panel}/*`}
|
|
45
45
|
element={
|
|
@@ -53,7 +53,9 @@ You need to create an array of schemas for your own admin panel. You can write t
|
|
|
53
53
|
) : null}
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
You will need to create an array of schemas for your own admin panel.
|
|
57
|
+
|
|
58
|
+
#### ⚠️ Don't forget to wrap the Router component into a ChakraProvider component. Otherwise, you will not like the way it looks. :)
|
|
57
59
|
|
|
58
60
|
## What is a schema?
|
|
59
61
|
|
|
@@ -121,9 +123,9 @@ export interface RowAction {
|
|
|
121
123
|
}
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
A page schema is based on these interfaces,
|
|
126
|
+
A page schema is based on these interfaces, and it describes how one table of your admin panel would need to be structured to accomplish what the user needs to do regarding an entity. (i.e. users, teams, companies, quizzes)
|
|
125
127
|
|
|
126
|
-
#### An array of schemas
|
|
128
|
+
#### An array of schemas must be defined as below:
|
|
127
129
|
|
|
128
130
|
```
|
|
129
131
|
const your_array = [
|
|
@@ -137,7 +139,7 @@ const your_array = [
|
|
|
137
139
|
];
|
|
138
140
|
```
|
|
139
141
|
|
|
140
|
-
|
|
142
|
+
- In TypeScript, it would slightly change:
|
|
141
143
|
|
|
142
144
|
```
|
|
143
145
|
const your_array: PageSchema[] = [
|
|
@@ -153,9 +155,9 @@ const your_array: PageSchema[] = [
|
|
|
153
155
|
|
|
154
156
|
## Other Specifications
|
|
155
157
|
|
|
156
|
-
Due to some corrupt dependencies, you need a Node version >= 20.5.0 to use this package in a
|
|
158
|
+
Due to some corrupt dependencies, you will need a Node version >= 20.5.0 to use this NPM package (it may work in some cases, but we still recommend updating Node to a newer version).
|
|
157
159
|
|
|
158
|
-
For every entity you describe through a page schema, getRequest and onSubmit functions
|
|
160
|
+
For every entity you describe through a page schema, getRequest and onSubmit functions use routes created for the entity. `getRequest` function makes a GET request, while `onSumbit` function generally makes a POST, PATCH or DELETE request.
|
|
159
161
|
|
|
160
162
|
## Learn More
|
|
161
163
|
|
package/admin_lsac.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
declare module 'admin_lsac' {
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export interface TableField {
|
|
4
|
+
name: string;
|
|
5
|
+
access: (obj: any) => string | number | React.ReactElement;
|
|
6
|
+
}
|
|
7
|
+
export interface SimpleField {
|
|
8
|
+
name: string;
|
|
9
|
+
label: string;
|
|
10
|
+
type: 'string' | 'number' | 'file';
|
|
11
|
+
validationSchema: any;
|
|
12
|
+
}
|
|
13
|
+
export interface Option {
|
|
14
|
+
value: string | number | boolean;
|
|
15
|
+
display: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DropdownField {
|
|
18
|
+
name: string;
|
|
19
|
+
label: string;
|
|
20
|
+
type: 'dropdown';
|
|
21
|
+
options?: Option[] | undefined;
|
|
22
|
+
getOptions: () => Promise<Option[]>;
|
|
23
|
+
}
|
|
24
|
+
export interface ObjectField {
|
|
25
|
+
name: string;
|
|
26
|
+
label: string;
|
|
27
|
+
type: 'object';
|
|
28
|
+
fields: FormField[];
|
|
29
|
+
}
|
|
30
|
+
export interface ArrayField {
|
|
31
|
+
name: string;
|
|
32
|
+
label: string;
|
|
33
|
+
type: 'array';
|
|
34
|
+
element: Exclude<FormField, ArrayField>;
|
|
35
|
+
}
|
|
36
|
+
export type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
|
|
37
|
+
export interface Action {
|
|
38
|
+
name: string;
|
|
39
|
+
fields?: FormField[];
|
|
40
|
+
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
41
|
+
}
|
|
42
|
+
export interface RowAction {
|
|
43
|
+
name: string;
|
|
44
|
+
fields?: FormField[];
|
|
45
|
+
initialise?: (obj: any) => any;
|
|
46
|
+
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
47
|
+
}
|
|
48
|
+
export interface PageSchema {
|
|
49
|
+
name: string;
|
|
50
|
+
actions: Action[];
|
|
51
|
+
rowActions: RowAction[];
|
|
52
|
+
getRequest: () => Promise<any[]>;
|
|
53
|
+
tableFields: TableField[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function pageToUrl(page: PageSchema): string;
|
|
57
|
+
export function AdminPage({
|
|
58
|
+
pages,
|
|
59
|
+
selectedPage,
|
|
60
|
+
basePath,
|
|
61
|
+
apiURL,
|
|
62
|
+
}: {
|
|
63
|
+
pages: PageSchema[];
|
|
64
|
+
selectedPage: PageSchema;
|
|
65
|
+
basePath: string;
|
|
66
|
+
apiURL?: string;
|
|
67
|
+
}): import('react/jsx-runtime').JSX.Element;
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
declare module 'admin_lsac' {
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
export interface TableField {
|
|
4
|
+
name: string;
|
|
5
|
+
access: (obj: any) => string | number | React.ReactElement;
|
|
6
|
+
}
|
|
7
|
+
export interface SimpleField {
|
|
8
|
+
name: string;
|
|
9
|
+
label: string;
|
|
10
|
+
type: 'string' | 'number' | 'file';
|
|
11
|
+
validationSchema: any;
|
|
12
|
+
}
|
|
13
|
+
export interface Option {
|
|
14
|
+
value: string | number | boolean;
|
|
15
|
+
display: string;
|
|
16
|
+
}
|
|
17
|
+
export interface DropdownField {
|
|
18
|
+
name: string;
|
|
19
|
+
label: string;
|
|
20
|
+
type: 'dropdown';
|
|
21
|
+
options?: Option[] | undefined;
|
|
22
|
+
getOptions: () => Promise<Option[]>;
|
|
23
|
+
}
|
|
24
|
+
export interface ObjectField {
|
|
25
|
+
name: string;
|
|
26
|
+
label: string;
|
|
27
|
+
type: 'object';
|
|
28
|
+
fields: FormField[];
|
|
29
|
+
}
|
|
30
|
+
export interface ArrayField {
|
|
31
|
+
name: string;
|
|
32
|
+
label: string;
|
|
33
|
+
type: 'array';
|
|
34
|
+
element: Exclude<FormField, ArrayField>;
|
|
35
|
+
}
|
|
36
|
+
export type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
|
|
37
|
+
export interface Action {
|
|
38
|
+
name: string;
|
|
39
|
+
fields?: FormField[];
|
|
40
|
+
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
41
|
+
}
|
|
42
|
+
export interface RowAction {
|
|
43
|
+
name: string;
|
|
44
|
+
fields?: FormField[];
|
|
45
|
+
initialise?: (obj: any) => any;
|
|
46
|
+
onSubmit: (obj1: any, obj2?: any) => Promise<any>;
|
|
47
|
+
}
|
|
48
|
+
export interface PageSchema {
|
|
49
|
+
name: string;
|
|
50
|
+
actions: Action[];
|
|
51
|
+
rowActions: RowAction[];
|
|
52
|
+
getRequest: () => Promise<any[]>;
|
|
53
|
+
tableFields: TableField[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function pageToUrl(page: PageSchema): string;
|
|
57
|
+
export function AdminPage({
|
|
58
|
+
pages,
|
|
59
|
+
selectedPage,
|
|
60
|
+
basePath,
|
|
61
|
+
apiURL,
|
|
62
|
+
}: {
|
|
63
|
+
pages: PageSchema[];
|
|
64
|
+
selectedPage: PageSchema;
|
|
65
|
+
basePath: string;
|
|
66
|
+
apiURL?: string;
|
|
67
|
+
}): import('react/jsx-runtime').JSX.Element;
|
|
68
|
+
}
|