admin_lsac 1.2.3 → 1.2.5

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
  ];
@@ -12,7 +12,11 @@ var __assign = (this && this.__assign) || function () {
12
12
  };
13
13
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
14
  if (k2 === undefined) k2 = k;
15
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
16
20
  }) : (function(o, m, k, k2) {
17
21
  if (k2 === undefined) k2 = k;
18
22
  o[k2] = m[k];
@@ -44,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
44
48
  function verb(n) { return function (v) { return step([n, v]); }; }
45
49
  function step(op) {
46
50
  if (f) throw new TypeError("Generator is already executing.");
47
- while (_) try {
51
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
48
52
  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;
49
53
  if (y = 0, t) op = [op[0] & 2, t.value];
50
54
  switch (op[0]) {
@@ -107,15 +111,15 @@ function parseValidation(fields) {
107
111
  }, {});
108
112
  }
109
113
  function generateSingleField(formfield, fieldName, key) {
110
- return ((0, jsx_runtime_1.jsx)(formik_1.Field, __assign({ name: fieldName }, { children: function (_a) {
114
+ return ((0, jsx_runtime_1.jsx)(formik_1.Field, { name: fieldName, children: function (_a) {
111
115
  var _b;
112
116
  var field = _a.field, form = _a.form;
113
- return ((0, jsx_runtime_1.jsxs)(react_1.FormControl, __assign({ isInvalid: (0, formik_1.getIn)(form.touched, fieldName) && (0, formik_1.getIn)(form.errors, fieldName) }, { children: [(0, jsx_runtime_1.jsx)(react_1.FormLabel, __assign({ marginTop: 2 }, { children: formfield.label }), void 0), formfield.type === "string" || formfield.type === "number" ? ((0, jsx_runtime_1.jsx)(react_1.Input, __assign({}, field, { type: formfield.type === "number" ? "number" : "text", placeholder: "" }), void 0)) : formfield.type === "file" ? ((0, jsx_runtime_1.jsx)(react_1.Input, { type: "file", name: fieldName, onChange: function (event) {
117
+ return ((0, jsx_runtime_1.jsxs)(react_1.FormControl, { isInvalid: (0, formik_1.getIn)(form.touched, fieldName) && (0, formik_1.getIn)(form.errors, fieldName), children: [(0, jsx_runtime_1.jsx)(react_1.FormLabel, { marginTop: 2, children: formfield.label }), formfield.type === "string" || formfield.type === "number" ? ((0, jsx_runtime_1.jsx)(react_1.Input, __assign({}, field, { type: formfield.type === "number" ? "number" : "text", placeholder: "" }))) : formfield.type === "file" ? ((0, jsx_runtime_1.jsx)(react_1.Input, { type: "file", name: fieldName, onChange: function (event) {
114
118
  if (event.currentTarget.files != null) {
115
119
  form.setFieldValue(fieldName, event.currentTarget.files[0]);
116
120
  }
117
- } }, void 0)) : ((0, jsx_runtime_1.jsxs)(react_1.Select, __assign({}, field, { defaultValue: "" }, { children: [(0, jsx_runtime_1.jsx)("option", __assign({ disabled: true, value: "" }, { children: "Select an option!" }), void 0), (_b = formfield.options) === null || _b === void 0 ? void 0 : _b.map(function (option, key) { return ((0, jsx_runtime_1.jsx)("option", __assign({ value: "".concat(option.value) }, { children: option.display }), key)); })] }), void 0)), (0, jsx_runtime_1.jsx)(react_1.FormErrorMessage, { children: (0, formik_1.getIn)(form.errors, fieldName) }, void 0)] }), void 0));
118
- } }), key));
121
+ } })) : ((0, jsx_runtime_1.jsxs)(react_1.Select, __assign({}, field, { defaultValue: "", children: [(0, jsx_runtime_1.jsx)("option", { disabled: true, value: "", children: "Select an option!" }), (_b = formfield.options) === null || _b === void 0 ? void 0 : _b.map(function (option, key) { return ((0, jsx_runtime_1.jsx)("option", { value: "".concat(option.value), children: option.display }, key)); })] }))), (0, jsx_runtime_1.jsx)(react_1.FormErrorMessage, { children: (0, formik_1.getIn)(form.errors, fieldName) })] }));
122
+ } }, key));
119
123
  }
120
124
  function parseFields(fields, previous) {
121
125
  if (!fields) {
@@ -128,12 +132,12 @@ function parseFields(fields, previous) {
128
132
  return (0, jsx_runtime_1.jsx)(react_1.FormControl, { children: objectFields }, fieldName);
129
133
  }
130
134
  else if (formfield.type === "array") {
131
- return ((0, jsx_runtime_1.jsx)(formik_1.FieldArray, __assign({ name: fieldName }, { children: function (_a) {
135
+ return ((0, jsx_runtime_1.jsx)(formik_1.FieldArray, { name: fieldName, children: function (_a) {
132
136
  var remove = _a.remove, push = _a.push, form = _a.form;
133
- return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(react_1.FormLabel, __assign({ marginTop: 2 }, { children: formfield.label }), void 0), (0, formik_1.getIn)(form.values, fieldName).length > 0 &&
134
- (0, formik_1.getIn)(form.values, fieldName).map(function (element, index) { return ((0, jsx_runtime_1.jsxs)(react_1.Box, __assign({ paddingLeft: 10 }, { children: [(0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("b", { children: "".concat(fieldName, ".").concat(index) }, void 0) }, void 0), (0, jsx_runtime_1.jsx)(react_1.Box, __assign({ paddingLeft: 10 }, { children: formfield.element.type === "object"
137
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(react_1.FormLabel, { marginTop: 2, children: formfield.label }), (0, formik_1.getIn)(form.values, fieldName).length > 0 &&
138
+ (0, formik_1.getIn)(form.values, fieldName).map(function (element, index) { return ((0, jsx_runtime_1.jsxs)(react_1.Box, { paddingLeft: 10, children: [(0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("b", { children: "".concat(fieldName, ".").concat(index) }) }), (0, jsx_runtime_1.jsx)(react_1.Box, { paddingLeft: 10, children: formfield.element.type === "object"
135
139
  ? parseFields(formfield.element.fields, "".concat(fieldName, ".").concat(index))
136
- : generateSingleField(formfield.element, "".concat(fieldName, ".").concat(index), key) }), void 0), (0, jsx_runtime_1.jsxs)(react_1.Button, __assign({ type: "button", colorScheme: "red", marginY: 2, onClick: function () { return remove(index); } }, { children: ["Remove ", "".concat(fieldName, ".").concat(index)] }), void 0)] }), void 0)); }), (0, jsx_runtime_1.jsxs)(react_1.Button, __assign({ type: "button", marginY: 2, colorScheme: "blue", onClick: function () {
140
+ : generateSingleField(formfield.element, "".concat(fieldName, ".").concat(index), key) }), (0, jsx_runtime_1.jsxs)(react_1.Button, { type: "button", colorScheme: "red", marginY: 2, onClick: function () { return remove(index); }, children: ["Remove ", "".concat(fieldName, ".").concat(index)] })] })); }), (0, jsx_runtime_1.jsxs)(react_1.Button, { type: "button", marginY: 2, colorScheme: "blue", onClick: function () {
137
141
  var value = undefined;
138
142
  if (formfield.element.type === "object") {
139
143
  value = getInitialValues(formfield.element.fields);
@@ -142,8 +146,8 @@ function parseFields(fields, previous) {
142
146
  value = getInitialValues([formfield.element])[0];
143
147
  }
144
148
  push(value);
145
- } }, { children: ["Add ", fieldName] }), void 0)] }, void 0));
146
- } }), void 0));
149
+ }, children: ["Add ", fieldName] })] }));
150
+ } }));
147
151
  }
