admin_lsac 1.2.2 → 1.2.4

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.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -33,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
33
37
  function verb(n) { return function (v) { return step([n, v]); }; }
34
38
  function step(op) {
35
39
  if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
37
41
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
42
  if (y = 0, t) op = [op[0] & 2, t.value];
39
43
  switch (op[0]) {
@@ -85,7 +89,8 @@ var typeAdding = function (objectField) {
85
89
  };
86
90
  var arrayObjs = function (x) {
87
91
  if (x > 0)
88
- return [{
92
+ return [
93
+ {
89
94
  name: "simpleFields",
90
95
  label: "Type SimpleField",
91
96
  type: "array",
@@ -93,31 +98,33 @@ var arrayObjs = function (x) {
93
98
  name: "",
94
99
  label: "",
95
100
  type: "object",
96
- fields: [{
101
+ fields: [
102
+ {
97
103
  name: "name",
98
104
  label: "Name",
99
105
  type: "string",
100
- validationSchema: Yup.string().required()
106
+ validationSchema: Yup.string().required(),
101
107
  },
102
108
  {
103
109
  name: "label",
104
110
  label: "Label",
105
111
  type: "string",
106
- validationSchema: Yup.string().required()
112
+ validationSchema: Yup.string().required(),
107
113
  },
108
114
  {
109
115
  name: "type",
110
116
  label: "Type",
111
117
  type: "string",
112
- validationSchema: Yup.string().required()
118
+ validationSchema: Yup.string().required(),
113
119
  },
114
120
  {
115
121
  name: "validationSchema",
116
122
  label: "Validation Schema",
117
123
  type: "string",
118
- validationSchema: Yup.string().required()
119
- }]
120
- }
124
+ validationSchema: Yup.string().required(),
125
+ },
126
+ ],
127
+ },
121
128
  },
122
129
  {
123
130
  name: "dropdownFields",
@@ -127,17 +134,18 @@ var arrayObjs = function (x) {
127
134
  name: "",
128
135
  label: "",
129
136
  type: "object",
130
- fields: [{
137
+ fields: [
138
+ {
131
139
  name: "name",
132
140
  label: "Name",
133
141
  type: "string",
134
- validationSchema: Yup.string().required()
142
+ validationSchema: Yup.string().required(),
135
143
  },
136
144
  {
137
145
  name: "label",
138
146
  label: "Label",
139
147
  type: "string",
140
- validationSchema: Yup.string().required()
148
+ validationSchema: Yup.string().required(),
141
149
  },
142
150
  {
143
151
  name: "options",
@@ -147,27 +155,30 @@ var arrayObjs = function (x) {
147
155
  name: "",
148
156
  label: "",
149
157
  type: "object",
150
- fields: [{
158
+ fields: [
159
+ {
151
160
  name: "value",
152
161
  label: "Value",
153
162
  type: "string",
154
- validationSchema: Yup.string().required()
163
+ validationSchema: Yup.string().required(),
155
164
  },
156
165
  {
157
166
  name: "display",
158
167
  label: "Display",
159
168
  type: "string",
160
- validationSchema: Yup.string().required()
161
- }]
162
- }
169
+ validationSchema: Yup.string().required(),
170
+ },
171
+ ],
172
+ },
163
173
  },
164
174
  {
165
175
  name: "getOptions",
166
176
  label: "GetOptions Function",
167
177
  type: "string",
168
- validationSchema: Yup.string().required()
169
- }]
170
- }
178
+ validationSchema: Yup.string().required(),
179
+ },
180
+ ],
181
+ },
171
182
  },
172
183
  {
173
184
  name: "objectFields",
@@ -177,19 +188,21 @@ var arrayObjs = function (x) {
177
188
  name: "",
178
189
  label: "",
179
190
  type: "object",
180
- fields: __spreadArray([{
191
+ fields: __spreadArray([
192
+ {
181
193
  name: "name",
182
194
  label: "Name",
183
195
  type: "string",
184
- validationSchema: Yup.string().required()
196
+ validationSchema: Yup.string().required(),
185
197
  },
186
198
  {
187
199
  name: "label",
188
200
  label: "Label",
189
201
  type: "string",
190
- validationSchema: Yup.string().required()
191
- }], arrayObjs(x - 1), true)
192
- }
202
+ validationSchema: Yup.string().required(),
203
+ }
204
+ ], arrayObjs(x - 1), true),
205
+ },
193
206
  },
194
207
  {
195
208
  name: "arrayFields",
@@ -199,20 +212,23 @@ var arrayObjs = function (x) {
199
212
  name: "",
200
213
  label: "",
201
214
  type: "object",
202
- fields: __spreadArray([{
215
+ fields: __spreadArray([
216
+ {
203
217
  name: "name",
204
218
  label: "Name",
205
219
  type: "string",
206
- validationSchema: Yup.string().required()
220
+ validationSchema: Yup.string().required(),
207
221
  },
208
222
  {
209
223
  name: "label",
210
224
  label: "Label",
211
225
  type: "string",
212
- validationSchema: Yup.string().required()
213
- }], arrayObjs(x - 1), true)
214
- }
215
- }];
226
+ validationSchema: Yup.string().required(),
227
+ }
228
+ ], arrayObjs(x - 1), true),
229
+ },
230
+ },
231
+ ];
216
232
  else
