drf-react-by-schema 0.3.1 → 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.
- package/dist/api.d.ts +6 -7
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +24 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +42 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +1 -0
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable.js +16 -0
- package/dist/components/DataTotals.d.ts +1 -0
- package/dist/components/DialogJSONSchemaForm.d.ts +1 -0
- package/dist/components/FormButtons.d.ts +13 -6
- package/dist/components/FormButtons.js +20 -16
- package/dist/context/APIWrapper.js +2 -2
- package/dist/context/APIWrapperContext.d.ts +1 -1
- package/dist/context/Form.d.ts +11 -1
- package/dist/context/Form.js +22 -5
- package/dist/context/FormContext.d.ts +72 -0
- package/dist/context/FormContext.js +15 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/styles/layout.d.ts +1 -1
- package/dist/styles/theme.d.ts +1 -1
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +1 -1
- package/package.json +4 -4
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
2
1
|
import { serverEndPointType } from './context/DRFReactBySchemaContext';
|
|
3
2
|
import { Item, SchemaType, DataSchemaColumnsType, ItemSchemaColumnsType } from './utils';
|
|
4
3
|
type Id = string | number | null;
|
|
@@ -24,11 +23,11 @@ interface TargetApiParamsOptionalId {
|
|
|
24
23
|
* @param param0
|
|
25
24
|
* @returns Id when succesfully updated, false otherwise
|
|
26
25
|
*/
|
|
27
|
-
export declare const updateData: ({ path, serverEndPoint, data, id }: TargetApiParams) => Promise<
|
|
28
|
-
export declare const partialUpdateData: ({ path, serverEndPoint, data, id }: TargetApiParams) => Promise<
|
|
29
|
-
export declare const createData: ({ path, serverEndPoint, data }: Omit<TargetApiParams, 'id'>) => Promise<
|
|
26
|
+
export declare const updateData: ({ path, serverEndPoint, data, id }: TargetApiParams) => Promise<any>;
|
|
27
|
+
export declare const partialUpdateData: ({ path, serverEndPoint, data, id }: TargetApiParams) => Promise<any>;
|
|
28
|
+
export declare const createData: ({ path, serverEndPoint, data }: Omit<TargetApiParams, 'id'>) => Promise<any>;
|
|
30
29
|
export declare const deleteData: (path: string, serverEndPoint: serverEndPointType | null, id: Id) => Promise<boolean>;
|
|
31
|
-
export declare const createOrUpdateData: ({ path, serverEndPoint, data, id }: TargetApiParamsOptionalId) => Promise<
|
|
30
|
+
export declare const createOrUpdateData: ({ path, serverEndPoint, data, id }: TargetApiParamsOptionalId) => Promise<any>;
|
|
32
31
|
export declare const updateDataBySchema: ({ model, modelObjectId, serverEndPoint, data, schema, path }: {
|
|
33
32
|
model: string;
|
|
34
33
|
modelObjectId: Id;
|
|
@@ -36,13 +35,13 @@ export declare const updateDataBySchema: ({ model, modelObjectId, serverEndPoint
|
|
|
36
35
|
data: Item;
|
|
37
36
|
schema: SchemaType;
|
|
38
37
|
path?: string | null | undefined;
|
|
39
|
-
}) => Promise<
|
|
38
|
+
}) => Promise<any>;
|
|
40
39
|
export declare const addExistingRelatedModel: ({ model, serverEndPoint, id, data }: {
|
|
41
40
|
model: string;
|
|
42
41
|
serverEndPoint: serverEndPointType | null;
|
|
43
42
|
id: Id;
|
|
44
43
|
data: Item;
|
|
45
|
-
}) => Promise<
|
|
44
|
+
}) => Promise<any>;
|
|
46
45
|
export declare const getAutoComplete: ({ model, serverEndPoint }: {
|
|
47
46
|
model: string;
|
|
48
47
|
serverEndPoint: serverEndPointType | null;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SxProps } from '@mui/material';
|
|
3
|
+
import { GridEnrichedBySchemaColDef } from '../../utils';
|
|
4
|
+
interface BooleanInputCellProps {
|
|
5
|
+
field: string;
|
|
6
|
+
id: number | string;
|
|
7
|
+
value?: any;
|
|
8
|
+
column: GridEnrichedBySchemaColDef;
|
|
9
|
+
sx?: SxProps;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* @param {BooleanInputCellProps} {
|
|
15
|
+
* field,
|
|
16
|
+
* id,
|
|
17
|
+
* value,
|
|
18
|
+
* column,
|
|
19
|
+
* sx = {}
|
|
20
|
+
* }
|
|
21
|
+
* @returns {*} {JSX.Element}
|
|
22
|
+
*/
|
|
23
|
+
export declare function BooleanInputCell({ field, id, value, sx }: BooleanInputCellProps): JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BooleanInputCell = void 0;
|
|
16
|
+
const react_1 = __importDefault(require("react"));
|
|
17
|
+
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
18
|
+
const Checkbox_1 = __importDefault(require("@mui/material/Checkbox"));
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
*
|
|
22
|
+
* @param {BooleanInputCellProps} {
|
|
23
|
+
* field,
|
|
24
|
+
* id,
|
|
25
|
+
* value,
|
|
26
|
+
* column,
|
|
27
|
+
* sx = {}
|
|
28
|
+
* }
|
|
29
|
+
* @returns {*} {JSX.Element}
|
|
30
|
+
*/
|
|
31
|
+
function BooleanInputCell({ field, id, value, sx = {} }) {
|
|
32
|
+
// TODO: allow edit option label, as in formautocomplete!
|
|
33
|
+
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
34
|
+
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
36
|
+
apiRef.current.stopCellEditMode({ id, field });
|
|
37
|
+
});
|
|
38
|
+
return (react_1.default.createElement(Checkbox_1.default, { key: field, id: field, checked: value, inputProps: { 'aria-label': 'controlled' }, onChange: (event) => {
|
|
39
|
+
handleChange(event.target.checked);
|
|
40
|
+
}, sx: sx }));
|
|
41
|
+
}
|
|
42
|
+
exports.BooleanInputCell = BooleanInputCell;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { GridApi
|
|
2
|
+
import { GridApi } from "@mui/x-data-grid";
|
|
3
3
|
import { GridEnrichedBySchemaColDef } from "../../utils";
|
|
4
4
|
export type ResizeType = 'condense' | 'maxContent' | 'fitScreen';
|
|
5
5
|
/**
|
|
@@ -12,4 +12,4 @@ export type ResizeType = 'condense' | 'maxContent' | 'fitScreen';
|
|
|
12
12
|
export declare function resizeColumns(columns: GridEnrichedBySchemaColDef[], resizeType: ResizeType, apiRef: React.MutableRefObject<GridApi>): GridEnrichedBySchemaColDef[];
|
|
13
13
|
export declare const quantityOnlyOperators: ({ type }: {
|
|
14
14
|
type: string;
|
|
15
|
-
}) => GridFilterOperator
|
|
15
|
+
}) => GridFilterOperator[];
|
|
@@ -66,6 +66,7 @@ const CustomToolbar_1 = require("./DataGridBySchemaEditable/CustomToolbar");
|
|
|
66
66
|
const SelectEditInputCell_1 = require("./DataGridBySchemaEditable/SelectEditInputCell");
|
|
67
67
|
const GridDecimalInput_1 = require("./DataGridBySchemaEditable/GridDecimalInput");
|
|
68
68
|
const GridPatternInput_1 = require("./DataGridBySchemaEditable/GridPatternInput");
|
|
69
|
+
const BooleanInputCell_1 = require("./DataGridBySchemaEditable/BooleanInputCell");
|
|
69
70
|
const FooterToolbar_1 = require("./DataGridBySchemaEditable/FooterToolbar");
|
|
70
71
|
const ConfirmDialog_1 = require("./DataGridBySchemaEditable/ConfirmDialog");
|
|
71
72
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
@@ -227,6 +228,18 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
227
228
|
return (!params.value) ? '' : params.value.display_name;
|
|
228
229
|
};
|
|
229
230
|
break;
|
|
231
|
+
case 'boolean':
|
|
232
|
+
if (isEditable) {
|
|
233
|
+
column.valueFormatter = params => {
|
|
234
|
+
return (params.value) ? 'Sim' : 'Não';
|
|
235
|
+
};
|
|
236
|
+
column.renderEditCell = (params) => react_1.default.createElement(BooleanInputCell_1.BooleanInputCell, Object.assign({}, params, { column: column }));
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
column.valueGetter = params => {
|
|
240
|
+
return (params.value) ? 'Sim' : 'Não';
|
|
241
|
+
};
|
|
242
|
+
break;
|
|
230
243
|
case 'decimal':
|
|
231
244
|
case 'float':
|
|
232
245
|
column.type = 'number';
|
|
@@ -402,7 +415,9 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
402
415
|
setDataGridLoading(true);
|
|
403
416
|
const indexCol = preparedColumns.find(col => col.field === indexField);
|
|
404
417
|
processingRow.current = newRow.id;
|
|
418
|
+
console.log('antes');
|
|
405
419
|
yield yupValidationSchema.current.validate(newRow);
|
|
420
|
+
console.log('depois');
|
|
406
421
|
const onlyAddExisting = (indexField &&
|
|
407
422
|
(0, utils_1.isTmpId)(newRow.id) &&
|
|
408
423
|
(newRow[indexField] && !(0, utils_1.isTmpId)(newRow[indexField].id)) &&
|
|
@@ -428,6 +443,7 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)((_a, ref) => {
|
|
|
428
443
|
newRow[indexField] = newRow[indexField].label;
|
|
429
444
|
}
|
|
430
445
|
}
|
|
446
|
+
console.log({ modelParent, modelParentId, apiContext });
|
|
431
447
|
if (modelParent && modelParentId && apiContext) {
|
|
432
448
|
const response = yield apiContext.onEditRelatedModelSave({
|
|
433
449
|
model: modelParent,
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Id } from '../utils';
|
|
3
3
|
interface FormButtonsProps {
|
|
4
|
+
model: string;
|
|
5
|
+
objId: Id;
|
|
4
6
|
title: string;
|
|
5
|
-
objId?: string | number;
|
|
6
7
|
formDisabled: boolean;
|
|
7
|
-
cancelBtn?:
|
|
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;
|
|
8
15
|
bottom?: boolean;
|
|
9
16
|
borderBottom?: boolean;
|
|
10
17
|
saveAndContinue?: boolean;
|
|
11
|
-
sx?:
|
|
18
|
+
sx?: any;
|
|
12
19
|
}
|
|
13
|
-
export default function FormButtons({
|
|
20
|
+
export default function FormButtons({ model, objId, title, formDisabled, cancelBtn, cancelBtnLabel, deleteBtnLabel, saveAndCreateNewBtnLabel, saveAndContinueBtnLabel, saveBtnLabel, onSuccess, bottom, borderBottom, saveAndContinue, sx }: FormButtonsProps): JSX.Element;
|
|
14
21
|
export {};
|
|
@@ -4,36 +4,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const react_1 = __importDefault(require("react"));
|
|
7
|
-
const react_router_dom_1 = require("react-router-dom");
|
|
8
|
-
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
9
7
|
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
10
8
|
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
11
|
-
// import
|
|
9
|
+
// import { SxProps } from '@mui/material';
|
|
10
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
12
11
|
const styles_1 = require("../styles");
|
|
13
|
-
const utils_1 = require("../utils
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
14
|
+
function FormButtons({ model, objId, title, formDisabled, cancelBtn, cancelBtnLabel = 'Cancel', deleteBtnLabel = 'Delete', saveAndCreateNewBtnLabel = 'Save and Create New', saveAndContinueBtnLabel = 'Save and Continue', saveBtnLabel = 'Save', onSuccess, bottom = false, borderBottom = true, saveAndContinue = true, sx = {} }) {
|
|
15
|
+
const apiContext = react_1.default.useContext(APIWrapperContext_1.APIWrapperContext);
|
|
16
|
+
if (!apiContext) {
|
|
17
|
+
console.error('Error on drf-react-by-schema: there is no serverEndPoint configuration!');
|
|
18
|
+
return (react_1.default.createElement(react_1.default.Fragment, null));
|
|
19
|
+
}
|
|
20
|
+
const onDeleteModel = apiContext.onDeleteModel;
|
|
21
|
+
if (bottom && borderBottom && objId && objId !== 'novo' && sx !== null) {
|
|
17
22
|
sx.mb = 5;
|
|
18
23
|
sx.pb = 2;
|
|
19
24
|
sx.borderBottom = 'solid 1px #aaa';
|
|
20
25
|
}
|
|
21
26
|
return (react_1.default.createElement(Box_1.default, { sx: Object.assign(Object.assign({}, styles_1.Layout.flexRowGrow), sx) },
|
|
22
27
|
bottom
|
|
23
|
-
? react_1.default.createElement(Button_1.default, { variant: "contained", type: "button", color: "error", size: "small", disabled: (0, utils_1.isTmpId)(objId) || !onDeleteModel, onClick:
|
|
28
|
+
? react_1.default.createElement(Button_1.default, { variant: "contained", type: "button", color: "error", size: "small", disabled: (0, utils_1.isTmpId)(objId) || !onDeleteModel, onClick: () => {
|
|
29
|
+
onDeleteModel(model, objId, onSuccess);
|
|
30
|
+
} }, deleteBtnLabel)
|
|
24
31
|
: title
|
|
25
32
|
? react_1.default.createElement(Typography_1.default, { variant: "h5" }, title)
|
|
26
33
|
: react_1.default.createElement(Box_1.default, null),
|
|
27
34
|
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.flexRow },
|
|
28
|
-
cancelBtn
|
|
29
|
-
|
|
30
|
-
: react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick: () => {
|
|
31
|
-
navigate(-1);
|
|
32
|
-
} }, "Voltar"),
|
|
35
|
+
cancelBtn &&
|
|
36
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", color: "primary", size: "small", sx: { ml: 1 }, onClick: cancelBtn }, cancelBtnLabel),
|
|
33
37
|
saveAndContinue &&
|
|
34
38
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
35
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name: "createNewOnSave", type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled },
|
|
36
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name: "stayOnSave", type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled },
|
|
37
|
-
react_1.default.createElement(Button_1.default, { variant: "contained", name: "exitOnSave", type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled },
|
|
39
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: "createNewOnSave", type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, saveAndCreateNewBtnLabel),
|
|
40
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: "stayOnSave", type: "submit", color: "secondary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, saveAndContinueBtnLabel)),
|
|
41
|
+
react_1.default.createElement(Button_1.default, { variant: "contained", name: "exitOnSave", type: "submit", color: "primary", size: "small", sx: { ml: 1 }, disabled: formDisabled }, saveBtnLabel))));
|
|
38
42
|
}
|
|
39
43
|
exports.default = FormButtons;
|
|
@@ -235,8 +235,8 @@ function APIWrapper({ setLoading, handleLoading, setSnackBar, setDialog, childre
|
|
|
235
235
|
msg: 'Apagado com com sucesso!',
|
|
236
236
|
severity: 'info'
|
|
237
237
|
});
|
|
238
|
-
if (onSuccess
|
|
239
|
-
onSuccess();
|
|
238
|
+
if (onSuccess) {
|
|
239
|
+
onSuccess({});
|
|
240
240
|
}
|
|
241
241
|
return true;
|
|
242
242
|
}
|
|
@@ -66,7 +66,7 @@ export interface APIWrapperContextType {
|
|
|
66
66
|
[x: string]: any;
|
|
67
67
|
}, React.Dispatch<PageFormType>];
|
|
68
68
|
onEditModel: (p: OnEditModelType) => void;
|
|
69
|
-
onDeleteModel: (model: string, id: Id, onSuccess:
|
|
69
|
+
onDeleteModel: (model: string, id: Id, onSuccess?: (e: React.BaseSyntheticEvent) => any) => void;
|
|
70
70
|
onEditRelatedModelSave: (p: OnEditRelatedModelType) => Promise<boolean | Id | ItemSchemaColumnsType>;
|
|
71
71
|
onDeleteRelatedModel: (p: OnDeleteRelatedModelType) => Promise<boolean>;
|
|
72
72
|
onTriggerSnackBar: (p: SnackBarType) => void;
|
package/dist/context/Form.d.ts
CHANGED
|
@@ -5,7 +5,17 @@ interface FormProps {
|
|
|
5
5
|
id: Id;
|
|
6
6
|
objTitleField?: string;
|
|
7
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;
|
|
8
18
|
children: React.ReactNode;
|
|
9
19
|
}
|
|
10
|
-
export default function Form({ model, id, objTitleField, optionsACModels, children }: FormProps): JSX.Element;
|
|
20
|
+
export default function Form({ model, id, objTitleField, optionsACModels, cancelBtn, cancelBtnLabel, deleteBtnLabel, saveAndCreateNewBtnLabel, saveAndContinueBtnLabel, saveBtnLabel, onSuccess, borderBottom, saveAndContinue, formButtonsSx, children }: FormProps): JSX.Element;
|
|
11
21
|
export {};
|
package/dist/context/Form.js
CHANGED
|
@@ -36,7 +36,8 @@ const FormButtons_1 = __importDefault(require("../components/FormButtons"));
|
|
|
36
36
|
const APIWrapperContext_1 = require("./APIWrapperContext");
|
|
37
37
|
const utils_1 = require("../utils");
|
|
38
38
|
const DRFReactBySchemaContext_1 = require("./DRFReactBySchemaContext");
|
|
39
|
-
|
|
39
|
+
const FormContext_1 = require("./FormContext");
|
|
40
|
+
function Form({ model, id, objTitleField = 'name', optionsACModels = [], cancelBtn, cancelBtnLabel, deleteBtnLabel, saveAndCreateNewBtnLabel, saveAndContinueBtnLabel, saveBtnLabel, onSuccess, borderBottom, saveAndContinue, formButtonsSx, children }) {
|
|
40
41
|
const apiContext = react_1.default.useContext(APIWrapperContext_1.APIWrapperContext);
|
|
41
42
|
const context = react_1.default.useContext(DRFReactBySchemaContext_1.DRFReactBySchemaContext);
|
|
42
43
|
if (!context.serverEndPoint || !apiContext) {
|
|
@@ -66,14 +67,30 @@ function Form({ model, id, objTitleField = 'name', optionsACModels = [], childre
|
|
|
66
67
|
loadAllData();
|
|
67
68
|
}, [id]);
|
|
68
69
|
const formButtonProps = {
|
|
70
|
+
model,
|
|
69
71
|
objId: id,
|
|
72
|
+
title: (0, utils_1.isTmpId)(id) ? 'Novo' : 'Editar',
|
|
70
73
|
formDisabled: !isDirty,
|
|
71
|
-
|
|
74
|
+
cancelBtn,
|
|
75
|
+
cancelBtnLabel,
|
|
76
|
+
deleteBtnLabel,
|
|
77
|
+
saveAndCreateNewBtnLabel,
|
|
78
|
+
saveAndContinueBtnLabel,
|
|
79
|
+
saveBtnLabel,
|
|
80
|
+
onSuccess,
|
|
81
|
+
borderBottom,
|
|
82
|
+
saveAndContinue,
|
|
83
|
+
sx: formButtonsSx
|
|
72
84
|
};
|
|
85
|
+
// onSubmit={handleSubmit((data, event) => {
|
|
86
|
+
// onSubmit(
|
|
87
|
+
// model,
|
|
88
|
+
// id,
|
|
89
|
+
// data,
|
|
90
|
+
// event
|
|
91
|
+
// );
|
|
73
92
|
return (react_1.default.createElement(react_1.default.Fragment, null, pageForm.initialValues && pageForm.schema && control &&
|
|
74
|
-
react_1.default.createElement(
|
|
75
|
-
onSubmit(model, id, data, event);
|
|
76
|
-
}) },
|
|
93
|
+
react_1.default.createElement(FormContext_1.FormContext.Provider, { value: null },
|
|
77
94
|
react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterMoment_1.AdapterMoment },
|
|
78
95
|
react_1.default.createElement(FormButtons_1.default, Object.assign({}, formButtonProps)),
|
|
79
96
|
react_1.default.createElement(Box_1.default, null, children),
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Id, Item, SchemaType } from '../utils';
|
|
3
|
+
export interface LoadSinglePageDataProps {
|
|
4
|
+
model: string;
|
|
5
|
+
objId?: Id;
|
|
6
|
+
objTitleField?: string;
|
|
7
|
+
optionsACModels: string[];
|
|
8
|
+
basePath?: string;
|
|
9
|
+
formPath?: string | null;
|
|
10
|
+
extraValidators?: Item;
|
|
11
|
+
}
|
|
12
|
+
export type OptionsACType = Record<string, Item[]>;
|
|
13
|
+
export interface PageFormType {
|
|
14
|
+
id: Id;
|
|
15
|
+
schema: SchemaType | null;
|
|
16
|
+
initialValues: Item | null;
|
|
17
|
+
validationSchema: Item | null;
|
|
18
|
+
}
|
|
19
|
+
export interface OnEditModelType {
|
|
20
|
+
fieldKey: string;
|
|
21
|
+
index: string;
|
|
22
|
+
model: string;
|
|
23
|
+
id: Id;
|
|
24
|
+
labelKey: string;
|
|
25
|
+
setValue: (p: any) => void;
|
|
26
|
+
getValues: (p: any) => any;
|
|
27
|
+
}
|
|
28
|
+
export interface OnEditRelatedModelType {
|
|
29
|
+
model: string;
|
|
30
|
+
id: Id;
|
|
31
|
+
relatedModel: string;
|
|
32
|
+
relatedModelId: Id;
|
|
33
|
+
newRow: Item;
|
|
34
|
+
schema: SchemaType;
|
|
35
|
+
onlyAddExisting: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface OnDeleteRelatedModelType {
|
|
38
|
+
model: string;
|
|
39
|
+
id: Id;
|
|
40
|
+
relatedModel: string;
|
|
41
|
+
relatedModelId: Id;
|
|
42
|
+
}
|
|
43
|
+
export interface SnackBarType {
|
|
44
|
+
open?: boolean;
|
|
45
|
+
msg?: string;
|
|
46
|
+
severity?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface DialogType {
|
|
49
|
+
open: boolean;
|
|
50
|
+
loading?: boolean;
|
|
51
|
+
title?: string;
|
|
52
|
+
Body?: React.ReactNode;
|
|
53
|
+
Actions?: React.ReactNode;
|
|
54
|
+
}
|
|
55
|
+
export interface FormContextType {
|
|
56
|
+
model: string;
|
|
57
|
+
id: Id;
|
|
58
|
+
objTitleField: string;
|
|
59
|
+
optionsACModels: string[];
|
|
60
|
+
cancelBtn?: (e: React.BaseSyntheticEvent) => any;
|
|
61
|
+
cancelBtnLabel: any;
|
|
62
|
+
deleteBtnLabel: any;
|
|
63
|
+
saveAndCreateNewBtnLabel: any;
|
|
64
|
+
saveAndContinueBtnLabel: any;
|
|
65
|
+
saveBtnLabel: any;
|
|
66
|
+
onSuccess: any;
|
|
67
|
+
borderBottom: any;
|
|
68
|
+
saveAndContinue: any;
|
|
69
|
+
formButtonsSx: any;
|
|
70
|
+
children: any;
|
|
71
|
+
}
|
|
72
|
+
export declare const FormContext: React.Context<FormContextType | 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.FormContext = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
;
|
|
9
|
+
;
|
|
10
|
+
;
|
|
11
|
+
;
|
|
12
|
+
;
|
|
13
|
+
;
|
|
14
|
+
;
|
|
15
|
+
exports.FormContext = react_1.default.createContext(null);
|
package/dist/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ import GenericModelList from './components/GenericModelList';
|
|
|
8
8
|
import GenericRelatedModelList from './components/GenericRelatedModelList';
|
|
9
9
|
import DataTotals from './components/DataTotals';
|
|
10
10
|
import DialogActions from './components/DialogActions';
|
|
11
|
-
|
|
11
|
+
import Form from './context/Form';
|
|
12
|
+
export { DRFReactBySchemaProvider, DRFReactBySchemaContext, APIWrapperContext, useTheme, Form, FormContext, DataGridBySchemaEditable, GenericModelList, GenericRelatedModelList, DataTotals, DialogActions, updateData, partialUpdateData, createData, deleteData, createOrUpdateData, updateDataBySchema, addExistingRelatedModel, getAutoComplete, getJSONSchema, createOrUpdateJSONSchema, loginByPayload, setAuthToken, isLoggedIn, getGenericModelList, getGenericModel, emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getTmpId, isTmpId, getPatternFormat };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.getGenericModel = exports.getGenericModelList = exports.isLoggedIn = exports.setAuthToken = exports.loginByPayload = exports.createOrUpdateJSONSchema = exports.getJSONSchema = exports.getAutoComplete = exports.addExistingRelatedModel = exports.updateDataBySchema = exports.createOrUpdateData = exports.deleteData = exports.createData = exports.partialUpdateData = exports.updateData = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.useTheme = exports.APIWrapperContext = exports.DRFReactBySchemaContext = exports.DRFReactBySchemaProvider = void 0;
|
|
6
|
+
exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.getGenericModel = exports.getGenericModelList = exports.isLoggedIn = exports.setAuthToken = exports.loginByPayload = exports.createOrUpdateJSONSchema = exports.getJSONSchema = exports.getAutoComplete = exports.addExistingRelatedModel = exports.updateDataBySchema = exports.createOrUpdateData = exports.deleteData = exports.createData = exports.partialUpdateData = exports.updateData = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.FormContext = exports.Form = exports.useTheme = exports.APIWrapperContext = exports.DRFReactBySchemaContext = exports.DRFReactBySchemaProvider = void 0;
|
|
7
7
|
// Methods:
|
|
8
8
|
const api_1 = require("./api");
|
|
9
9
|
Object.defineProperty(exports, "updateData", { enumerable: true, get: function () { return api_1.updateData; } });
|
|
@@ -49,3 +49,5 @@ const DataTotals_1 = __importDefault(require("./components/DataTotals"));
|
|
|
49
49
|
exports.DataTotals = DataTotals_1.default;
|
|
50
50
|
const DialogActions_1 = __importDefault(require("./components/DialogActions"));
|
|
51
51
|
exports.DialogActions = DialogActions_1.default;
|
|
52
|
+
const Form_1 = __importDefault(require("./context/Form"));
|
|
53
|
+
exports.Form = Form_1.default;
|
package/dist/styles/layout.d.ts
CHANGED
package/dist/styles/theme.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Yup from 'yup';
|
|
2
1
|
import { GridActionsColDef, GridColDef } from '@mui/x-data-grid';
|
|
3
2
|
export type Id = string | number;
|
|
4
3
|
export type Item = Record<string, any>;
|
|
@@ -54,7 +53,7 @@ export declare const buildGenericYupValidationSchema: ({ data, schema, many, ski
|
|
|
54
53
|
many?: boolean | undefined;
|
|
55
54
|
skipFields?: string[] | undefined;
|
|
56
55
|
extraValidators?: Item | undefined;
|
|
57
|
-
}) =>
|
|
56
|
+
}) => any;
|
|
58
57
|
export declare const errorProps: ({ type, errors, fieldKey, fieldKeyProp, index }: {
|
|
59
58
|
type: string;
|
|
60
59
|
errors: Item;
|
package/dist/utils.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drf-react-by-schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Components and Tools for building a React App having Django Rest Framework (DRF) as server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"prepare": "install-peers",
|
|
11
11
|
"styleguide": "styleguidist server",
|
|
12
12
|
"styleguide:build": "styleguidist build",
|
|
13
|
-
"release:major": "
|
|
14
|
-
"release:minor": "
|
|
15
|
-
"release:patch": "
|
|
13
|
+
"release:major": "yarn version --version $(semver $npm_package_version -i major) && yarn publish --tag latest",
|
|
14
|
+
"release:minor": "yarn version --new-version $(semver $npm_package_version -i minor) && yarn publish --tag latest",
|
|
15
|
+
"release:patch": "yarn version --new-version $(semver $npm_package_version -i patch) && yarn publish --tag latest"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|