drf-react-by-schema 0.3.0 → 0.4.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.
Files changed (88) hide show
  1. package/dist/api.d.ts +83 -0
  2. package/dist/api.js +613 -0
  3. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +24 -0
  4. package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +42 -0
  5. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +8 -0
  6. package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +21 -0
  7. package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +17 -0
  8. package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +77 -0
  9. package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +17 -0
  10. package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +41 -0
  11. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +9 -0
  12. package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +32 -0
  13. package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +9 -0
  14. package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +30 -0
  15. package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +4 -0
  16. package/dist/components/DataGridBySchemaEditable/InputInterval.js +105 -0
  17. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +33 -0
  18. package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +140 -0
  19. package/dist/components/DataGridBySchemaEditable/utils.d.ts +15 -0
  20. package/{src/components/DataGridBySchemaEditable/utils.ts → dist/components/DataGridBySchemaEditable/utils.js} +32 -50
  21. package/dist/components/DataGridBySchemaEditable.d.ts +34 -0
  22. package/dist/components/DataGridBySchemaEditable.js +565 -0
  23. package/dist/components/DataTotals.d.ts +15 -0
  24. package/dist/components/DataTotals.js +23 -0
  25. package/dist/components/DialogActions.d.ts +10 -0
  26. package/dist/components/DialogActions.js +17 -0
  27. package/dist/components/DialogJSONSchemaForm.d.ts +13 -0
  28. package/dist/components/DialogJSONSchemaForm.js +20 -0
  29. package/dist/components/FormButtons.d.ts +21 -0
  30. package/dist/components/FormButtons.js +43 -0
  31. package/dist/components/GenericModelList.d.ts +19 -0
  32. package/dist/components/GenericModelList.js +113 -0
  33. package/dist/components/GenericRelatedModelList.d.ts +25 -0
  34. package/dist/components/GenericRelatedModelList.js +111 -0
  35. package/dist/components/TextFieldBySchema.js +39 -0
  36. package/dist/context/APIWrapper.d.ts +12 -0
  37. package/dist/context/APIWrapper.js +341 -0
  38. package/{src/context/APIWrapperContext.tsx → dist/context/APIWrapperContext.d.ts} +22 -31
  39. package/dist/context/APIWrapperContext.js +15 -0
  40. package/{src/context/DRFReactBySchemaContext.tsx → dist/context/DRFReactBySchemaContext.d.ts} +4 -17
  41. package/dist/context/DRFReactBySchemaContext.js +19 -0
  42. package/dist/context/DRFReactBySchemaProvider.d.ts +13 -0
  43. package/dist/context/DRFReactBySchemaProvider.js +53 -0
  44. package/dist/context/Form.d.ts +21 -0
  45. package/dist/context/Form.js +99 -0
  46. package/dist/context/FormContext.d.ts +72 -0
  47. package/dist/context/FormContext.js +15 -0
  48. package/dist/context/Overlays.d.ts +4 -0
  49. package/dist/context/Overlays.js +87 -0
  50. package/dist/index.d.ts +12 -0
  51. package/dist/index.js +3 -1
  52. package/{src/styles/index.ts → dist/styles/index.d.ts} +0 -1
  53. package/dist/styles/index.js +28 -0
  54. package/dist/styles/layout.d.ts +107 -0
  55. package/dist/styles/layout.js +56 -0
  56. package/dist/styles/theme.d.ts +21 -0
  57. package/dist/styles/theme.js +139 -0
  58. package/dist/utils.d.ts +74 -0
  59. package/dist/utils.js +268 -0
  60. package/package.json +11 -2
  61. package/.eslintrc.js +0 -14
  62. package/.gitlab-ci.yml +0 -14
  63. package/src/api.ts +0 -727
  64. package/src/components/DataGridBySchemaEditable/ConfirmDialog.tsx +0 -41
  65. package/src/components/DataGridBySchemaEditable/CustomToolbar.tsx +0 -93
  66. package/src/components/DataGridBySchemaEditable/FooterToolbar.tsx +0 -77
  67. package/src/components/DataGridBySchemaEditable/GridDecimalInput.tsx +0 -41
  68. package/src/components/DataGridBySchemaEditable/GridPatternInput.tsx +0 -37
  69. package/src/components/DataGridBySchemaEditable/InputInterval.tsx +0 -194
  70. package/src/components/DataGridBySchemaEditable/SelectEditInputCell.tsx +0 -154
  71. package/src/components/DataGridBySchemaEditable.md +0 -50
  72. package/src/components/DataGridBySchemaEditable.tsx +0 -758
  73. package/src/components/DataTotals.tsx +0 -57
  74. package/src/components/DialogActions.tsx +0 -33
  75. package/src/components/DialogJSONSchemaForm.tsx +0 -40
  76. package/src/components/GenericModelList.tsx +0 -165
  77. package/src/components/GenericRelatedModelList.tsx +0 -168
  78. package/src/context/APIWrapper.tsx +0 -447
  79. package/src/context/DRFReactBySchemaProvider.md +0 -57
  80. package/src/context/DRFReactBySchemaProvider.tsx +0 -72
  81. package/src/context/Overlays.tsx +0 -94
  82. package/src/index.ts +0 -77
  83. package/src/styles/layout.ts +0 -104
  84. package/src/styles/theme.ts +0 -190
  85. package/src/utils.ts +0 -327
  86. package/styleguide.config.js +0 -13
  87. package/tsconfig.json +0 -104
  88. package/webpack.config.js +0 -24
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = 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);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __rest = (this && this.__rest) || function (s, e) {
35
+ var t = {};
36
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
+ t[p] = s[p];
38
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
+ t[p[i]] = s[p[i]];
42
+ }
43
+ return t;
44
+ };
45
+ var __importDefault = (this && this.__importDefault) || function (mod) {
46
+ return (mod && mod.__esModule) ? mod : { "default": mod };
47
+ };
48
+ Object.defineProperty(exports, "__esModule", { value: true });
49
+ const react_1 = __importStar(require("react"));
50
+ const utils_1 = require("../utils");
51
+ const DialogJSONSchemaForm_1 = __importDefault(require("../components/DialogJSONSchemaForm"));
52
+ const DialogActions_1 = __importDefault(require("../components/DialogActions"));
53
+ const DRFReactBySchemaContext_1 = require("./DRFReactBySchemaContext");
54
+ const api_1 = require("../api");
55
+ const APIWrapperContext_1 = require("./APIWrapperContext");
56
+ ;
57
+ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, children }) {
58
+ const { serverEndPoint } = DRFReactBySchemaContext_1.DRFReactBySchemaContext
59
+ ? react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext)
60
+ : { serverEndPoint: null };
61
+ if (!serverEndPoint) {
62
+ return (react_1.default.createElement(react_1.default.Fragment, null, children));
63
+ }
64
+ const [usuaria, setUsuaria] = (0, react_1.useState)(null);
65
+ const [optionsAC, setOptionsAC] = (0, react_1.useReducer)(utils_1.reducer, {});
66
+ const initialPageForm = {
67
+ id: '',
68
+ schema: null,
69
+ initialValues: null,
70
+ validationSchema: null
71
+ };
72
+ const [pageForm, setPageForm] = (0, react_1.useReducer)(utils_1.reducer, initialPageForm);
73
+ const editModel = (0, react_1.useRef)({});
74
+ const jsonSchemaFormRef = (0, react_1.useRef)(null);
75
+ (0, react_1.useEffect)(() => {
76
+ setUsuaria(null);
77
+ (0, api_1.isLoggedIn)(serverEndPoint).then(usuaria => {
78
+ setUsuaria(usuaria || { erro: 'token inválido' });
79
+ });
80
+ }, []);
81
+ (0, react_1.useEffect)(() => {
82
+ setPageForm(initialPageForm);
83
+ }, []);
84
+ const onTriggerSnackBar = ({ msg, severity = 'info' }) => {
85
+ setSnackBar({
86
+ open: true,
87
+ msg,
88
+ severity
89
+ });
90
+ };
91
+ const loadSinglePageData = ({ model, objId, optionsACModels, extraValidators = {} }) => __awaiter(this, void 0, void 0, function* () {
92
+ setLoading(true);
93
+ if (!objId || objId === 'novo') {
94
+ objId = (0, utils_1.getTmpId)();
95
+ }
96
+ const object = yield (0, api_1.getGenericModel)({
97
+ model,
98
+ serverEndPoint,
99
+ id: (0, utils_1.isTmpId)(objId) ? null : objId
100
+ });
101
+ if (object === false) {
102
+ setPageForm({ schema: false, id: '' });
103
+ console.log('Houve um erro ao tentar carregar os dados!');
104
+ return false;
105
+ }
106
+ setLoading(false);
107
+ populateOptionsAC(optionsACModels);
108
+ const values = populateInitialValues(Object.assign({ model, id: objId, extraValidators }, object));
109
+ return values;
110
+ });
111
+ const onSubmit = (model, id, data, event) => __awaiter(this, void 0, void 0, function* () {
112
+ setLoading(true);
113
+ const response = yield (0, api_1.updateDataBySchema)({
114
+ model,
115
+ modelObjectId: id,
116
+ serverEndPoint,
117
+ data,
118
+ schema: pageForm.schema
119
+ });
120
+ setLoading(false);
121
+ if (!['number', 'string'].includes(typeof response)) {
122
+ onTriggerSnackBar({
123
+ msg: 'Houve um problema ao salvar seus dados! Por favor, entre em contato',
124
+ severity: 'error'
125
+ });
126
+ console.log({
127
+ msg: 'Error saving model',
128
+ errors: response,
129
+ data
130
+ });
131
+ return false;
132
+ }
133
+ onTriggerSnackBar({
134
+ msg: (id)
135
+ ? 'Dados atualizados com sucesso!'
136
+ : 'Criado com sucesso!'
137
+ });
138
+ return response;
139
+ });
140
+ const populateOptionsAC = (optionsACModels) => {
141
+ for (const model of optionsACModels) {
142
+ (0, api_1.getAutoComplete)({ model, serverEndPoint }).then(options => {
143
+ setOptionsAC({ [model]: options });
144
+ });
145
+ }
146
+ };
147
+ ;
148
+ const populateInitialValues = (_a) => {
149
+ var { model, id, isEditModel, extraValidators } = _a, object = __rest(_a, ["model", "id", "isEditModel", "extraValidators"]);
150
+ const values = (0, utils_1.populateValues)(object);
151
+ const yupSchema = (0, utils_1.buildGenericYupValidationSchema)(Object.assign(Object.assign({}, object), { data: values, extraValidators }));
152
+ setPageForm({
153
+ model,
154
+ id,
155
+ schema: object.schema,
156
+ initialValues: values,
157
+ validationSchema: yupSchema
158
+ });
159
+ return values;
160
+ };
161
+ const onEditModel = ({ fieldKey, index, model, id, labelKey, setValue, getValues }) => {
162
+ setDialog({
163
+ open: true,
164
+ loading: true
165
+ });
166
+ (0, api_1.getJSONSchema)({ model, serverEndPoint, id }).then(data => {
167
+ const jsonSchemaSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
168
+ jsonSchemaFormRef.current.onSubmit(e);
169
+ return true;
170
+ });
171
+ setDialog({
172
+ loading: false,
173
+ title: 'Editar',
174
+ Body: react_1.default.createElement(DialogJSONSchemaForm_1.default, { jsonSchemaFormRef: jsonSchemaFormRef, schema: data.serializer.schema, uiSchema: data.serializer.uiSchema, formData: data.formData, onSubmit: onEditModelSave }),
175
+ Actions: react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, handleSave: jsonSchemaSubmit })
176
+ });
177
+ editModel.current = {
178
+ fieldKey,
179
+ index,
180
+ model,
181
+ id,
182
+ labelKey,
183
+ setValue,
184
+ getValues
185
+ };
186
+ });
187
+ };
188
+ const onEditModelSave = ({ formData }) => __awaiter(this, void 0, void 0, function* () {
189
+ setDialog({ open: false });
190
+ setLoading(true);
191
+ const { fieldKey, index, model, id, labelKey, setValue, getValues } = editModel.current;
192
+ const newModelId = yield (0, api_1.createOrUpdateJSONSchema)({
193
+ model,
194
+ serverEndPoint,
195
+ id,
196
+ formData
197
+ });
198
+ if (newModelId.errors) {
199
+ console.log(newModelId.errors);
200
+ onTriggerSnackBar({
201
+ msg: 'Houve um problema ao salvar a alteração! Por favor, entre em contato.',
202
+ severity: 'error'
203
+ });
204
+ return;
205
+ }
206
+ onTriggerSnackBar({
207
+ msg: 'Alterações salvas com sucesso!',
208
+ severity: 'info'
209
+ });
210
+ const targetKey = (fieldKey && index >= 0)
211
+ ? `${fieldKey}.${index}.${model}`
212
+ : model;
213
+ const newValue = Object.assign(Object.assign(Object.assign({}, getValues(targetKey)), formData), { label: formData[labelKey] });
214
+ setValue(targetKey, newValue);
215
+ populateOptionsAC([model]);
216
+ setLoading(false);
217
+ });
218
+ const onDeleteModel = (model, id, onSuccess) => {
219
+ setDialog({
220
+ open: true,
221
+ loading: false,
222
+ title: 'Apagar',
223
+ Body: 'Tem certeza de que deseja apagar este item?',
224
+ Actions: react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, handleSave: (e) => {
225
+ return onDeleteModelSave(model, id, onSuccess);
226
+ }, btnConfirm: "Sim, apagar" })
227
+ });
228
+ };
229
+ const onDeleteModelSave = (model, id, onSuccess) => __awaiter(this, void 0, void 0, function* () {
230
+ setDialog({ open: false });
231
+ setLoading(true);
232
+ const ret = yield (0, api_1.deleteData)(model, serverEndPoint, id);
233
+ if (ret !== false) {
234
+ onTriggerSnackBar({
235
+ msg: 'Apagado com com sucesso!',
236
+ severity: 'info'
237
+ });
238
+ if (onSuccess) {
239
+ onSuccess({});
240
+ }
241
+ return true;
242
+ }
243
+ setLoading(false);
244
+ onTriggerSnackBar({
245
+ msg: 'Houve um problema ao remover o item! Por favor, entre em contato.',
246
+ severity: 'error'
247
+ });
248
+ return false;
249
+ });
250
+ const onEditRelatedModelSave = ({ model, id, relatedModel, relatedModelId, newRow, schema, onlyAddExisting }) => __awaiter(this, void 0, void 0, function* () {
251
+ const updateUrl = `${model}/${id}/${relatedModel}`;
252
+ if (onlyAddExisting) {
253
+ const response = yield (0, api_1.addExistingRelatedModel)({
254
+ model,
255
+ id,
256
+ serverEndPoint,
257
+ data: {
258
+ onlyAddExisting: {
259
+ key: relatedModel,
260
+ value: newRow.id_to_add
261
+ }
262
+ }
263
+ });
264
+ if (Object.prototype.hasOwnProperty.call(response, 'errors')) {
265
+ console.log(response);
266
+ onTriggerSnackBar({
267
+ msg: 'Houve um problema ao salvar a alteração! Por favor, entre em contato.',
268
+ severity: 'error'
269
+ });
270
+ return false;
271
+ }
272
+ onTriggerSnackBar({
273
+ msg: 'Alterações salvas com sucesso!',
274
+ severity: 'info'
275
+ });
276
+ const object = yield (0, api_1.getGenericModel)({
277
+ model,
278
+ id,
279
+ serverEndPoint,
280
+ relatedModel,
281
+ relatedModelId: newRow.id_to_add
282
+ });
283
+ return object;
284
+ }
285
+ // This is important for related data
286
+ if (schema[model] && !newRow[model]) {
287
+ newRow[model] = id;
288
+ }
289
+ const response = yield (0, api_1.updateDataBySchema)({
290
+ model: relatedModel,
291
+ modelObjectId: newRow.id,
292
+ serverEndPoint,
293
+ data: newRow,
294
+ schema,
295
+ path: updateUrl
296
+ });
297
+ if (response && !Object.prototype.hasOwnProperty.call(response, 'errors')) {
298
+ onTriggerSnackBar({
299
+ msg: 'Alterações salvas com sucesso!',
300
+ severity: 'info'
301
+ });
302
+ return response;
303
+ }
304
+ onTriggerSnackBar({
305
+ msg: 'Não foi possível salvar os dados. Confira os erros.',
306
+ severity: 'error'
307
+ });
308
+ return false;
309
+ });
310
+ const onDeleteRelatedModel = ({ model, id, relatedModel, relatedModelId }) => __awaiter(this, void 0, void 0, function* () {
311
+ const deleteUrl = `${model}/${id}/${relatedModel}`;
312
+ const response = yield (0, api_1.deleteData)(deleteUrl, serverEndPoint, relatedModelId);
313
+ if (response) {
314
+ onTriggerSnackBar({
315
+ msg: 'Alterações salvas com sucesso!',
316
+ severity: 'info'
317
+ });
318
+ return response;
319
+ }
320
+ onTriggerSnackBar({
321
+ msg: 'Houve um problema ao remover o item! Por favor, entre em contato.',
322
+ severity: 'error'
323
+ });
324
+ return false;
325
+ });
326
+ return (react_1.default.createElement(APIWrapperContext_1.APIWrapperContext.Provider, { value: {
327
+ usuaria,
328
+ onSubmit,
329
+ loadSinglePageData,
330
+ handleLoading,
331
+ optionsACState: [optionsAC, setOptionsAC],
332
+ pageFormState: [pageForm, setPageForm],
333
+ onEditModel,
334
+ onDeleteModel,
335
+ onEditRelatedModelSave,
336
+ onDeleteRelatedModel,
337
+ onTriggerSnackBar,
338
+ setDialog
339
+ } }, children));
340
+ }
341
+ exports.default = react_1.default.memo(APIWrapper);
@@ -1,30 +1,22 @@
1
1
  import React from 'react';