217
233
  return [];
218
234
  };
@@ -222,19 +238,21 @@ exports.page = {
222
238
  return [2 /*return*/, []];
223
239
  }); }); },
224
240
  tableFields: [],
225
- actions: [{
241
+ actions: [
242
+ {
226
243
  name: "Create New Page",
227
- fields: [{
244
+ fields: [
245
+ {
228
246
  name: "name",
229
247
  label: "Page Name",
230
248
  type: "string",
231
- validationSchema: Yup.string().required()
249
+ validationSchema: Yup.string().required(),
232
250
  },
233
251
  {
234
252
  name: "getRequest",
235
253
  label: "GetRequest",
236
254
  type: "string",
237
- validationSchema: Yup.string().required()
255
+ validationSchema: Yup.string().required(),
238
256
  },
239
257
  {
240
258
  name: "tableFields",
@@ -244,19 +262,21 @@ exports.page = {
244
262
  name: "",
245
263
  label: "",
246
264
  type: "object",
247
- fields: [{
265
+ fields: [
266
+ {
248
267
  name: "name",
249
268
  label: "TableField Name",
250
269
  type: "string",
251
- validationSchema: Yup.string().required()
270
+ validationSchema: Yup.string().required(),
252
271
  },
253
272
  {
254
273
  name: "access",
255
274
  label: "TableField Access Function",
256
275
  type: "string",
257
- validationSchema: Yup.string().required()
258
- }]
259
- }
276
+ validationSchema: Yup.string().required(),
277
+ },
278
+ ],
279
+ },
260
280
  },
261
281
  {
262
282
  name: "actions",
@@ -266,18 +286,22 @@ exports.page = {
266
286
  name: "",
267
287
  label: "",
268
288
  type: "object",
269
- fields: __spreadArray(__spreadArray([{
289
+ fields: __spreadArray(__spreadArray([
290
+ {
270
291
  name: "name",
271
292
  label: "Action Name",
272
293
  type: "string",
273
- validationSchema: Yup.string().required()
274
- }], arrayObjs(4), true), [{
294
+ validationSchema: Yup.string().required(),
295
+ }
296
+ ], arrayObjs(4), true), [
297
+ {
275
298
  name: "onSubmit",
276
299
  label: "Action OnSubmit Function",
277
300
  type: "string",
278
- validationSchema: Yup.string().required()
279
- }], false)
280
- }
301
+ validationSchema: Yup.string().required(),
302
+ },
303
+ ], false),
304
+ },
281
305
  },
282
306
  {
283
307
  name: "rowActions",
@@ -287,32 +311,37 @@ exports.page = {
287
311
  name: "",
288
312
  label: "",
289
313
  type: "object",
290
- fields: __spreadArray(__spreadArray([{
314
+ fields: __spreadArray(__spreadArray([
315
+ {
291
316
  name: "name",
292
317
  label: "Row Action Name",
293
318
  type: "string",
294
- validationSchema: Yup.string().required()
295
- }], arrayObjs(4), true), [{
319
+ validationSchema: Yup.string().required(),
320
+ }
321
+ ], arrayObjs(4), true), [
322
+ {
296
323
  name: "initialise",
297
324
  label: "Row Action Initialise Function",
298
325
  type: "string",
299
- validationSchema: ""
326
+ validationSchema: "",
300
327
  },
301
328
  {
302
329
  name: "onSubmit",
303
330
  label: "Row Action OnSubmit Function",
304
331
  type: "string",
305
- validationSchema: Yup.string().required()
306
- }], false)
307
- }
308
- }],
332
+ validationSchema: Yup.string().required(),
333
+ },
334
+ ], false),
335
+ },
336
+ },
337
+ ],
309
338
  onSubmit: function (formValues) { return __awaiter(void 0, void 0, void 0, function () {
310
339
  return __generator(this, function (_a) {
311
340
  if (Array.isArray(formValues.actions))
312
341
  formValues.actions.map(function (action) {
313
342
  var _a, _b, _c;
314
- (_a = action.dropdownFields) === null || _a === void 0 ? void 0 : _a.map(function (actionField) { return actionField.type = "dropdown"; });
315
- (_b = action.objectFields) === null || _b === void 0 ? void 0 : _b.map(function (actionField) { return actionField = typeAdding(actionField); });
343
+ (_a = action.dropdownFields) === null || _a === void 0 ? void 0 : _a.map(function (actionField) { return (actionField.type = "dropdown"); });
344
+ (_b = action.objectFields) === null || _b === void 0 ? void 0 : _b.map(function (actionField) { return (actionField = typeAdding(actionField)); });
316
345
  (_c = action.arrayFields) === null || _c === void 0 ? void 0 : _c.map(function (actionField) {
317
346
  actionField.type = "array";
318
347
  actionField.element = typeAdding(actionField.element);
@@ -324,8 +353,10 @@ exports.page = {
324
353
  if (Array.isArray(formValues.rowActions))
325
354
  formValues.actions.map(function (rowAction) {
326
355
  var _a, _b, _c;
327
- (_a = rowAction.dropdownFields) === null || _a === void 0 ? void 0 : _a.map(function (rowActionField) { return rowActionField.type = "dropdown"; });
328
- (_b = rowAction.objectFields) === null || _b === void 0 ? void 0 : _b.map(function (rowActionField) { return rowActionField = typeAdding(rowActionField); });
356
+ (_a = rowAction.dropdownFields) === null || _a === void 0 ? void 0 : _a.map(function (rowActionField) { return (rowActionField.type = "dropdown"); });
357
+ (_b = rowAction.objectFields) === null || _b === void 0 ? void 0 : _b.map(function (rowActionField) {
358
+ return (rowActionField = typeAdding(rowActionField));
359
+ });
329
360
  (_c = rowAction.arrayFields) === null || _c === void 0 ? void 0 : _c.map(function (rowActionField) {
330
361
  rowActionField.type = "array";
331
362
  rowActionField.element = typeAdding(rowActionField.element);
@@ -337,7 +368,8 @@ exports.page = {
337
368
  console.log(formValues);
338
369
  return [2 /*return*/, []];
339
370
  });
340
- }); }
341
- }],
371
+ }); },
372
+ },
373
+ ],
342
374
  rowActions: [],
343
375
  };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -4,6 +4,6 @@ exports.pages = void 0;
4
4
  var event_1 = require("../pages/event");
5
5
  var page_1 = require("../pages/page");
6
6
  exports.pages = [
7
- event_1.event,
7
+ event_1.event, // example schema
8
8
  page_1.page,
9
9
  ];
@@ -2,6 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pageToUrl = void 0;
4
4
  function pageToUrl(page) {
5
- return "/".concat(page.name.toLowerCase().replace(" ", "_"));
5
+ return "".concat(page.name.toLowerCase().replace(" ", "_"));
6
6
  }
7
7
  exports.pageToUrl = pageToUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "admin_lsac",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "Generic Admin Panel created for storing events' data",
5
5
  "private": false,
6
6
  "dependencies": {
@@ -66,7 +66,7 @@
66
66
  "ts-loader": "^9.5.1",
67
67
  "webpack-cli": "^5.1.4"
68
68
  },
69
- "main": "dist/App.js",
70
- "module": "dist/esm/App.js",
69
+ "main": "dist/components/Page.js",
70
+ "module": "dist/esm/components/Page.js",
71
71
  "types": "dist/App.d.ts"
72
72
  }
package/src/App.tsx CHANGED
@@ -1,97 +1,110 @@
1
- import { ChakraProvider } from "@chakra-ui/react";
2
- import { BrowserRouter, Route, Routes } from "react-router-dom";
3
- import { Page } from "./components/Page";
4
- import { pageToUrl } from "./schema/schema";
5
- import * as React from "react";
6
- import { page } from "./pages/page";
7
-
8
- interface TableField {
9
- name: string;
10
- access: (obj: any) => string | number | React.ReactElement;
11
- }
12
-
13
- interface SimpleField {
14
- name: string;
15
- label: string;
16
- type: "string" | "number" | "file";
17
- validationSchema: any;
18
- }
19
-
20
- interface Option {
21
- value: string | number | boolean;
22
- display: string;
23
- }
24
-
25
- interface DropdownField {
26
- name: string;
27
- label: string;
28
- type: "dropdown";
29
- options?: Option[] | undefined;
30
- getOptions: () => Promise<Option[]>;
31
- }
32
-
33
- interface ObjectField {
34
- name: string;
35
- label: string;
36
- type: "object";
37
- fields: FormField[];
38
- }
39
-
40
- interface ArrayField {
41
- name: string;
42
- label: string;
43
- type: "array";
44
- element: Exclude<FormField, ArrayField>;
45
- }
46
-
47
- type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
48
-
49
- interface Action {
50
- name: string;
51
- fields?: FormField[];
52
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
53
- }
54
-
55
- interface RowAction {
56
- name: string;
57
- fields?: FormField[];
58
- initialise?: (obj: any) => any;
59
- onSubmit: (obj1: any, obj2?: any) => Promise<any>;
60
- }
61
-
62
- interface PageSchema {
63
- name: string;
64
- actions: Action[];
65
- rowActions: RowAction[];
66
- getRequest: () => Promise<any[]>;
67
- tableFields: TableField[];
68
- }
69
-
70
- function AdminPanel({ pages, basePath }: { pages: PageSchema[], basePath: string }) {
71
- const [pagesToDisplay, setPagesToDisplay] = React.useState(pages);
72
-
73
- React.useEffect(() => {
74
- setPagesToDisplay([...pages, page]);
75
- }, [])
76
-
77
- return (
78
- <ChakraProvider>
79
- <Routes>
80
- {pagesToDisplay.map((page) => (
81
- <Route
82
- path={`${basePath}/${pageToUrl(page)}`}
83
- element={<Page pages={pagesToDisplay} selectedPage={page} basePath={basePath} />}
84
- />
85
- ))}
86
- {pages[0] ?
87
- <Route
88
- path={`${basePath}/*`}
89
- element={<Page pages={pagesToDisplay} selectedPage={pages[0]} basePath={basePath} />}
90
- />
91
- : null}
92
- </Routes>
93
- </ChakraProvider>
94
- );
95
- }
96
-
97
- export default AdminPanel;
1
+ import { ChakraProvider } from "@chakra-ui/react";
2
+ import { BrowserRouter, Route, Routes } from "react-router-dom";
3
+ import { AdminPage } from "./components/Page";
4
+ import { pageToUrl } from "./schema/schema";
5
+ import * as React from "react";
6
+
7
+ interface TableField {
8
+ name: string;
9
+ access: (obj: any) => string | number | React.ReactElement;
10
+ }
11
+
12
+ interface SimpleField {
13
+ name: string;
14
+ label: string;
15
+ type: "string" | "number" | "file";
16
+ validationSchema: any;
17
+ }
18
+
19
+ interface Option {
20
+ value: string | number | boolean;
21
+ display: string;
22
+ }
23
+
24
+ interface DropdownField {
25
+ name: string;
26
+ label: string;
27
+ type: "dropdown";
28
+ options?: Option[] | undefined;
29
+ getOptions: () => Promise<Option[]>;
30
+ }
31
+
32
+ interface ObjectField {
33
+ name: string;
34
+ label: string;
35
+ type: "object";
36
+ fields: FormField[];
37
+ }
38
+
39
+ interface ArrayField {
40
+ name: string;
41
+ label: string;
42
+ type: "array";
43
+ element: Exclude<FormField, ArrayField>;
44
+ }
45
+
46
+ type FormField = SimpleField | DropdownField | ObjectField | ArrayField;
47
+
48
+ interface Action {
49
+ name: string;
50
+ fields?: FormField[];
51
+ onSubmit: (obj1: any, obj2?: any) => Promise<any>;
52
+ }
53
+
54
+ interface RowAction {
55
+ name: string;
56
+ fields?: FormField[];
57
+ initialise?: (obj: any) => any;
58
+ onSubmit: (obj1: any, obj2?: any) => Promise<any>;
59
+ }
60
+
61
+ interface PageSchema {
62
+ name: string;
63
+ actions: Action[];
64
+ rowActions: RowAction[];
65
+ getRequest: () => Promise<any[]>;
66
+ tableFields: TableField[];
67
+ }
68
+
69
+ function AdminPanel({
70
+ pages,
71
+ basePath,
72
+ }: {
73
+ pages: PageSchema[];
74
+ basePath: string;
75
+ }) {
76
+ return (
77
+ <ChakraProvider>
78
+ <BrowserRouter>
79
+ <Routes>
80
+ {pages.map((page) => (
81
+ <Route
82
+ path={`${basePath}/${pageToUrl(page)}`}
83
+ element={
84
+ <AdminPage
85
+ pages={pages}
86
+ selectedPage={page}
87
+ basePath={basePath}
88
+ />
89
+ }
90
+ />
91
+ ))}
92
+ {pages[0] ? (
93
+ <Route
94
+ path={`${basePath}/*`}
95
+ element={
96
+ <AdminPage
97
+ pages={pages}
98
+ selectedPage={pages[0]}
99
+ basePath={basePath}
100
+ />
101
+ }
102
+ />
103
+ ) : null}
104
+ </Routes>
105
+ </BrowserRouter>
106
+ </ChakraProvider>
107
+ );
108
+ }
109
+
110
+ export default AdminPanel;