148
152
  else {
149
153
  return generateSingleField(formfield, fieldName, key);
@@ -227,8 +231,8 @@ function GenericForm(_a) {
227
231
  });
228
232
  }, []);
229
233
  if (!action.fields)
230
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}, void 0);
231
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(formik_1.Formik, __assign({ initialValues: initialValues, validationSchema: Yup.object(validationSchema), onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
234
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
235
+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(formik_1.Formik, { initialValues: initialValues, validationSchema: Yup.object(validationSchema), onSubmit: function (values) { return __awaiter(_this, void 0, void 0, function () {
232
236
  var res, e_1, err;
233
237
  return __generator(this, function (_a) {
234
238
  switch (_a.label) {
@@ -261,9 +265,9 @@ function GenericForm(_a) {
261
265
  case 6: return [2 /*return*/];
262
266
  }
263
267
  });
264
- }); } }, { children: function (_a) {
268
+ }); }, children: function (_a) {
265
269
  var isSubmitting = _a.isSubmitting;
266
- return ((0, jsx_runtime_1.jsxs)(formik_1.Form, { children: [formFields, (0, jsx_runtime_1.jsx)(react_1.Button, __assign({ mt: 4, colorScheme: "teal", isLoading: isSubmitting, type: "submit" }, { children: "Submit" }), void 0)] }, void 0));
267
- } }), void 0) }, void 0));
270
+ return ((0, jsx_runtime_1.jsxs)(formik_1.Form, { children: [formFields, (0, jsx_runtime_1.jsx)(react_1.Button, { mt: 4, colorScheme: "teal", isLoading: isSubmitting, type: "submit", children: "Submit" })] }));
271
+ } }) }));
268
272
  }