2
+ import { FieldValues, SubmitHandler } from 'react-hook-form';
2
3
  import { ItemSchemaColumnsType, Id, Item, SchemaType } from '../utils';
3
-
4
4
  export interface LoadSinglePageDataProps {
5
5
  model: string;
6
- objId: Id;
6
+ objId?: Id;
7
7
  objTitleField?: string;
8
8
  optionsACModels: string[];
9
9
  basePath?: string;
10
10
  formPath?: string | null;
11
- extraValidators: Item;
12
- };
13
-
14
- // export interface LoadingStateType {
15
- // loading: boolean,
16
- // setLoading: React.Dispatch<React.SetStateAction<boolean>>;
17
- // };
18
-
11
+ extraValidators?: Item;
12
+ }
19
13
  export type OptionsACType = Record<string, Item[]>;
20
-
21
14
  export interface PageFormType {
22
15
  id: Id;
23
16
  schema: SchemaType | null;
24
17
  initialValues: Item | null;
25
18
  validationSchema: Item | null;
26
- };
27
-
19
+ }
28
20
  export interface OnEditModelType {
29
21
  fieldKey: string;
30
22
  index: string;
@@ -33,8 +25,7 @@ export interface OnEditModelType {
33
25
  labelKey: string;
34
26
  setValue: (p: any) => void;
35
27
  getValues: (p: any) => any;
36
- };
37
-
28
+ }
38
29
  export interface OnEditRelatedModelType {
39
30
  model: string;
40
31
  id: Id;
@@ -43,21 +34,18 @@ export interface OnEditRelatedModelType {
43
34
  newRow: Item;
44
35
  schema: SchemaType;
45
36
  onlyAddExisting: boolean;
46
- };
47
-
37
+ }
48
38
  export interface OnDeleteRelatedModelType {
49
39
  model: string;
50
40
  id: Id;
51
41
  relatedModel: string;
52
42
  relatedModelId: Id;
53
- };
54
-
43
+ }
55
44
  export interface SnackBarType {
56
45
  open?: boolean;
57
46
  msg?: string;
58
- severity?: string
59
- };
60
-
47
+ severity?: string;
48
+ }
61
49
  export interface DialogType {
62
50
  open: boolean;
63
51
  loading?: boolean;
@@ -65,20 +53,23 @@ export interface DialogType {
65
53
  Body?: React.ReactNode;
66
54
  Actions?: React.ReactNode;
67
55
  }
68
-
56
+ export type DRFReactBySchemaSubmitHandler = (...args: [...[model: string, id: Id], ...Parameters<SubmitHandler<FieldValues>>]) => ReturnType<SubmitHandler<FieldValues>>;
69
57
  export interface APIWrapperContextType {
70
58
  usuaria: Item | null;
71
- onSubmit: (model: string, id: Id, data: Item, e: React.SyntheticEvent<HTMLButtonElement, SubmitEvent>) => Promise<false | Id>;
72
- loadSinglePageData: (p: LoadSinglePageDataProps) => boolean | Item;
59
+ onSubmit: DRFReactBySchemaSubmitHandler;
60
+ loadSinglePageData: (p: LoadSinglePageDataProps) => Promise<boolean | FieldValues>;
73
61
  handleLoading: (p: boolean) => void;
74
- optionsACState: [{ [x: string]: any; }, React.Dispatch<OptionsACType>];
75
- pageFormState: [{ [x: string]: any; }, React.Dispatch<PageFormType>];
62
+ optionsACState: [{
63
+ [x: string]: any;
64
+ }, React.Dispatch<OptionsACType>];
65
+ pageFormState: [{
66
+ [x: string]: any;
67
+ }, React.Dispatch<PageFormType>];
76
68
  onEditModel: (p: OnEditModelType) => void;
77
- onDeleteModel: (model:string, id:Id, onSuccess:()=>void | null) => void;
69
+ onDeleteModel: (model: string, id: Id, onSuccess?: (e: React.BaseSyntheticEvent) => any) => void;
78
70
  onEditRelatedModelSave: (p: OnEditRelatedModelType) => Promise<boolean | Id | ItemSchemaColumnsType>;
79
71
  onDeleteRelatedModel: (p: OnDeleteRelatedModelType) => Promise<boolean>;
80
72
  onTriggerSnackBar: (p: SnackBarType) => void;
81
73
  setDialog: React.Dispatch<React.SetStateAction<DialogType>>;
82
- };
83
-
84
- export const APIWrapperContext = React.createContext<APIWrapperContextType | null>(null);
74
+ }
75
+ export declare const APIWrapperContext: React.Context<APIWrapperContextType | null>;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.APIWrapperContext = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ ;
9
+ ;
10
+ ;
11
+ ;
12
+ ;
13
+ ;
14
+ ;
15
+ exports.APIWrapperContext = react_1.default.createContext(null);
@@ -1,8 +1,5 @@
1
1
  import React from 'react';
