drf-react-by-schema 0.22.3 → 0.23.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/@types/index.d.ts +25 -14
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/api.d.ts +7 -11
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +50 -28
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +4 -21
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +64 -19
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +56 -50
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +8 -8
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +234 -737
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +1 -1
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +4 -21
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/FileInputCell.js +62 -21
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +5 -1
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +24 -4
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +4 -9
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridDateInput.js +125 -5
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +4 -8
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +51 -5
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts +8 -0
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridGenericInput.js +30 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts +4 -7
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +59 -5
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +2 -2
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/InputInterval.js +23 -4
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.js +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +4 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +72 -25
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +34 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.js +170 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts +14 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useOptionsAC.js +67 -0
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts +9 -0
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/usePreparedColumns.js +68 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +33 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +219 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.d.ts +18 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useRowMode.js +43 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +30 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +180 -0
- package/dist/components/DataGridBySchemaEditable.d.ts +2 -1
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable.js +24 -4
- package/dist/components/GenericModelList.d.ts.map +1 -1
- package/dist/components/GenericModelList.js +12 -7
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelList.js +13 -8
- package/dist/components/GenericRelatedModelListTable.d.ts +3 -2
- package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -1
- package/dist/components/GenericRelatedModelListTable.js +2 -2
- package/dist/components/Image.d.ts.map +1 -1
- package/dist/components/Image.js +2 -2
- package/dist/components/details/DetailBySchema.js +1 -1
- package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailFieldBySchema.js +3 -0
- package/dist/components/forms/DialogFormBySchema.d.ts +4 -3
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/Form.d.ts +4 -3
- package/dist/components/forms/Form.d.ts.map +1 -1
- package/dist/components/forms/Form.js +21 -2
- package/dist/components/forms/FormBySchema.d.ts +3 -2
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +2 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +2 -2
- package/dist/context/APIWrapper.d.ts.map +1 -1
- package/dist/context/APIWrapper.js +35 -29
- package/dist/context/APIWrapperContext.d.ts +17 -14
- package/dist/context/APIWrapperContext.d.ts.map +1 -1
- package/dist/context/APIWrapperContext.js +12 -10
- package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -1
- package/dist/context/DRFReactBySchemaProvider.js +2 -1
- package/dist/styles/grid.d.ts +3 -0
- package/dist/styles/grid.d.ts.map +1 -0
- package/dist/styles/grid.js +42 -0
- package/dist/styles/theme.d.ts.map +1 -1
- package/dist/styles/theme.js +33 -7
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +24 -28
- package/package.json +9 -8
|
@@ -1,4 +1,37 @@
|
|
|
1
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -13,18 +46,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
46
|
};
|
|
14
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
48
|
exports.GridPatternInput = void 0;
|
|
16
|
-
const react_1 =
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
17
50
|
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
18
51
|
const react_number_format_1 = require("react-number-format");
|
|
19
52
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
20
|
-
const
|
|
53
|
+
const grid_1 = require("../../styles/grid");
|
|
54
|
+
const GridPatternInput = (props) => {
|
|
55
|
+
const { id, value, field, patternFormat = 'cpf', error, helperText, hasFocus,
|
|
56
|
+
// tabIndex,
|
|
57
|
+
// cellMode,
|
|
58
|
+
// isEditable,
|
|
59
|
+
// api,
|
|
60
|
+
// row,
|
|
61
|
+
colDef,
|
|
62
|
+
// ...other
|
|
63
|
+
} = props;
|
|
21
64
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
65
|
+
const inputCallbackRef = (0, react_1.useCallback)((node) => {
|
|
66
|
+
if (node !== null && hasFocus) {
|
|
67
|
+
requestAnimationFrame(() => {
|
|
68
|
+
node.focus();
|
|
69
|
+
node.select();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, [hasFocus]);
|
|
22
73
|
const handleChange = (newValue) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
74
|
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
24
|
-
apiRef.current.stopCellEditMode({ id, field });
|
|
25
75
|
});
|
|
26
|
-
return (react_1.default.createElement(react_number_format_1.PatternFormat, { key: field, id: field, onValueChange: (values) => {
|
|
76
|
+
return (react_1.default.createElement(react_number_format_1.PatternFormat, { key: field, id: field, inputRef: inputCallbackRef, onValueChange: (values) => {
|
|
27
77
|
handleChange(values.value);
|
|
28
|
-
}, value: value, valueIsNumericString: true, format: patternFormat, mask: "_", customInput: TextField_1.default
|
|
78
|
+
}, value: value, valueIsNumericString: true, format: patternFormat, mask: "_", customInput: TextField_1.default, slotProps: {
|
|
79
|
+
htmlInput: {
|
|
80
|
+
'aria-label': `Editar ${colDef.headerName || field}. Pressione Enter para salvar toda a linha.`,
|
|
81
|
+
},
|
|
82
|
+
}, error: error, helperText: helperText, sx: grid_1.seamlessTextFieldStyle }));
|
|
29
83
|
};
|
|
30
84
|
exports.GridPatternInput = GridPatternInput;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { RefObject } from 'react';
|
|
2
2
|
import { Id } from '../../@types';
|
|
3
3
|
type FilterValue = [string | undefined, string | undefined] | string;
|
|
4
4
|
type GridFilterItem = {
|
|
@@ -9,7 +9,7 @@ type GridFilterItem = {
|
|
|
9
9
|
};
|
|
10
10
|
type InputIntervalProps = {
|
|
11
11
|
applyValue: (params: GridFilterItem) => void;
|
|
12
|
-
focusElementRef?: null | ((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement
|
|
12
|
+
focusElementRef?: null | ((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement>;
|
|
13
13
|
item: GridFilterItem;
|
|
14
14
|
type: string;
|
|
15
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputInterval.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/InputInterval.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"InputInterval.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/InputInterval.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAoB,SAAS,EAAU,MAAM,OAAO,CAAC;AAKnE,OAAO,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAIlC,KAAK,WAAW,GAAG,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC;AAErE,KAAK,cAAc,GAAG;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,EAAE,CAAC;IACP,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C,eAAe,CAAC,EACd,IAAI,GACJ,CAAC,CAAC,QAAQ,EAAE,gBAAgB,GAAG,IAAI,KAAK,IAAI,CAAC,GAC7C,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAC9B,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAoKF,KAAK,YAAY,GAAG,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAErD,eAAO,MAAM,mBAAmB,GAAI,OAAO,YAAY,sBAEtD,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,OAAO,YAAY,sBAEpD,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO,YAAY,sBAErD,CAAC"}
|
|
@@ -86,17 +86,36 @@ const InputInterval = ({ item, applyValue, focusElementRef = null, type }) => {
|
|
|
86
86
|
} },
|
|
87
87
|
type === 'number' && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
88
88
|
react_1.default.createElement(TextField_1.default, { name: "lower-bound-input", placeholder: "De", label: "De", variant: "standard", value: Number(filterValueState[0]), onChange: handleLowerFilterChange, type: "number", inputRef: focusElementRef, sx: { mr: 2, minWidth: 130 } }),
|
|
89
|
-
react_1.default.createElement(TextField_1.default, { name: "upper-bound-input", placeholder: "At\u00E9", label: "At\u00E9", variant: "standard", value: Number(filterValueState[1]), onChange: handleUpperFilterChange, type: "number", sx: { minWidth: 130 },
|
|
89
|
+
react_1.default.createElement(TextField_1.default, { name: "upper-bound-input", placeholder: "At\u00E9", label: "At\u00E9", variant: "standard", value: Number(filterValueState[1]), onChange: handleUpperFilterChange, type: "number", sx: { minWidth: 130 }, slotProps: {
|
|
90
|
+
input: {
|
|
91
|
+
endAdornment: applying ? react_1.default.createElement(Sync_1.default, null) : undefined,
|
|
92
|
+
}
|
|
93
|
+
} }))),
|
|
90
94
|
type === 'float' && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
91
95
|
react_1.default.createElement(react_number_format_1.NumericFormat, { name: "lower-bound-input", placeholder: "De", label: "De", variant: "standard", value: Number(filterValueState[0]), onValueChange: (values) => {
|
|
92
96
|
handleLowerFilterChange({ target: { value: values.value } });
|
|
93
97
|
}, thousandSeparator: ".", decimalSeparator: ",", decimalScale: 2, fixedDecimalScale: true, valueIsNumericString: true, inputRef: focusElementRef, sx: { mr: 2, minWidth: 130 }, customInput: TextField_1.default }),
|
|
94
98
|
react_1.default.createElement(react_number_format_1.NumericFormat, { name: "upper-bound-input", placeholder: "At\u00E9", label: "At\u00E9", variant: "standard", value: Number(filterValueState[1]), onValueChange: (values) => {
|
|
95
99
|
handleUpperFilterChange({ target: { value: values.value } });
|
|
96
|
-
}, thousandSeparator: ".", decimalSeparator: ",", decimalScale: 2, fixedDecimalScale: true, valueIsNumericString: true,
|
|
100
|
+
}, thousandSeparator: ".", decimalSeparator: ",", decimalScale: 2, fixedDecimalScale: true, valueIsNumericString: true, sx: { minWidth: 130 }, customInput: TextField_1.default, slotProps: {
|
|
101
|
+
input: {
|
|
102
|
+
endAdornment: applying ? react_1.default.createElement(Sync_1.default, null) : undefined,
|
|
103
|
+
}
|
|
104
|
+
} }))),
|
|
97
105
|
type === 'date' && (react_1.default.createElement(react_1.default.Fragment, null,
|
|
98
|
-
react_1.default.createElement(TextField_1.default, { name: "lower-bound-input", label: "De", variant: "standard", value: filterValueState[0] || '', onChange: handleLowerFilterChange, type: "date", inputRef: focusElementRef,
|
|
99
|
-
|
|
106
|
+
react_1.default.createElement(TextField_1.default, { name: "lower-bound-input", label: "De", variant: "standard", value: filterValueState[0] || '', onChange: handleLowerFilterChange, type: "date", inputRef: focusElementRef, slotProps: {
|
|
107
|
+
inputLabel: {
|
|
108
|
+
shrink: true,
|
|
109
|
+
}
|
|
110
|
+
}, sx: { mr: 2, minWidth: 130 } }),
|
|
111
|
+
react_1.default.createElement(TextField_1.default, { name: "upper-bound-input", label: "At\u00E9", variant: "standard", value: filterValueState[1] || '', onChange: handleUpperFilterChange, type: "date", slotProps: {
|
|
112
|
+
input: {
|
|
113
|
+
endAdornment: applying ? react_1.default.createElement(Sync_1.default, null) : undefined,
|
|
114
|
+
},
|
|
115
|
+
inputLabel: {
|
|
116
|
+
shrink: true,
|
|
117
|
+
}
|
|
118
|
+
}, sx: { minWidth: 130 } })))));
|
|
100
119
|
};
|
|
101
120
|
const InputNumberInterval = (props) => {
|
|
102
121
|
return react_1.default.createElement(InputInterval, Object.assign({}, props, { type: "number" }));
|
|
@@ -58,7 +58,7 @@ function MobileSearchBar({ paginationModel, setPaginationModel }) {
|
|
|
58
58
|
startAdornment: (react_1.default.createElement(InputAdornment_1.default, { position: "start" },
|
|
59
59
|
react_1.default.createElement(Search_1.default, null))),
|
|
60
60
|
endAdornment: (react_1.default.createElement(InputAdornment_1.default, { position: "end" },
|
|
61
|
-
react_1.default.createElement(IconButton_1.default, { onClick: () => handleSearchChange('') },
|
|
61
|
+
react_1.default.createElement(IconButton_1.default, { onClick: () => handleSearchChange(''), "aria-label": "Limpar busca" },
|
|
62
62
|
react_1.default.createElement(Clear_1.default, null)))),
|
|
63
63
|
}, fullWidth: true, onChange: handleChangeEvent }));
|
|
64
64
|
}
|
|
@@ -15,7 +15,10 @@ interface SelectEditInputCellProps {
|
|
|
15
15
|
fieldsLayout?: FormFieldLayout[];
|
|
16
16
|
sx?: SxProps<Theme>;
|
|
17
17
|
setDialog: (x: Partial<DialogType>) => void;
|
|
18
|
+
error?: boolean;
|
|
19
|
+
helperText?: string;
|
|
20
|
+
hasFocus?: boolean;
|
|
18
21
|
}
|
|
19
|
-
export declare function SelectEditInputCell({ field, id, value, column, type, options, isIndexField, multiple, onEditModel, fieldsLayout, sx, setDialog, }: SelectEditInputCellProps): JSX.Element;
|
|
22
|
+
export declare function SelectEditInputCell({ field, id, value, column, type, options, isIndexField, multiple, onEditModel, fieldsLayout, sx, setDialog, error, helperText, hasFocus, }: SelectEditInputCellProps): JSX.Element;
|
|
20
23
|
export {};
|
|
21
24
|
//# sourceMappingURL=SelectEditInputCell.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectEditInputCell.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/SelectEditInputCell.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"SelectEditInputCell.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/SelectEditInputCell.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,GAAG,EAAoC,MAAM,OAAO,CAAC;AAGrE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAMtD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAM9E,UAAU,wBAAwB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,0BAA0B,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;IAClD,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,IAAI,CAAC;IAC3C,YAAY,CAAC,EAAE,eAAe,EAAE,CAAC;IACjC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpB,SAAS,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IAC5C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,EAAE,EACF,KAAK,EACL,MAAM,EACN,IAAI,EACJ,OAAO,EACP,YAAY,EACZ,QAAgB,EAChB,WAAW,EACX,YAAY,EACZ,EAAyB,EACzB,SAAS,EACT,KAAK,EACL,UAAU,EACV,QAAQ,GACT,EAAE,wBAAwB,GAAG,GAAG,CAAC,OAAO,CAmRxC"}
|
|
@@ -54,11 +54,21 @@ const Edit_1 = __importDefault(require("@mui/icons-material/Edit"));
|
|
|
54
54
|
const Autocomplete_1 = __importStar(require("@mui/material/Autocomplete"));
|
|
55
55
|
const utils_1 = require("../../utils");
|
|
56
56
|
const DialogActions_1 = __importDefault(require("../DialogActions"));
|
|
57
|
+
const grid_1 = require("../../styles/grid");
|
|
57
58
|
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
58
|
-
function SelectEditInputCell({ field, id, value, column, type, options, isIndexField, multiple = false, onEditModel, fieldsLayout, sx = {}, setDialog, }) {
|
|
59
|
+
function SelectEditInputCell({ field, id, value, column, type, options, isIndexField, multiple = false, onEditModel, fieldsLayout, sx = {}, setDialog, error, helperText, hasFocus, }) {
|
|
59
60
|
const [loadedOptions, setLoadedOptions] = (0, react_1.useState)(null);
|
|
60
61
|
// TODO: allow edit option label, as in formautocomplete!
|
|
61
62
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
63
|
+
const [openOptions, setOpenOptions] = (0, react_1.useState)(false);
|
|
64
|
+
const inputCallbackRef = (0, react_1.useCallback)((node) => {
|
|
65
|
+
if (node !== null && hasFocus) {
|
|
66
|
+
requestAnimationFrame(() => {
|
|
67
|
+
node.focus();
|
|
68
|
+
node.select();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}, [hasFocus]);
|
|
62
72
|
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
63
73
|
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
64
74
|
apiRef.current.stopCellEditMode({ id, field });
|
|
@@ -69,7 +79,7 @@ function SelectEditInputCell({ field, id, value, column, type, options, isIndexF
|
|
|
69
79
|
// if (column.creatable || isIndexField) {
|
|
70
80
|
if (column.creatable) {
|
|
71
81
|
creatableProps = {
|
|
72
|
-
|
|
82
|
+
freeSolo: true,
|
|
73
83
|
filterOptions: (thisOptions, params) => {
|
|
74
84
|
let filtered = filter(thisOptions, params);
|
|
75
85
|
const inputValue = params.inputValue ? params.inputValue : '';
|
|
@@ -117,6 +127,12 @@ function SelectEditInputCell({ field, id, value, column, type, options, isIndexF
|
|
|
117
127
|
},
|
|
118
128
|
};
|
|
119
129
|
}
|
|
130
|
+
const handleOpenOptions = () => {
|
|
131
|
+
setOpenOptions(true);
|
|
132
|
+
};
|
|
133
|
+
const handleCloseOptions = () => {
|
|
134
|
+
setOpenOptions(false);
|
|
135
|
+
};
|
|
120
136
|
(0, react_1.useEffect)(() => {
|
|
121
137
|
if (!options) {
|
|
122
138
|
return;
|
|
@@ -136,11 +152,15 @@ function SelectEditInputCell({ field, id, value, column, type, options, isIndexF
|
|
|
136
152
|
) {
|
|
137
153
|
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
138
154
|
}
|
|
139
|
-
return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, id: field, value: value, options: loadedOptions, selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option,
|
|
140
|
-
return option[labelKey] ===
|
|
155
|
+
return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, open: openOptions, onOpen: handleOpenOptions, onClose: handleCloseOptions, id: field, value: value, options: loadedOptions, selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option, val) => {
|
|
156
|
+
return option[labelKey] === val[labelKey];
|
|
141
157
|
}, getOptionLabel: (option) => {
|
|
158
|
+
if (typeof option === 'string')
|
|
159
|
+
return option;
|
|
160
|
+
if (option.inputValue)
|
|
161
|
+
return option.inputValue;
|
|
142
162
|
return option ? option[labelKey] : '';
|
|
143
|
-
}, onChange: (
|
|
163
|
+
}, onChange: (_e, value) => {
|
|
144
164
|
// if (!column.creatable && !isIndexField) {
|
|
145
165
|
if (!column.creatable) {
|
|
146
166
|
handleChange(value);
|
|
@@ -175,25 +195,52 @@ function SelectEditInputCell({ field, id, value, column, type, options, isIndexF
|
|
|
175
195
|
};
|
|
176
196
|
}
|
|
177
197
|
handleChange(newValue);
|
|
178
|
-
}, fullWidth: true,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
}, fullWidth: true, slotProps: {
|
|
199
|
+
paper: {
|
|
200
|
+
sx: {
|
|
201
|
+
marginTop: '1px', // Gap to show the bottom cell border
|
|
202
|
+
boxShadow: 3,
|
|
203
|
+
border: '1px solid #e0e0e0',
|
|
204
|
+
'& .MuiAutocomplete-listbox': {
|
|
205
|
+
padding: 0,
|
|
206
|
+
fontSize: '0.875rem',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
}, renderInput: (params) => (react_1.default.createElement(react_1.default.Fragment, null, column.creatable ? (react_1.default.createElement(TextField_1.default, Object.assign({}, params, {
|
|
211
|
+
// margin="normal"
|
|
212
|
+
inputRef: inputCallbackRef, slotProps: {
|
|
213
|
+
htmlInput: Object.assign(Object.assign({}, params.inputProps), { 'aria-label': `Editar ${column.headerName || field}. Pressione Enter ou comece a digitar para ver as opções.` }),
|
|
214
|
+
input: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
215
|
+
!multiple && onEditModel && value && (react_1.default.createElement(IconButton_1.default, { size: "small", "aria-label": "Editar", onClick: () => {
|
|
216
|
+
if ((0, utils_1.isTmpId)(value.id)) {
|
|
217
|
+
setDialog({
|
|
218
|
+
open: true,
|
|
219
|
+
loading: false,
|
|
220
|
+
title: 'Linha sendo criada',
|
|
221
|
+
Body: 'Esta linha está sendo criada agora por você. Para editar suas propriedades, salve antes, e depois você poderá editar!',
|
|
222
|
+
Actions: (react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, btnCancel: "Entendi" })),
|
|
223
|
+
});
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
onEditModel({
|
|
227
|
+
model: field,
|
|
228
|
+
id: value[valueKey],
|
|
229
|
+
labelKey,
|
|
230
|
+
fieldsLayout,
|
|
187
231
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
232
|
+
} },
|
|
233
|
+
react_1.default.createElement(Edit_1.default, null))),
|
|
234
|
+
params.InputProps.endAdornment)) }),
|
|
235
|
+
}, error: error, helperText: helperText, sx: [grid_1.seamlessTextFieldStyle, ...(Array.isArray(sx) ? sx : [sx])] }))) : (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { inputRef: inputCallbackRef, slotProps: {
|
|
236
|
+
htmlInput: Object.assign(Object.assign({}, params.inputProps), { 'aria-label': `Selecionar ${column.headerName || field}` }),
|
|
237
|
+
}, error: error, helperText: helperText, sx: [grid_1.seamlessTextFieldStyle, ...(Array.isArray(sx) ? sx : [sx])] }))))) }, creatableProps, { onKeyDown: (event) => {
|
|
238
|
+
if (event.key === 'Enter') {
|
|
239
|
+
if (!openOptions) {
|
|
240
|
+
// Abrir o menu de opções
|
|
241
|
+
event.stopPropagation();
|
|
242
|
+
handleOpenOptions();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
} })));
|
|
199
246
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { GridRowId } from '@mui/x-data-grid';
|
|
3
|
+
import { GridApiCommunity } from '@mui/x-data-grid/internals';
|
|
4
|
+
import { Id, Item, SchemaType, BulkUpdateData, BulkDeleteData } from '../../../@types';
|
|
5
|
+
interface UseDataGridActionsProps {
|
|
6
|
+
apiRef: RefObject<GridApiCommunity>;
|
|
7
|
+
model: string;
|
|
8
|
+
schema: SchemaType;
|
|
9
|
+
emptyItem: Item;
|
|
10
|
+
dataGrid: {
|
|
11
|
+
data: Item[];
|
|
12
|
+
};
|
|
13
|
+
setDataGrid: (value: React.SetStateAction<{
|
|
14
|
+
data: Item[];
|
|
15
|
+
}>) => void;
|
|
16
|
+
setSelectionModel: (value: React.SetStateAction<Item[]>) => void;
|
|
17
|
+
setSelectionModelIds: (value: React.SetStateAction<GridRowId[]>) => void;
|
|
18
|
+
setSnackBar: (value: React.SetStateAction<Item>) => void;
|
|
19
|
+
setDataGridLoading: (value: boolean) => void;
|
|
20
|
+
onDataChange?: (p: Item[]) => void;
|
|
21
|
+
handleStartEditing: (p?: Id) => void;
|
|
22
|
+
tableAutoHeight?: boolean;
|
|
23
|
+
indexField: string;
|
|
24
|
+
defaultValues?: Item;
|
|
25
|
+
isRowEditing?: Id;
|
|
26
|
+
}
|
|
27
|
+
export declare const useDataGridActions: ({ apiRef, model, schema, emptyItem, dataGrid, setDataGrid, setSelectionModel, setSelectionModelIds, setSnackBar, setDataGridLoading, onDataChange, handleStartEditing, tableAutoHeight, indexField, defaultValues, isRowEditing, }: UseDataGridActionsProps) => {
|
|
28
|
+
handleAddItem: () => void;
|
|
29
|
+
bulkUpdateData: BulkUpdateData;
|
|
30
|
+
bulkDeleteData: BulkDeleteData;
|
|
31
|
+
bulkCreateData: (ids: Id[]) => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=useDataGridActions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDataGridActions.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/hooks/useDataGridActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIvF,UAAU,uBAAuB;IAC/B,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,QAAQ,EAAE;QAAE,IAAI,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC;IAC3B,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC;QAAE,IAAI,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC;IACrE,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IACjE,oBAAoB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC,KAAK,IAAI,CAAC;IACzE,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;IACzD,kBAAkB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,IAAI,CAAC;IACrB,YAAY,CAAC,EAAE,EAAE,CAAC;CACnB;AAED,eAAO,MAAM,kBAAkB,GAAI,oOAiBhC,uBAAuB;;;;0BAyJW,EAAE,EAAE;CAiBxC,CAAC"}
|
|
@@ -0,0 +1,170 @@
|
|
|
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.useDataGridActions = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const utils_1 = require("../../../utils");
|
|
18
|
+
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
19
|
+
const useDataGridActions = ({ apiRef, model, schema, emptyItem, dataGrid, setDataGrid, setSelectionModel, setSelectionModelIds, setSnackBar, setDataGridLoading, onDataChange, handleStartEditing, tableAutoHeight, indexField, defaultValues, isRowEditing, }) => {
|
|
20
|
+
const { rawDeleteData, rawUpdateDataBySchema } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
21
|
+
const handleAddItems = (n = 1) => {
|
|
22
|
+
const newRows = [];
|
|
23
|
+
for (let i = 0; i < n; i++) {
|
|
24
|
+
const id = (0, utils_1.getTmpId)();
|
|
25
|
+
newRows.push(Object.assign(Object.assign(Object.assign({}, emptyItem), defaultValues), { id }));
|
|
26
|
+
}
|
|
27
|
+
const newData = tableAutoHeight
|
|
28
|
+
? [...dataGrid.data, ...newRows]
|
|
29
|
+
: [...newRows, ...dataGrid.data];
|
|
30
|
+
if (onDataChange) {
|
|
31
|
+
onDataChange(newData);
|
|
32
|
+
}
|
|
33
|
+
setDataGrid({
|
|
34
|
+
data: newData,
|
|
35
|
+
});
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
let fieldToFocus = indexField;
|
|
38
|
+
if (!fieldToFocus) {
|
|
39
|
+
const visibleColumns = apiRef.current.getAllColumns();
|
|
40
|
+
const firstEditableCol = visibleColumns.find((col) => col.editable && col.field !== 'actions');
|
|
41
|
+
fieldToFocus = firstEditableCol === null || firstEditableCol === void 0 ? void 0 : firstEditableCol.field;
|
|
42
|
+
}
|
|
43
|
+
apiRef.current.startRowEditMode({ id: newRows[0].id, fieldToFocus });
|
|
44
|
+
handleStartEditing(newRows[0].id);
|
|
45
|
+
// apiRef.current.setCellFocus(newRows[0].id, fieldToFocus);
|
|
46
|
+
if (!tableAutoHeight) {
|
|
47
|
+
apiRef.current.scrollToIndexes({ rowIndex: 0 });
|
|
48
|
+
}
|
|
49
|
+
}, 100);
|
|
50
|
+
};
|
|
51
|
+
const handleAddItem = () => {
|
|
52
|
+
if (isRowEditing) {
|
|
53
|
+
if ((0, utils_1.isTmpId)(isRowEditing)) {
|
|
54
|
+
setSnackBar({
|
|
55
|
+
open: true,
|
|
56
|
+
severity: 'info',
|
|
57
|
+
msg: 'Adicione uma linha por vez',
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
apiRef.current.stopRowEditMode({ id: isRowEditing });
|
|
62
|
+
}
|
|
63
|
+
const id = (0, utils_1.getTmpId)();
|
|
64
|
+
const newRow = Object.assign(Object.assign(Object.assign({}, emptyItem), defaultValues), { id });
|
|
65
|
+
const newData = tableAutoHeight ? [...dataGrid.data, newRow] : [newRow, ...dataGrid.data];
|
|
66
|
+
if (onDataChange) {
|
|
67
|
+
onDataChange(newData);
|
|
68
|
+
}
|
|
69
|
+
setDataGrid({
|
|
70
|
+
data: newData,
|
|
71
|
+
});
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
let fieldToFocus = indexField;
|
|
74
|
+
if (!fieldToFocus) {
|
|
75
|
+
const visibleColumns = apiRef.current.getAllColumns();
|
|
76
|
+
const firstEditableCol = visibleColumns.find((col) => col.editable && col.field !== 'actions');
|
|
77
|
+
fieldToFocus = firstEditableCol === null || firstEditableCol === void 0 ? void 0 : firstEditableCol.field;
|
|
78
|
+
}
|
|
79
|
+
apiRef.current.startRowEditMode({ id, fieldToFocus });
|
|
80
|
+
handleStartEditing(id);
|
|
81
|
+
// apiRef.current.setCellFocus(id, fieldToFocus);
|
|
82
|
+
if (!tableAutoHeight) {
|
|
83
|
+
apiRef.current.scrollToIndexes({ rowIndex: 0 });
|
|
84
|
+
}
|
|
85
|
+
}, 100);
|
|
86
|
+
};
|
|
87
|
+
const bulkUpdateData = (newData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
|
+
const promises = [];
|
|
89
|
+
const ids = [];
|
|
90
|
+
newData.map((item) => {
|
|
91
|
+
promises.push(rawUpdateDataBySchema({
|
|
92
|
+
model,
|
|
93
|
+
modelObjectId: item.id,
|
|
94
|
+
data: item,
|
|
95
|
+
schema,
|
|
96
|
+
}));
|
|
97
|
+
ids.push(item.id);
|
|
98
|
+
});
|
|
99
|
+
const results = yield Promise.all(promises);
|
|
100
|
+
setSelectionModel([]);
|
|
101
|
+
setSelectionModelIds([]);
|
|
102
|
+
const updatedData = dataGrid.data.map((item) => {
|
|
103
|
+
const index = ids.indexOf(item.id);
|
|
104
|
+
return index === -1 ? item : newData[index];
|
|
105
|
+
});
|
|
106
|
+
if (onDataChange) {
|
|
107
|
+
onDataChange(updatedData);
|
|
108
|
+
}
|
|
109
|
+
setDataGrid({
|
|
110
|
+
data: updatedData,
|
|
111
|
+
});
|
|
112
|
+
setSnackBar({
|
|
113
|
+
open: true,
|
|
114
|
+
severity: 'success',
|
|
115
|
+
msg: 'Alterações salvas com sucesso',
|
|
116
|
+
});
|
|
117
|
+
return results.map((result, index) => {
|
|
118
|
+
return {
|
|
119
|
+
id: ids[index],
|
|
120
|
+
success: !axios_1.default.isAxiosError(result),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
const bulkDeleteData = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
const promises = [];
|
|
126
|
+
ids.map((id) => {
|
|
127
|
+
promises.push(rawDeleteData(model, id));
|
|
128
|
+
});
|
|
129
|
+
setDataGridLoading(true);
|
|
130
|
+
const results = yield Promise.all(promises);
|
|
131
|
+
setSelectionModel([]);
|
|
132
|
+
setSelectionModelIds([]);
|
|
133
|
+
const newData = dataGrid.data.filter(({ id }) => !ids.includes(id));
|
|
134
|
+
if (onDataChange) {
|
|
135
|
+
onDataChange(newData);
|
|
136
|
+
}
|
|
137
|
+
setDataGrid({
|
|
138
|
+
data: newData,
|
|
139
|
+
});
|
|
140
|
+
setDataGridLoading(false);
|
|
141
|
+
setSnackBar({
|
|
142
|
+
open: true,
|
|
143
|
+
severity: 'success',
|
|
144
|
+
msg: 'Itens apagados com sucesso',
|
|
145
|
+
});
|
|
146
|
+
return results.map((result, index) => {
|
|
147
|
+
return {
|
|
148
|
+
id: ids[index],
|
|
149
|
+
success: result === true,
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
const bulkCreateData = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
154
|
+
handleAddItems(ids.length);
|
|
155
|
+
setSelectionModel([]);
|
|
156
|
+
setSelectionModelIds([]);
|
|
157
|
+
setSnackBar({
|
|
158
|
+
open: true,
|
|
159
|
+
severity: 'success',
|
|
160
|
+
msg: 'Linhas adicionadas com sucesso',
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
return {
|
|
164
|
+
handleAddItem,
|
|
165
|
+
bulkUpdateData,
|
|
166
|
+
bulkDeleteData,
|
|
167
|
+
bulkCreateData,
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
exports.useDataGridActions = useDataGridActions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaType, OptionsAC, GridEnrichedBySchemaColDef } from '../../../@types';
|
|
2
|
+
interface UseOptionsACProps {
|
|
3
|
+
columns: GridEnrichedBySchemaColDef[];
|
|
4
|
+
schema: SchemaType;
|
|
5
|
+
optionsACExternal?: OptionsAC;
|
|
6
|
+
indexField?: string;
|
|
7
|
+
addExistingModel?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const useOptionsAC: ({ columns, schema, optionsACExternal, indexField, addExistingModel, }: UseOptionsACProps) => {
|
|
10
|
+
optionsAC: OptionsAC;
|
|
11
|
+
updateOptionsAC: () => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=useOptionsAC.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOptionsAC.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/hooks/useOptionsAC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAGpF,UAAU,iBAAiB;IACzB,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,YAAY,GAAI,uEAM1B,iBAAiB;;;CAiDnB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
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.useOptionsAC = void 0;
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
19
|
+
const useOptionsAC = ({ columns, schema, optionsACExternal, indexField, addExistingModel, }) => {
|
|
20
|
+
const { getAutoComplete } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
21
|
+
const [optionsAC, setOptionsAC] = (0, react_1.useState)({});
|
|
22
|
+
const updateOptionsAC = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
const newOptionsAC = {};
|
|
25
|
+
for (const col of columns) {
|
|
26
|
+
if (optionsACExternal && col.field in optionsACExternal) {
|
|
27
|
+
newOptionsAC[col.field] = optionsACExternal[col.field];
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (!schema[col.field]) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const fieldSchema = schema[col.field];
|
|
34
|
+
if (['field', 'nested object'].includes(fieldSchema.type) && !(col.field in newOptionsAC)) {
|
|
35
|
+
const options = yield getAutoComplete(col.field);
|
|
36
|
+
if (!axios_1.default.isAxiosError(options)) {
|
|
37
|
+
newOptionsAC[col.field] = options;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
console.log(`Couldn't load autocomplete options from '${col.field}'`);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (fieldSchema.type === 'choice' && !(col.field in newOptionsAC)) {
|
|
44
|
+
newOptionsAC[col.field] = fieldSchema.choices || [];
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (fieldSchema.type === 'list' && !(col.field in newOptionsAC)) {
|
|
48
|
+
newOptionsAC[col.field] = ((_a = fieldSchema.child) === null || _a === void 0 ? void 0 : _a.choices) || [];
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (col.field === indexField && addExistingModel && !newOptionsAC[col.field]) {
|
|
52
|
+
const options = yield getAutoComplete(addExistingModel);
|
|
53
|
+
if (!axios_1.default.isAxiosError(options)) {
|
|
54
|
+
newOptionsAC[col.field] = options;
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
setOptionsAC(newOptionsAC);
|
|
60
|
+
}), [columns, schema, optionsACExternal, indexField, addExistingModel]);
|
|
61
|
+
(0, react_1.useEffect)(() => {
|
|
62
|
+
updateOptionsAC();
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
}, [columns]);
|
|
65
|
+
return { optionsAC, updateOptionsAC };
|
|
66
|
+
};
|
|
67
|
+
exports.useOptionsAC = useOptionsAC;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GridEnrichedBySchemaColDef } from '../../../@types';
|
|
2
|
+
import { BuildPreparedColumnsProps } from '../utils/columnFactory';
|
|
3
|
+
export declare const usePreparedColumns: ({ schema, columns, isEditable, actions, LinkComponent, stateToLink, validationErrors, optionsAC, onEditModel, customFieldFormLayouts, setDialog, indexField, indexFieldMinWidth, minWidth, customColumnOperations, customLinkDestination, indexFieldBasePath, }: Omit<BuildPreparedColumnsProps, "columns" | "serverEndPoint"> & {
|
|
4
|
+
columns: GridEnrichedBySchemaColDef[];
|
|
5
|
+
}) => {
|
|
6
|
+
preparedColumns: any[] | null;
|
|
7
|
+
setPreparedColumns: import("react").Dispatch<import("react").SetStateAction<any[] | null>>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=usePreparedColumns.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePreparedColumns.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/hooks/usePreparedColumns.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAwB,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAGzF,eAAO,MAAM,kBAAkB,GAAI,iQAkBhC,IAAI,CAAC,yBAAyB,EAAE,SAAS,GAAG,gBAAgB,CAAC,GAAG;IACjE,OAAO,EAAE,0BAA0B,EAAE,CAAC;CACvC;;;CAqDA,CAAC"}
|