269
273
  exports.GenericForm = GenericForm;
@@ -1,27 +1,15 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
16
5
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Page = void 0;
6
+ exports.AdminPage = void 0;
18
7
  var jsx_runtime_1 = require("react/jsx-runtime");
19
8
  var react_1 = require("react");
20
9
  var react_2 = require("@chakra-ui/react");
21
10
  var schema_1 = require("../schema/schema");
22
11
  var react_3 = require("@chakra-ui/react");
23
12
  var GenericForm_1 = require("./GenericForm");
24
- var react_router_1 = require("react-router");
25
13
  var react_4 = require("@emotion/react");
26
14
  var styles_1 = require("@mui/material/styles");
27
15
  var material_react_table_1 = require("material-react-table");
@@ -30,20 +18,27 @@ var sweetalert2_1 = __importDefault(require("sweetalert2"));
30
18
  var MenuItem_1 = __importDefault(require("@mui/material/MenuItem"));
31
19
  function Header(_a) {
32
20
  var pages = _a.pages, data = _a.data, basePath = _a.basePath;
33
- var nav = (0, react_router_1.useNavigate)();
34
- return ((0, jsx_runtime_1.jsx)(react_3.Box, __assign({ background: "blue.50", padding: 1 }, { children: (0, jsx_runtime_1.jsxs)(react_3.Stack, __assign({ margin: 3, direction: "row", justifyContent: "space-between", alignItems: "center" }, { children: [(0, jsx_runtime_1.jsx)(react_3.Stack, __assign({ margin: 4, gap: 10, direction: "row", alignItems: "center" }, { children: pages.map(function (p) { return ((0, jsx_runtime_1.jsx)(react_3.Box, __assign({ as: "a", href: "".concat(basePath, "/").concat((0, schema_1.pageToUrl)(p)) }, { children: p.name }), void 0)); }) }), void 0), (0, jsx_runtime_1.jsx)(react_3.Stack, __assign({ direction: "row" }, { children: (0, jsx_runtime_1.jsx)(react_3.Button, __assign({ colorScheme: "red", onClick: function () {
21
+ return ((0, jsx_runtime_1.jsx)(react_3.Box, { background: "blue.50", padding: 1, children: (0, jsx_runtime_1.jsxs)(react_3.Stack, { margin: 3, direction: "row", justifyContent: "space-between", alignItems: "center", children: [(0, jsx_runtime_1.jsx)(react_3.Stack, { margin: 4, gap: 10, direction: "row", alignItems: "center", children: pages.map(function (p) { return ((0, jsx_runtime_1.jsx)(react_3.Box, { as: "a", href: "".concat(basePath, "/").concat((0, schema_1.pageToUrl)(p)), children: p.name })); }) }), (0, jsx_runtime_1.jsx)(react_3.Stack, { direction: "row", children: (0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "red", onClick: function () {
35
22
  var filename = prompt("Enter filename:");
36
23
  if (filename)
37
24
  exportToCSV(data, filename);
38
- } }, { children: "Export Data" }), void 0) }), void 0)] }), void 0) }), void 0));
25
+ }, children: "Export Data" }) })] }) }));
39
26
  }
40
27
  function exportToCSV(data, filename) {
41
28
  var formatImageData = function (obj) {
42
29
  var formattedObj = {};
43
- for (var key in obj) {
30
+ var _loop_1 = function (key) {
44
31
  if (typeof obj[key] !== "object") {
45
32
  formattedObj[key] = obj[key];
46
33
  }
34
+ else if (typeof obj[key] === "object" && obj[key] != null) {
35
+ Object.keys(obj[key]).forEach(function (k) {
36
+ formattedObj["".concat(key, ".").concat(k)] = obj[key][k];
37
+ });
38
+ }
39
+ };
40
+ for (var key in obj) {
41
+ _loop_1(key);
47
42
  }
48
43
  return formattedObj;
49
44
  };
@@ -63,7 +58,7 @@ function exportToCSV(data, filename) {
63
58
  });
64
59
  }