2
2
  import { Theme } from '@mui/material/styles';
3
-
4
- import defaultTheme from '../styles/theme';
5
-
6
3
  export interface serverEndPointType {
7
4
  url: string;
8
5
  autocomplete?: string;
@@ -10,8 +7,8 @@ export interface serverEndPointType {
10
7
  JSONSchema?: string;
11
8
  apiTokenUrl: string;
12
9
  getToken?: string;
13
- refreshToken?: string,
14
- verifyToken?: string
10
+ refreshToken?: string;
11
+ verifyToken?: string;
15
12
  }
16
13
  export interface DRFReactBySchemaContextType {
17
14
  serverEndPoint: serverEndPointType | null;
@@ -19,15 +16,5 @@ export interface DRFReactBySchemaContextType {
19
16
  isInBatches?: boolean;
20
17
  firstBatchLength?: number;
21
18
  }
22
-
23
- export const DRFReactBySchemaContext = React.createContext<DRFReactBySchemaContextType>({
24
- serverEndPoint: null,
25
- theme: defaultTheme,
26
- isInBatches: true,
27
- firstBatchLength: 100
28
- });
29
-
30
- export const useTheme = () => {
31
- const context = React.useContext(DRFReactBySchemaContext);
32
- return context.theme;
33
- }
19
+ export declare const DRFReactBySchemaContext: React.Context<DRFReactBySchemaContextType>;
20
+ export declare const useTheme: () => Theme;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useTheme = exports.DRFReactBySchemaContext = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const theme_1 = __importDefault(require("../styles/theme"));
9
+ exports.DRFReactBySchemaContext = react_1.default.createContext({
10
+ serverEndPoint: null,
11
+ theme: theme_1.default,
12
+ isInBatches: true,
13
+ firstBatchLength: 100
14
+ });
15
+ const useTheme = () => {
16
+ const context = react_1.default.useContext(exports.DRFReactBySchemaContext);
17
+ return context.theme;
18
+ };
19
+ exports.useTheme = useTheme;
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { DRFReactBySchemaContextType } from './DRFReactBySchemaContext';
3
+ interface DRFReactBySchemaProviderProps extends DRFReactBySchemaContextType {
4
+ children: React.ReactNode;
5
+ }
6
+ /**
7
+ *
8
+ *
9
+ * @param {*} props
10
+ * @returns {*}
11
+ */
12
+ declare const DRFReactBySchemaProvider: ({ serverEndPoint, theme, isInBatches, firstBatchLength, children }: DRFReactBySchemaProviderProps) => JSX.Element;
13
+ export default DRFReactBySchemaProvider;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_1 = __importDefault(require("react"));
7
+ const styles_1 = require("@mui/material/styles");
8
+ const CssBaseline_1 = __importDefault(require("@mui/material/CssBaseline"));
9
+ const theme_1 = __importDefault(require("../styles/theme"));
10
+ const Overlays_1 = __importDefault(require("./Overlays"));
11
+ const DRFReactBySchemaContext_1 = require("./DRFReactBySchemaContext");
12
+ /**
13
+ *
14
+ *
15
+ * @param {*} props
16
+ * @returns {*}
17
+ */
18
+ const DRFReactBySchemaProvider = ({ serverEndPoint, theme, isInBatches, firstBatchLength, children }) => {
19
+ if (serverEndPoint) {
20
+ const defaultKeys = [
21
+ 'autocomplete',
22
+ 'api',
23
+ ['JSONSchema', 'jsonschema'],
24
+ ['getToken', ''],
25
+ ['refreshToken', 'refresh'],
26
+ ['verifyToken', 'verify']
27
+ ];
28
+ for (const key of defaultKeys) {
29
+ const hybridKey = (typeof key === 'string')
30
+ ? key
31
+ : key[0];
32
+ const hybridUrl = (typeof key === 'string')
33
+ ? key
34
+ : key[1];
35
+ if (serverEndPoint[hybridKey]) {
36
+ continue;
37
+ }
38
+ serverEndPoint[hybridKey] = `${serverEndPoint.url}/${hybridUrl}`;
39
+ }
40
+ }
41
+ const mergedTheme = (theme)
42
+ ? Object.assign(Object.assign({}, theme_1.default), theme) : theme_1.default;
43
+ return (react_1.default.createElement(styles_1.ThemeProvider, { theme: mergedTheme },
44
+ react_1.default.createElement(CssBaseline_1.default, null),
45
+ react_1.default.createElement(DRFReactBySchemaContext_1.DRFReactBySchemaContext.Provider, { value: {
46
+ serverEndPoint,
47
+ theme,
48
+ isInBatches,
49
+ firstBatchLength
50
+ } },
51
+ react_1.default.createElement(Overlays_1.default, { children: children }))));
52
+ };
53
+ exports.default = DRFReactBySchemaProvider;
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { Id } from '../utils';
3
+ interface FormProps {
4
+ model: string;
5
+ id: Id;
6
+ objTitleField?: string;
7
+ optionsACModels: string[];
8
+ cancelBtn?: (e: React.BaseSyntheticEvent) => any;
9
+ cancelBtnLabel?: string;
10
+ deleteBtnLabel?: string;
11
+ saveAndCreateNewBtnLabel?: string;
12
+ saveAndContinueBtnLabel?: string;
13
+ saveBtnLabel?: string;
14
+ onSuccess?: (e: React.BaseSyntheticEvent) => any;
15
+ borderBottom?: boolean;
16
+ saveAndContinue?: boolean;
17
+ formButtonsSx?: any;
18
+ children: React.ReactNode;
19
+ }
20
+ export default function Form({ model, id, objTitleField, optionsACModels, cancelBtn, cancelBtnLabel, deleteBtnLabel, saveAndCreateNewBtnLabel, saveAndContinueBtnLabel, saveBtnLabel, onSuccess, borderBottom, saveAndContinue, formButtonsSx, children }: FormProps): JSX.Element;
21
+ export {};