65
60
  }
66
- function Page(_a) {
61
+ function AdminPage(_a) {
67
62
  var _b;
68
63
  var pages = _a.pages, selectedPage = _a.selectedPage, basePath = _a.basePath;
69
64
  var _c = (0, react_3.useDisclosure)(), isOpen = _c.isOpen, onOpen = _c.onOpen, onClose = _c.onClose;
@@ -81,14 +76,14 @@ function Page(_a) {
81
76
  return selectedPage.tableFields.map(function (field) { return field.access(table_data); });
82
77
  }));
83
78
  }, [data]);
84
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { pages: pages, data: data, basePath: basePath }, void 0), (0, jsx_runtime_1.jsx)(react_4.ThemeProvider, __assign({ theme: (0, styles_1.createTheme)() }, { children: (0, jsx_runtime_1.jsx)(material_react_table_1.MaterialReactTable, { columns: selectedPage.tableFields.map(function (field, index) { return ({
79
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Header, { pages: pages, data: data, basePath: basePath }), (0, jsx_runtime_1.jsx)(react_4.ThemeProvider, { theme: (0, styles_1.createTheme)(), children: (0, jsx_runtime_1.jsx)(material_react_table_1.MaterialReactTable, { columns: selectedPage.tableFields.map(function (field, index) { return ({
85
80
  accessorFn: function (row) { return row[index]; },
86
81
  header: field.name,
87
- }); }), data: displayData, muiTableContainerProps: { sx: { maxHeight: "70vh" } }, enableColumnResizing: true, enableColumnPinning: true, enableGlobalFilterModes: true, enablePagination: true, paginationDisplayMode: "pages", enableRowVirtualization: true, rowVirtualizerOptions: { overscan: 20 }, renderTopToolbarCustomActions: function () { return ((0, jsx_runtime_1.jsx)(react_2.ChakraProvider, { children: (0, jsx_runtime_1.jsx)(react_3.Stack, __assign({ margin: 0, padding: 3, direction: "row" }, { children: selectedPage.actions.map(function (action) { return ((0, jsx_runtime_1.jsx)(react_3.Button, __assign({ colorScheme: "blue", onClick: function () {
82
+ }); }), data: displayData, muiTableContainerProps: { sx: { maxHeight: "70vh" } }, enableColumnResizing: true, enableColumnPinning: true, enableGlobalFilterModes: true, enablePagination: true, paginationDisplayMode: "pages", enableRowVirtualization: true, rowVirtualizerOptions: { overscan: 20 }, renderTopToolbarCustomActions: function () { return ((0, jsx_runtime_1.jsx)(react_2.ChakraProvider, { children: (0, jsx_runtime_1.jsx)(react_3.Stack, { margin: 0, padding: 3, direction: "row", children: selectedPage.actions.map(function (action) { return ((0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "blue", onClick: function () {
88
83
  setSelectedAction(action);
89
84
  onOpen();
90
- } }, { children: action.name }), void 0)); }) }), void 0) }, void 0)); }, enableRowActions: true, renderRowActionMenuItems: function (obj) {
91
- return selectedPage.rowActions.map(function (rowAction) { return ((0, jsx_runtime_1.jsx)(MenuItem_1.default, __assign({ onClick: function () {
85
+ }, children: action.name })); }) }) })); }, enableRowActions: true, renderRowActionMenuItems: function (obj) {
86
+ return selectedPage.rowActions.map(function (rowAction) { return ((0, jsx_runtime_1.jsx)(MenuItem_1.default, { onClick: function () {
92
87
  setSelectedAction(rowAction);
93
88
  setRowId(obj.row.original[0]);
94
89
  onOpen();
@@ -96,11 +91,11 @@ function Page(_a) {
96
91
  if (rowActionsMenu) {
97
92
  rowActionsMenu.remove();
98
93
  }
99
- } }, { children: rowAction.name + " " + obj.row.original[0] }), void 0)); });
100
- } }, void 0) }), void 0), (0, jsx_runtime_1.jsxs)(react_3.Modal, __assign({ size: "6xl", isOpen: isOpen, onClose: onClose }, { children: [(0, jsx_runtime_1.jsx)(react_3.ModalOverlay, {}, void 0), (0, jsx_runtime_1.jsxs)(react_3.ModalContent, { children: [(0, jsx_runtime_1.jsx)(react_3.ModalHeader, { children: selectedAction.name }, void 0), (0, jsx_runtime_1.jsx)(react_3.ModalCloseButton, {}, void 0), (0, jsx_runtime_1.jsxs)(react_3.ModalBody, { children: [selectedAction.fields && ((_b = selectedAction.fields) === null || _b === void 0 ? void 0 : _b.length) > 0 ? ((0, jsx_runtime_1.jsx)(GenericForm_1.GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId }, void 0)) : ((0, jsx_runtime_1.jsx)(react_3.Button, __assign({ colorScheme: "blue", mr: 3, onClick: function () {
94
+ }, children: rowAction.name + " " + obj.row.original[0] })); });
95
+ } }) }), (0, jsx_runtime_1.jsxs)(react_3.Modal, { size: "6xl", isOpen: isOpen, onClose: onClose, children: [(0, jsx_runtime_1.jsx)(react_3.ModalOverlay, {}), (0, jsx_runtime_1.jsxs)(react_3.ModalContent, { children: [(0, jsx_runtime_1.jsx)(react_3.ModalHeader, { children: selectedAction.name }), (0, jsx_runtime_1.jsx)(react_3.ModalCloseButton, {}), (0, jsx_runtime_1.jsxs)(react_3.ModalBody, { children: [selectedAction.fields && ((_b = selectedAction.fields) === null || _b === void 0 ? void 0 : _b.length) > 0 ? ((0, jsx_runtime_1.jsx)(GenericForm_1.GenericForm, { action: selectedAction, onClose: onClose, rowId: rowId })) : ((0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "blue", mr: 3, onClick: function () {
101
96
  selectedAction.onSubmit(rowId);
102
97
  onClose();
103
98
  window.location.reload();
104
- } }, { children: "Confirm Action" }), void 0)), (0, jsx_runtime_1.jsx)(react_3.Button, __assign({ colorScheme: "red", mr: 3, onClick: onClose }, { children: "Close" }), void 0)] }, void 0)] }, void 0)] }), void 0)] }, void 0));
99
+ }, children: "Confirm Action" })), (0, jsx_runtime_1.jsx)(react_3.Button, { colorScheme: "red", mr: 3, onClick: onClose, children: "Close" })] })] })] })] }));
105
100
  }
106
- exports.Page = Page;
101
+ exports.AdminPage = AdminPage;
package/dist/esm/App.js CHANGED
@@ -1,27 +1,10 @@
1
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
2
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
3
- if (ar || !(i in from)) {
4
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
5
- ar[i] = from[i];
6
- }
7
- }
8
- return to.concat(ar || Array.prototype.slice.call(from));
9
- };
10
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
2
  import { ChakraProvider } from "@chakra-ui/react";
12
- import { Route, Routes } from "react-router-dom";
13
- import { Page } from "./components/Page";
3
+ import { BrowserRouter, Route, Routes } from "react-router-dom";
4
+ import { AdminPage } from "./components/Page";
14
5
  import { pageToUrl } from "./schema/schema";
15
- import * as React from "react";
16
- import { page } from "./pages/page";
17
6
  function AdminPanel(_a) {
18
7
  var pages = _a.pages, basePath = _a.basePath;
19
- var _b = React.useState(pages), pagesToDisplay = _b[0], setPagesToDisplay = _b[1];
20
- React.useEffect(function () {
21
- setPagesToDisplay(__spreadArray(__spreadArray([], pages, true), [page], false));
22
- }, []);
23
- return (_jsx(ChakraProvider, { children: _jsxs(Routes, { children: [pagesToDisplay.map(function (page) { return (_jsx(Route, { path: "".concat(basePath, "/").concat(pageToUrl(page)), element: _jsx(Page, { pages: pagesToDisplay, selectedPage: page, basePath: basePath }, void 0) }, void 0)); }), pages[0] ?
24
- _jsx(Route, { path: "".concat(basePath, "/*"), element: _jsx(Page, { pages: pagesToDisplay, selectedPage: pages[0], basePath: basePath }, void 0) }, void 0)
25
- : null] }, void 0) }, void 0));
8
+ return (_jsx(ChakraProvider, { children: _jsx(BrowserRouter, { children: _jsxs(Routes, { children: [pages.map(function (page) { return (_jsx(Route, { path: "".concat(basePath, "/").concat(pageToUrl(page)), element: _jsx(AdminPage, { pages: pages, selectedPage: page, basePath: basePath }) })); }), pages[0] ? (_jsx(Route, { path: "".concat(basePath, "/*"), element: _jsx(AdminPage, { pages: pages, selectedPage: pages[0], basePath: basePath }) })) : null] }) }) }));
26
9
  }
27
10
  export default AdminPanel;