drf-react-by-schema 0.28.8 → 0.28.9
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 +410 -0
- package/dist/@types/index.d.ts.map +1 -0
- package/dist/@types/index.js +9 -0
- package/dist/@types/string-mask.d.ts +10 -0
- package/dist/@types/string-mask.d.ts.map +1 -0
- package/dist/@types/string-mask.js +1 -0
- package/dist/api.d.ts +81 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +1118 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts +8 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/BooleanInputCell.js +86 -0
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts +12 -0
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/ConditionalEditWrapper.js +71 -0
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts +9 -0
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/ConfirmDialog.js +21 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts +26 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/CustomToolbar.js +146 -0
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts +73 -0
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/DataGridDesktop.js +421 -0
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts +18 -0
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/DataGridMobile.js +105 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts +11 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/FileInputCell.js +155 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts +12 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/FooterToolbar.js +36 -0
- package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts +10 -0
- package/dist/components/DataGridBySchemaEditable/GeoEditCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GeoEditCell.js +85 -0
- package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts +11 -0
- package/dist/components/DataGridBySchemaEditable/GeoThumbCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GeoThumbCell.js +87 -0
- package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts +18 -0
- package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridActionsCellItemLink.js +24 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts +8 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDateInput.js +166 -0
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts +6 -0
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDateTimeInput.js +154 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts +10 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridDecimalInput.js +78 -0
- 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 +7 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/GridPatternInput.js +74 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts +21 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/InputInterval.js +131 -0
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts +9 -0
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/MobileSearchBar.js +70 -0
- package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts +7 -0
- package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/RowEditingWatcher.js +41 -0
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts +24 -0
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +259 -0
- package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts +5 -0
- package/dist/components/DataGridBySchemaEditable/geoConstants.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/geoConstants.js +6 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts +33 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useDataGridActions.js +161 -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 +69 -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 +73 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts +30 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +199 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts +33 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +270 -0
- package/dist/components/DataGridBySchemaEditable/utils.d.ts +40 -0
- package/dist/components/DataGridBySchemaEditable/utils.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable/utils.js +181 -0
- package/dist/components/DataGridBySchemaEditable.d.ts +64 -0
- package/dist/components/DataGridBySchemaEditable.d.ts.map +1 -0
- package/dist/components/DataGridBySchemaEditable.js +172 -0
- package/dist/components/DataTotals.d.ts +12 -0
- package/dist/components/DataTotals.d.ts.map +1 -0
- package/dist/components/DataTotals.js +32 -0
- package/dist/components/DataTotalsServer.d.ts +10 -0
- package/dist/components/DataTotalsServer.d.ts.map +1 -0
- package/dist/components/DataTotalsServer.js +18 -0
- package/dist/components/DialogActions.d.ts +11 -0
- package/dist/components/DialogActions.d.ts.map +1 -0
- package/dist/components/DialogActions.js +20 -0
- package/dist/components/FileTypeIcon.d.ts +18 -0
- package/dist/components/FileTypeIcon.d.ts.map +1 -0
- package/dist/components/FileTypeIcon.js +48 -0
- package/dist/components/GenericModelList.d.ts +53 -0
- package/dist/components/GenericModelList.d.ts.map +1 -0
- package/dist/components/GenericModelList.js +194 -0
- package/dist/components/GenericRelatedModelList.d.ts +55 -0
- package/dist/components/GenericRelatedModelList.d.ts.map +1 -0
- package/dist/components/GenericRelatedModelList.js +181 -0
- package/dist/components/GenericRelatedModelListTable.d.ts +56 -0
- package/dist/components/GenericRelatedModelListTable.d.ts.map +1 -0
- package/dist/components/GenericRelatedModelListTable.js +31 -0
- package/dist/components/Image.d.ts +10 -0
- package/dist/components/Image.d.ts.map +1 -0
- package/dist/components/Image.js +111 -0
- package/dist/components/details/DetailBySchema.d.ts +4 -0
- package/dist/components/details/DetailBySchema.d.ts.map +1 -0
- package/dist/components/details/DetailBySchema.js +175 -0
- package/dist/components/details/DetailFieldBySchema.d.ts +4 -0
- package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -0
- package/dist/components/details/DetailFieldBySchema.js +88 -0
- package/dist/components/forms/ChangePasswordForm.d.ts +7 -0
- package/dist/components/forms/ChangePasswordForm.d.ts.map +1 -0
- package/dist/components/forms/ChangePasswordForm.js +93 -0
- package/dist/components/forms/DialogFormBySchema.d.ts +22 -0
- package/dist/components/forms/DialogFormBySchema.d.ts.map +1 -0
- package/dist/components/forms/DialogFormBySchema.js +97 -0
- package/dist/components/forms/FieldBySchema.d.ts +4 -0
- package/dist/components/forms/FieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/FieldBySchema.js +80 -0
- package/dist/components/forms/ForgotPasswordForm.d.ts +11 -0
- package/dist/components/forms/ForgotPasswordForm.d.ts.map +1 -0
- package/dist/components/forms/ForgotPasswordForm.js +114 -0
- package/dist/components/forms/Form.d.ts +61 -0
- package/dist/components/forms/Form.d.ts.map +1 -0
- package/dist/components/forms/Form.js +264 -0
- package/dist/components/forms/FormActions.d.ts +20 -0
- package/dist/components/forms/FormActions.d.ts.map +1 -0
- package/dist/components/forms/FormActions.js +55 -0
- package/dist/components/forms/FormBySchema.d.ts +21 -0
- package/dist/components/forms/FormBySchema.d.ts.map +1 -0
- package/dist/components/forms/FormBySchema.js +280 -0
- package/dist/components/forms/FormWatcher.d.ts +10 -0
- package/dist/components/forms/FormWatcher.d.ts.map +1 -0
- package/dist/components/forms/FormWatcher.js +25 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +13 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +133 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/BooleanFieldBySchema.js +39 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts +5 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/DesktopDatePickerBySchema.js +54 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts +5 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/DesktopDateTimePickerBySchema.js +47 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts +14 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +272 -0
- package/dist/components/forms/inputs/FileFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/FileFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/FileFieldBySchema.js +144 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/FloatFieldBySchema.js +64 -0
- package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts +8 -0
- package/dist/components/forms/inputs/GeometryFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/GeometryFieldBySchema.js +61 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts +19 -0
- package/dist/components/forms/inputs/MapGeometryPicker.d.ts.map +1 -0
- package/dist/components/forms/inputs/MapGeometryPicker.js +344 -0
- package/dist/components/forms/inputs/PatternFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/PatternFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/PatternFieldBySchema.js +56 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts +4 -0
- package/dist/components/forms/inputs/TextFieldBySchema.d.ts.map +1 -0
- package/dist/components/forms/inputs/TextFieldBySchema.js +56 -0
- package/dist/components/forms/inputs/leafletMarker.d.ts +12 -0
- package/dist/components/forms/inputs/leafletMarker.d.ts.map +1 -0
- package/dist/components/forms/inputs/leafletMarker.js +52 -0
- package/dist/context/APIWrapper.d.ts +18 -0
- package/dist/context/APIWrapper.d.ts.map +1 -0
- package/dist/context/APIWrapper.js +593 -0
- package/dist/context/APIWrapperContext.d.ts +132 -0
- package/dist/context/APIWrapperContext.d.ts.map +1 -0
- package/dist/context/APIWrapperContext.js +63 -0
- package/dist/context/DRFReactBySchemaContext.d.ts +31 -0
- package/dist/context/DRFReactBySchemaContext.d.ts.map +1 -0
- package/dist/context/DRFReactBySchemaContext.js +20 -0
- package/dist/context/DRFReactBySchemaProvider.d.ts +5 -0
- package/dist/context/DRFReactBySchemaProvider.d.ts.map +1 -0
- package/dist/context/DRFReactBySchemaProvider.js +105 -0
- package/dist/context/Overlays.d.ts +5 -0
- package/dist/context/Overlays.d.ts.map +1 -0
- package/dist/context/Overlays.js +114 -0
- package/dist/context/PrivateContext.d.ts +10 -0
- package/dist/context/PrivateContext.d.ts.map +1 -0
- package/dist/context/PrivateContext.js +16 -0
- package/dist/hooks/useDeepMemo.d.ts +2 -0
- package/dist/hooks/useDeepMemo.d.ts.map +1 -0
- package/dist/hooks/useDeepMemo.js +13 -0
- package/dist/hooks/useWhyDidYouUpdate.d.ts +4 -0
- package/dist/hooks/useWhyDidYouUpdate.d.ts.map +1 -0
- package/dist/hooks/useWhyDidYouUpdate.js +26 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/styles/grid.d.ts +3 -0
- package/dist/styles/grid.d.ts.map +1 -0
- package/dist/styles/grid.js +38 -0
- package/dist/styles/index.d.ts +3 -0
- package/dist/styles/index.d.ts.map +1 -0
- package/dist/styles/index.js +38 -0
- package/dist/styles/layout.d.ts +23 -0
- package/dist/styles/layout.d.ts.map +1 -0
- package/dist/styles/layout.js +71 -0
- package/dist/styles/texts.d.ts +66 -0
- package/dist/styles/texts.d.ts.map +1 -0
- package/dist/styles/texts.js +73 -0
- package/dist/styles/theme.d.ts +29 -0
- package/dist/styles/theme.d.ts.map +1 -0
- package/dist/styles/theme.js +226 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +17 -0
- package/dist/utils/utils.d.ts +107 -0
- package/dist/utils/utils.d.ts.map +1 -0
- package/dist/utils/utils.js +957 -0
- package/package.json +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.usePreparedColumns = void 0;
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const columnFactory_1 = require("../utils/columnFactory");
|
|
15
|
+
const DRFReactBySchemaContext_1 = require("../../../context/DRFReactBySchemaContext");
|
|
16
|
+
const utils_1 = require("../../../utils");
|
|
17
|
+
const usePreparedColumns = ({ apiRef, schema, columns, isEditable, actions, LinkComponent, stateToLink, validationErrors, optionsAC, onEditModel, customFieldFormLayouts, setDialog, indexField, indexFieldMinWidth, minWidth, customColumnOperations, customLinkDestination, indexFieldBasePath, }) => {
|
|
18
|
+
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
19
|
+
const [preparedColumns, setPreparedColumns] = (0, react_1.useState)(null);
|
|
20
|
+
const conditionalVisible = (0, react_1.useMemo)(() => (0, utils_1.buildConditionalVisibleBySchema)(schema), [schema]);
|
|
21
|
+
(0, react_1.useEffect)(() => {
|
|
22
|
+
const updateColumns = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
if (serverEndPoint) {
|
|
24
|
+
const cols = yield (0, columnFactory_1.buildPreparedColumns)({
|
|
25
|
+
apiRef,
|
|
26
|
+
schema,
|
|
27
|
+
columns,
|
|
28
|
+
isEditable,
|
|
29
|
+
actions,
|
|
30
|
+
LinkComponent,
|
|
31
|
+
stateToLink,
|
|
32
|
+
validationErrors,
|
|
33
|
+
optionsAC,
|
|
34
|
+
onEditModel,
|
|
35
|
+
customFieldFormLayouts,
|
|
36
|
+
setDialog,
|
|
37
|
+
indexField,
|
|
38
|
+
indexFieldMinWidth,
|
|
39
|
+
minWidth,
|
|
40
|
+
customColumnOperations,
|
|
41
|
+
customLinkDestination,
|
|
42
|
+
indexFieldBasePath,
|
|
43
|
+
conditionalVisible,
|
|
44
|
+
serverEndPoint,
|
|
45
|
+
});
|
|
46
|
+
setPreparedColumns(cols);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
updateColumns();
|
|
50
|
+
}, [
|
|
51
|
+
schema,
|
|
52
|
+
columns,
|
|
53
|
+
isEditable,
|
|
54
|
+
actions,
|
|
55
|
+
LinkComponent,
|
|
56
|
+
stateToLink,
|
|
57
|
+
validationErrors,
|
|
58
|
+
optionsAC,
|
|
59
|
+
// onEditModel,
|
|
60
|
+
customFieldFormLayouts,
|
|
61
|
+
// setDialog,
|
|
62
|
+
indexField,
|
|
63
|
+
indexFieldMinWidth,
|
|
64
|
+
minWidth,
|
|
65
|
+
customColumnOperations,
|
|
66
|
+
customLinkDestination,
|
|
67
|
+
indexFieldBasePath,
|
|
68
|
+
conditionalVisible,
|
|
69
|
+
serverEndPoint,
|
|
70
|
+
]);
|
|
71
|
+
return { preparedColumns, setPreparedColumns };
|
|
72
|
+
};
|
|
73
|
+
exports.usePreparedColumns = usePreparedColumns;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AnySchema } from 'yup';
|
|
2
|
+
import { GridRowId } from '@mui/x-data-grid';
|
|
3
|
+
import { GridApiCommunity } from '@mui/x-data-grid/models/api/gridApiCommunity';
|
|
4
|
+
import { RefObject } from 'react';
|
|
5
|
+
import { Item, SchemaType, Id, ExtraValidators, OnEditModelType, GridEnrichedBySchemaColDef, FieldKey, TField } from '../../../@types';
|
|
6
|
+
interface UseProcessRowUpdateProps<T extends TField = void> {
|
|
7
|
+
preparedColumns: GridEnrichedBySchemaColDef<T>[] | null;
|
|
8
|
+
yupValidationSchema: AnySchema | null;
|
|
9
|
+
setDataGridLoading: (value: boolean) => void;
|
|
10
|
+
indexField: FieldKey<T>;
|
|
11
|
+
processingRow: React.RefObject<number | string | null>;
|
|
12
|
+
setValidationErrors: React.Dispatch<React.SetStateAction<Record<GridRowId, Record<string, string>>>>;
|
|
13
|
+
modelParent?: string;
|
|
14
|
+
modelParentId?: Id;
|
|
15
|
+
model: string;
|
|
16
|
+
schema: SchemaType<T>;
|
|
17
|
+
addExistingModel?: string;
|
|
18
|
+
updateOptionsAC: () => Promise<void>;
|
|
19
|
+
apiRef: RefObject<GridApiCommunity>;
|
|
20
|
+
setDataGridRows: (value: React.SetStateAction<Item<T>[]>) => void;
|
|
21
|
+
onProcessRow?: (p?: Item<T>) => void;
|
|
22
|
+
handleStopEditing: () => void;
|
|
23
|
+
extraValidators?: ExtraValidators<T>;
|
|
24
|
+
onEditModel?: (p: OnEditModelType<T>) => void;
|
|
25
|
+
}
|
|
26
|
+
export declare const useProcessRowUpdate: <T extends TField = void>({ preparedColumns, yupValidationSchema, setDataGridLoading, indexField, processingRow, setValidationErrors, modelParent, modelParentId, model, schema, addExistingModel, updateOptionsAC, apiRef, setDataGridRows, onProcessRow, handleStopEditing, }: UseProcessRowUpdateProps<T>) => {
|
|
27
|
+
processRowUpdate: (editedRow: Item<T>, originalRow: Item<T>) => Promise<Item<T>>;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=useProcessRowUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useProcessRowUpdate.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAmB,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EACL,IAAI,EACJ,UAAU,EACV,EAAE,EACF,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,QAAQ,EACR,MAAM,EACP,MAAM,iBAAiB,CAAC;AAUzB,UAAU,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACxD,eAAe,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;IACxD,mBAAmB,EAAE,SAAS,GAAG,IAAI,CAAC;IACtC,kBAAkB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACxB,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CACjC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAChE,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACpC,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IAClE,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACrC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC/C;AAED,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,uPAkB1D,wBAAwB,CAAC,CAAC,CAAC;kCAEe,IAAI,CAAC,CAAC,CAAC,eAAe,IAAI,CAAC,CAAC,CAAC;CAoMzE,CAAC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
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.useProcessRowUpdate = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const utils_1 = require("../../../utils");
|
|
18
|
+
const APIWrapperContext_1 = require("../../../context/APIWrapperContext");
|
|
19
|
+
const utils_2 = require("../utils");
|
|
20
|
+
// import { buildEditPath } from '../utils'; // TODO: Check Why it is missing here
|
|
21
|
+
function isYupValidationError(err) {
|
|
22
|
+
return err instanceof Error && err.name === 'ValidationError';
|
|
23
|
+
}
|
|
24
|
+
const useProcessRowUpdate = ({ preparedColumns, yupValidationSchema, setDataGridLoading, indexField, processingRow, setValidationErrors, modelParent, modelParentId, model, schema, addExistingModel, updateOptionsAC, apiRef, setDataGridRows, onProcessRow, handleStopEditing,
|
|
25
|
+
// extraValidators, // TODO: Check why this is missing
|
|
26
|
+
}) => {
|
|
27
|
+
const { onEditRelatedModelSave, onEditModelDataGridSave } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
28
|
+
function processRowUpdate(editedRow, originalRow) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
var _a, _b;
|
|
31
|
+
// const originalRow = dataGrid.data.find((r) => r.id === editedRow.id);
|
|
32
|
+
if (originalRow && JSON.stringify(originalRow) === JSON.stringify(editedRow)) {
|
|
33
|
+
console.log('No changes detected, skipping save.');
|
|
34
|
+
handleStopEditing();
|
|
35
|
+
if ((0, utils_1.isTmpId)(editedRow.id)) {
|
|
36
|
+
(0, utils_2.deleteRow)({ id: editedRow.id, apiRef, setDataGridRows });
|
|
37
|
+
throw new Error('CANCEL_TMP_ROW');
|
|
38
|
+
}
|
|
39
|
+
return editedRow;
|
|
40
|
+
}
|
|
41
|
+
if (!preparedColumns || !yupValidationSchema) {
|
|
42
|
+
return originalRow;
|
|
43
|
+
}
|
|
44
|
+
setDataGridLoading(true);
|
|
45
|
+
const indexCol = preparedColumns.find((col) => col.field === indexField);
|
|
46
|
+
processingRow.current = editedRow.id;
|
|
47
|
+
try {
|
|
48
|
+
yield yupValidationSchema.validate(editedRow, { abortEarly: false });
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (isYupValidationError(err)) {
|
|
52
|
+
const rowErrors = {};
|
|
53
|
+
err.inner.forEach((e) => {
|
|
54
|
+
if (e.path) {
|
|
55
|
+
rowErrors[e.path] = e.message;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
rowErrors['campo desconhecido'] = e.message;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
setValidationErrors((prev) => (Object.assign(Object.assign({}, prev), { [editedRow.id]: rowErrors })));
|
|
62
|
+
err.message = Object.entries(rowErrors)
|
|
63
|
+
.map(([field, message]) => `${field}: ${message}`)
|
|
64
|
+
.join('; ');
|
|
65
|
+
}
|
|
66
|
+
setDataGridLoading(false);
|
|
67
|
+
throw err;
|
|
68
|
+
}
|
|
69
|
+
const indexValue = indexField ? editedRow[indexField] : undefined;
|
|
70
|
+
const onlyAddExisting = (0, utils_1.isTmpId)(editedRow.id) &&
|
|
71
|
+
indexValue &&
|
|
72
|
+
!(0, utils_1.isTmpId)(indexValue.id) &&
|
|
73
|
+
(!indexCol || !indexCol.valueFormatter);
|
|
74
|
+
const createNewItem = indexField && (0, utils_1.isTmpId)(editedRow.id) && indexValue && (0, utils_1.isTmpId)(indexValue.id);
|
|
75
|
+
if (onlyAddExisting) {
|
|
76
|
+
const row = {};
|
|
77
|
+
row.id_to_add = indexValue.id;
|
|
78
|
+
for (const [key, value] of Object.entries(indexValue)) {
|
|
79
|
+
if (key === 'id') {
|
|
80
|
+
row[key] = editedRow.id;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
row[key] = value;
|
|
84
|
+
}
|
|
85
|
+
editedRow = Object.assign({}, row);
|
|
86
|
+
}
|
|
87
|
+
if (createNewItem && indexValue) {
|
|
88
|
+
if (indexValue.inputValue) {
|
|
89
|
+
editedRow[indexField] = indexValue.inputValue;
|
|
90
|
+
}
|
|
91
|
+
if (addExistingModel) {
|
|
92
|
+
editedRow[indexField] = indexValue.label;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (modelParent && modelParentId && onEditRelatedModelSave) {
|
|
96
|
+
const response = yield onEditRelatedModelSave({
|
|
97
|
+
model: modelParent,
|
|
98
|
+
id: modelParentId,
|
|
99
|
+
relatedModel: model,
|
|
100
|
+
relatedModelId: editedRow.id,
|
|
101
|
+
newRow: editedRow,
|
|
102
|
+
schema,
|
|
103
|
+
onlyAddExisting,
|
|
104
|
+
});
|
|
105
|
+
if (axios_1.default.isAxiosError(response)) {
|
|
106
|
+
let errorMessage = 'Erro desconhecido no servidor';
|
|
107
|
+
if (((_a = response.response) === null || _a === void 0 ? void 0 : _a.data) &&
|
|
108
|
+
typeof response.response.data === 'object' &&
|
|
109
|
+
!Array.isArray(response.response.data)) {
|
|
110
|
+
const backendErrors = response.response.data;
|
|
111
|
+
const rowErrors = {};
|
|
112
|
+
Object.keys(backendErrors).forEach((field) => {
|
|
113
|
+
const msgs = backendErrors[field];
|
|
114
|
+
if (Array.isArray(msgs)) {
|
|
115
|
+
rowErrors[field] = msgs.join(', ');
|
|
116
|
+
}
|
|
117
|
+
else if (typeof msgs === 'string') {
|
|
118
|
+
rowErrors[field] = msgs;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
setValidationErrors((prev) => (Object.assign(Object.assign({}, prev), { [editedRow.id]: rowErrors })));
|
|
122
|
+
errorMessage = Object.entries(rowErrors)
|
|
123
|
+
.map(([field, message]) => `${field}: ${message}`)
|
|
124
|
+
.join('; ');
|
|
125
|
+
}
|
|
126
|
+
setDataGridLoading(false);
|
|
127
|
+
throw new Error(errorMessage);
|
|
128
|
+
}
|
|
129
|
+
if (onlyAddExisting || createNewItem || !onlyAddExisting) {
|
|
130
|
+
setValidationErrors((prev) => {
|
|
131
|
+
const newState = Object.assign({}, prev);
|
|
132
|
+
delete newState[editedRow.id];
|
|
133
|
+
return newState;
|
|
134
|
+
});
|
|
135
|
+
updateOptionsAC();
|
|
136
|
+
const newRow = (0, utils_1.enrichChoices)('data' in response && 'schema' in response ? response.data : response, schema);
|
|
137
|
+
if (onProcessRow) {
|
|
138
|
+
onProcessRow(newRow);
|
|
139
|
+
}
|
|
140
|
+
(0, utils_2.updateRow)({
|
|
141
|
+
newRow: newRow,
|
|
142
|
+
apiRef,
|
|
143
|
+
originalId: editedRow.id,
|
|
144
|
+
setDataGridRows,
|
|
145
|
+
});
|
|
146
|
+
setDataGridLoading(false);
|
|
147
|
+
handleStopEditing();
|
|
148
|
+
return newRow;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const response = yield onEditModelDataGridSave({
|
|
152
|
+
model,
|
|
153
|
+
id: editedRow.id,
|
|
154
|
+
newRow: editedRow,
|
|
155
|
+
schema,
|
|
156
|
+
});
|
|
157
|
+
if (axios_1.default.isAxiosError(response)) {
|
|
158
|
+
// Map DRF field validation errors (e.g. raised in a serializer's
|
|
159
|
+
// `validate()`) onto the corresponding cells of the edited row, so they
|
|
160
|
+
// show the message under each field, just like a yup error. Only keys
|
|
161
|
+
// present in the schema are mapped (they match the grid columns).
|
|
162
|
+
const fieldErrors = (0, utils_1.getFieldErrorsFromResponse)((_b = response.response) === null || _b === void 0 ? void 0 : _b.data, schema);
|
|
163
|
+
const rowErrors = {};
|
|
164
|
+
Object.entries(fieldErrors).forEach(([field, { message }]) => {
|
|
165
|
+
rowErrors[field] = message;
|
|
166
|
+
});
|
|
167
|
+
if (Object.keys(rowErrors).length > 0) {
|
|
168
|
+
setValidationErrors((prev) => (Object.assign(Object.assign({}, prev), { [editedRow.id]: rowErrors })));
|
|
169
|
+
}
|
|
170
|
+
const errorMessage = Object.entries(rowErrors)
|
|
171
|
+
.map(([field, message]) => `${field}: ${message}`)
|
|
172
|
+
.join('; ');
|
|
173
|
+
setDataGridLoading(false);
|
|
174
|
+
throw new Error(errorMessage || 'Erro desconhecido no servidor');
|
|
175
|
+
}
|
|
176
|
+
setValidationErrors((prev) => {
|
|
177
|
+
const newState = Object.assign({}, prev);
|
|
178
|
+
delete newState[editedRow.id];
|
|
179
|
+
return newState;
|
|
180
|
+
});
|
|
181
|
+
updateOptionsAC();
|
|
182
|
+
const newRow = (0, utils_1.enrichChoices)('data' in response && 'schema' in response ? response.data : response, schema);
|
|
183
|
+
(0, utils_2.updateRow)({
|
|
184
|
+
newRow,
|
|
185
|
+
originalId: editedRow.id,
|
|
186
|
+
apiRef,
|
|
187
|
+
setDataGridRows,
|
|
188
|
+
});
|
|
189
|
+
if (onProcessRow) {
|
|
190
|
+
onProcessRow(newRow);
|
|
191
|
+
}
|
|
192
|
+
setDataGridLoading(false);
|
|
193
|
+
handleStopEditing();
|
|
194
|
+
return newRow;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return { processRowUpdate };
|
|
198
|
+
};
|
|
199
|
+
exports.useProcessRowUpdate = useProcessRowUpdate;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { GridRowId, GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
|
+
import { GridApiCommunity } from '@mui/x-data-grid/internals';
|
|
4
|
+
import { SchemaType, GridEnrichedBySchemaColDef, OptionsAC, OnEditModelType, CustomAction, LinkComponentType, CustomFormFieldLayouts, FieldKey, CustomColumnOperations, RowAction, TField, ConditionalVisible } from '../../../@types';
|
|
5
|
+
import { DialogType } from '../../../context/APIWrapperContext';
|
|
6
|
+
import { ServerEndPoint } from '../../../context/DRFReactBySchemaContext';
|
|
7
|
+
export interface BuildPreparedColumnsProps<T extends TField = void> {
|
|
8
|
+
apiRef: RefObject<GridApiCommunity>;
|
|
9
|
+
schema: SchemaType<T>;
|
|
10
|
+
columns: GridEnrichedBySchemaColDef<T>[];
|
|
11
|
+
isEditable: boolean;
|
|
12
|
+
actions: RowAction<T>[];
|
|
13
|
+
customActions?: CustomAction[];
|
|
14
|
+
LinkComponent?: LinkComponentType;
|
|
15
|
+
indexFieldBasePath: string;
|
|
16
|
+
conditionalVisible: ConditionalVisible[];
|
|
17
|
+
indexFieldViewBasePath?: string;
|
|
18
|
+
stateToLink: object;
|
|
19
|
+
validationErrors: Record<GridRowId, Record<string, string>>;
|
|
20
|
+
optionsAC: OptionsAC<T>;
|
|
21
|
+
onEditModel?: (p: OnEditModelType<T>) => void;
|
|
22
|
+
customFieldFormLayouts?: CustomFormFieldLayouts<T>;
|
|
23
|
+
setDialog: (newState: Partial<DialogType> | null) => void;
|
|
24
|
+
indexField: FieldKey<T>;
|
|
25
|
+
addExistingModel?: string;
|
|
26
|
+
indexFieldMinWidth: number;
|
|
27
|
+
minWidth: number;
|
|
28
|
+
customColumnOperations?: CustomColumnOperations<T>;
|
|
29
|
+
customLinkDestination?: (p: GridRenderCellParams) => string;
|
|
30
|
+
serverEndPoint: ServerEndPoint;
|
|
31
|
+
}
|
|
32
|
+
export declare function buildPreparedColumns<T extends TField = void>({ apiRef, schema, columns, isEditable, actions, LinkComponent, stateToLink, validationErrors, optionsAC, onEditModel, customFieldFormLayouts, setDialog, indexField, indexFieldMinWidth, minWidth, customColumnOperations, customLinkDestination, indexFieldBasePath, conditionalVisible, serverEndPoint, }: BuildPreparedColumnsProps<T>): Promise<GridEnrichedBySchemaColDef<T>[]>;
|
|
33
|
+
//# sourceMappingURL=columnFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnFactory.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/utils/columnFactory.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKzC,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAA4B,MAAM,kBAAkB,CAAC;AAC7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EACL,UAAU,EACV,0BAA0B,EAC1B,SAAS,EACT,eAAe,EAEf,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,QAAQ,EACR,sBAAsB,EACtB,SAAS,EACT,MAAM,EACN,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAmB1E,MAAM,WAAW,yBAAyB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IAChE,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACpC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,kBAAkB,EAAE,kBAAkB,EAAE,CAAC;IACzC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5D,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACxB,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC9C,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACnD,SAAS,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,KAAK,IAAI,CAAC;IAC1D,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACnD,qBAAqB,CAAC,EAAE,CAAC,CAAC,EAAE,oBAAoB,KAAK,MAAM,CAAC;IAC5D,cAAc,EAAE,cAAc,CAAC;CAChC;AA4BD,wBAAsB,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAClE,MAAM,EACN,MAAM,EACN,OAAO,EACP,UAAU,EACV,OAAO,EACP,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,sBAAsB,EACtB,SAAS,EACT,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,sBAAsB,EACtB,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,GACf,EAAE,yBAAyB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,CAAC,CA2WzE"}
|
|
@@ -0,0 +1,270 @@
|
|
|
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.buildPreparedColumns = buildPreparedColumns;
|
|
16
|
+
const react_1 = __importDefault(require("react"));
|
|
17
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
18
|
+
const string_mask_1 = __importDefault(require("string-mask"));
|
|
19
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
20
|
+
const Stack_1 = __importDefault(require("@mui/material/Stack"));
|
|
21
|
+
const utils_1 = require("../../../utils");
|
|
22
|
+
const utils_2 = require("../utils");
|
|
23
|
+
const geoConstants_1 = require("../geoConstants");
|
|
24
|
+
const SelectEditInputCell_1 = __importDefault(require("../SelectEditInputCell"));
|
|
25
|
+
const GridDateInput_1 = __importDefault(require("../GridDateInput"));
|
|
26
|
+
const GridDateTimeInput_1 = __importDefault(require("../GridDateTimeInput"));
|
|
27
|
+
const GridDecimalInput_1 = __importDefault(require("../GridDecimalInput"));
|
|
28
|
+
const BooleanInputCell_1 = __importDefault(require("../BooleanInputCell"));
|
|
29
|
+
const FileInputCell_1 = __importDefault(require("../FileInputCell"));
|
|
30
|
+
const GridGenericInput_1 = __importDefault(require("../GridGenericInput"));
|
|
31
|
+
const GridPatternInput_1 = __importDefault(require("../GridPatternInput"));
|
|
32
|
+
const GeoThumbCell_1 = __importDefault(require("../GeoThumbCell"));
|
|
33
|
+
const GeoEditCell_1 = __importDefault(require("../GeoEditCell"));
|
|
34
|
+
const FileTypeIcon_1 = __importDefault(require("../../FileTypeIcon"));
|
|
35
|
+
const ConditionalEditWrapper_1 = __importDefault(require("../ConditionalEditWrapper"));
|
|
36
|
+
/**
|
|
37
|
+
* Applies a `pattern_format` mask to a column, merging with any existing valueFormatter.
|
|
38
|
+
*/
|
|
39
|
+
const applyPatternFormatToColumn = (column, patternFormat) => {
|
|
40
|
+
column.patternFormat = patternFormat;
|
|
41
|
+
const existingValueFormatter = column.valueFormatter;
|
|
42
|
+
column.valueFormatter = (value, row, colDef, apiRef) => {
|
|
43
|
+
const formatted = existingValueFormatter
|
|
44
|
+
? existingValueFormatter(value, row, colDef, apiRef)
|
|
45
|
+
: value;
|
|
46
|
+
if (typeof formatted !== 'string' || !formatted) {
|
|
47
|
+
return formatted;
|
|
48
|
+
}
|
|
49
|
+
return new string_mask_1.default(patternFormat, {}).apply(formatted);
|
|
50
|
+
};
|
|
51
|
+
return column;
|
|
52
|
+
};
|
|
53
|
+
function buildPreparedColumns(_a) {
|
|
54
|
+
return __awaiter(this, arguments, void 0, function* ({ apiRef, schema, columns, isEditable, actions, LinkComponent, stateToLink, validationErrors, optionsAC, onEditModel, customFieldFormLayouts, setDialog, indexField, indexFieldMinWidth, minWidth, customColumnOperations, customLinkDestination, indexFieldBasePath, conditionalVisible, serverEndPoint, }) {
|
|
55
|
+
const promises = columns.map((col) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const fieldSchema = schema[col.field];
|
|
57
|
+
if (!fieldSchema) {
|
|
58
|
+
return col;
|
|
59
|
+
}
|
|
60
|
+
const fieldType = fieldSchema.type;
|
|
61
|
+
const isIndexField = indexField !== '' && col.field === indexField;
|
|
62
|
+
let column = Object.assign({}, col);
|
|
63
|
+
column.editable =
|
|
64
|
+
isEditable &&
|
|
65
|
+
!col.disabled &&
|
|
66
|
+
(!fieldSchema.read_only || ['field', 'nested object'].includes(fieldType));
|
|
67
|
+
switch (fieldType) {
|
|
68
|
+
case 'date':
|
|
69
|
+
column.type = 'date';
|
|
70
|
+
if (!column.minWidth) {
|
|
71
|
+
column.minWidth = 150;
|
|
72
|
+
}
|
|
73
|
+
const df = (0, utils_1.buildDateFormatBySchema)(fieldSchema.date_views);
|
|
74
|
+
column.valueFormatter = (value) => (value ? (0, dayjs_1.default)(value).format(df) : '');
|
|
75
|
+
column.filterOperators = (0, utils_2.quantityOnlyOperators)({ type: 'date' });
|
|
76
|
+
if (isEditable && !col.disabled) {
|
|
77
|
+
column.renderEditCell = (p) => {
|
|
78
|
+
var _a;
|
|
79
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
80
|
+
const inputCell = (react_1.default.createElement(GridDateInput_1.default, Object.assign({}, p, { column: column, dateViews: fieldSchema.date_views, error: Boolean(err), helperText: err })));
|
|
81
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
82
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
83
|
+
}
|
|
84
|
+
return inputCell;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case 'datetime':
|
|
89
|
+
column.type = 'dateTime';
|
|
90
|
+
if (!column.minWidth) {
|
|
91
|
+
column.minWidth = 200;
|
|
92
|
+
}
|
|
93
|
+
column.valueFormatter = (value) => value ? (0, dayjs_1.default)(value).format('DD/MM/YYYY HH:mm') : '';
|
|
94
|
+
if (isEditable && !col.disabled) {
|
|
95
|
+
column.renderEditCell = (p) => {
|
|
96
|
+
var _a;
|
|
97
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
98
|
+
const inputCell = (react_1.default.createElement(GridDateTimeInput_1.default, Object.assign({}, p, { column: column, error: Boolean(err), helperText: err })));
|
|
99
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
100
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
101
|
+
}
|
|
102
|
+
return inputCell;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case 'nested object':
|
|
107
|
+
case 'field':
|
|
108
|
+
case 'choice':
|
|
109
|
+
case 'list':
|
|
110
|
+
column.minWidth = 150;
|
|
111
|
+
// Values are already option objects ({value, display_name} or {id,
|
|
112
|
+
// label}); single = one object, multiple = an array of objects.
|
|
113
|
+
const formatChoiceValue = (value) => {
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
return value.map((v) => (v === null || v === void 0 ? void 0 : v.label) || (v === null || v === void 0 ? void 0 : v.display_name) || '').join(', ');
|
|
116
|
+
}
|
|
117
|
+
return (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.display_name) || '';
|
|
118
|
+
};
|
|
119
|
+
if (isEditable && !col.disabled) {
|
|
120
|
+
column.valueFormatter = formatChoiceValue;
|
|
121
|
+
column.renderEditCell = (p) => {
|
|
122
|
+
var _a;
|
|
123
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
124
|
+
const inputCell = (react_1.default.createElement(SelectEditInputCell_1.default, Object.assign({}, p, { column: column, type: fieldType, options: optionsAC[col.field] || [], isIndexField: isIndexField, onEditModel: onEditModel, fieldsLayout: customFieldFormLayouts === null || customFieldFormLayouts === void 0 ? void 0 : customFieldFormLayouts[col.field], setDialog: setDialog, multiple: fieldType === 'list' || fieldSchema.many, error: Boolean(err), helperText: err })));
|
|
125
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
126
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
127
|
+
}
|
|
128
|
+
return inputCell;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
column.valueGetter = formatChoiceValue;
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case 'boolean':
|
|
136
|
+
column.valueFormatter = (value) => (value ? 'Sim' : 'Não');
|
|
137
|
+
if (isEditable && !col.disabled) {
|
|
138
|
+
column.renderEditCell = (p) => {
|
|
139
|
+
var _a;
|
|
140
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
141
|
+
const inputCell = (react_1.default.createElement(BooleanInputCell_1.default, Object.assign({}, p, { column: column, error: Boolean(err), helperText: err })));
|
|
142
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
143
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
144
|
+
}
|
|
145
|
+
return inputCell;
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
break;
|
|
149
|
+
case 'decimal':
|
|
150
|
+
case 'float':
|
|
151
|
+
case 'number':
|
|
152
|
+
case 'integer':
|
|
153
|
+
const ds = fieldSchema.decimal_places || (fieldType === 'integer' ? 0 : 2);
|
|
154
|
+
column.type = 'number';
|
|
155
|
+
column.valueFormatter = (value) => {
|
|
156
|
+
if (value === null || value === undefined)
|
|
157
|
+
return '';
|
|
158
|
+
return parseFloat(value).toLocaleString('pt-BR', {
|
|
159
|
+
minimumFractionDigits: ds,
|
|
160
|
+
maximumFractionDigits: ds,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
column.filterOperators = (0, utils_2.quantityOnlyOperators)({
|
|
164
|
+
type: fieldType === 'decimal' ? 'float' : 'number',
|
|
165
|
+
});
|
|
166
|
+
if (isEditable && !col.disabled) {
|
|
167
|
+
column.renderEditCell = (p) => {
|
|
168
|
+
var _a;
|
|
169
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
170
|
+
const inputCell = (react_1.default.createElement(GridDecimalInput_1.default, Object.assign({}, p, { decimalPlaces: ds, isCurrency: fieldSchema.is_currency, prefix: fieldSchema.prefix || '', suffix: fieldSchema.suffix || '', column: column, error: Boolean(err), helperText: err })));
|
|
171
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
172
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
173
|
+
}
|
|
174
|
+
return inputCell;
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
break;
|
|
178
|
+
case 'image upload':
|
|
179
|
+
case 'file upload':
|
|
180
|
+
case 'image':
|
|
181
|
+
case 'file':
|
|
182
|
+
column.minWidth = 200;
|
|
183
|
+
column.renderCell = (p) => {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, ((_a = p.value) === null || _a === void 0 ? void 0 : _a.name) &&
|
|
186
|
+
(((_b = p.value) === null || _b === void 0 ? void 0 : _b.url) && (fieldType === 'image upload' || fieldType === 'image') ? (react_1.default.createElement("img", { src: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${p.value.url}`, alt: p.value.name, style: { width: '100%', maxHeight: '100px', objectFit: 'cover' } })) : (react_1.default.createElement(Stack_1.default, { direction: "row", spacing: 0.5, alignItems: "center" },
|
|
187
|
+
react_1.default.createElement(FileTypeIcon_1.default, { name: p.value.name }),
|
|
188
|
+
react_1.default.createElement(Typography_1.default, { variant: "body2" }, p.value.name.split('/').pop()))))));
|
|
189
|
+
};
|
|
190
|
+
if (isEditable && !col.disabled) {
|
|
191
|
+
column.renderEditCell = (p) => {
|
|
192
|
+
var _a;
|
|
193
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
194
|
+
const acc = fieldSchema.allowed_mime_types
|
|
195
|
+
? fieldSchema.allowed_mime_types.join(', ')
|
|
196
|
+
: fieldType.includes('image')
|
|
197
|
+
? 'image/*'
|
|
198
|
+
: '*';
|
|
199
|
+
const inputCell = (react_1.default.createElement(FileInputCell_1.default, Object.assign({ accept: acc, fileType: fieldType, column: column, required: (0, utils_1.isFieldRequired)(fieldSchema) }, p, { error: Boolean(err), helperText: err })));
|
|
200
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
201
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
202
|
+
}
|
|
203
|
+
return inputCell;
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
case 'point':
|
|
208
|
+
case 'polygon':
|
|
209
|
+
case 'multipoint':
|
|
210
|
+
case 'multipolygon':
|
|
211
|
+
case 'geometrycollection':
|
|
212
|
+
column.minWidth = geoConstants_1.GIS_THUMB_SIZE.w + 24;
|
|
213
|
+
column.renderCell = (p) => (react_1.default.createElement(GeoThumbCell_1.default, { geometry: fieldType, value: p.value }));
|
|
214
|
+
if (isEditable && !col.disabled) {
|
|
215
|
+
column.renderEditCell = (p) => (react_1.default.createElement(GeoEditCell_1.default, Object.assign({}, p, { geometry: fieldType })));
|
|
216
|
+
}
|
|
217
|
+
break;
|
|
218
|
+
case 'string':
|
|
219
|
+
if (isEditable && !col.disabled && (fieldSchema.pattern_format || col.patternFormat)) {
|
|
220
|
+
column.renderEditCell = (p) => {
|
|
221
|
+
var _a;
|
|
222
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
223
|
+
const inputCell = (react_1.default.createElement(GridPatternInput_1.default, Object.assign({}, p, { patternFormat: fieldSchema.pattern_format || col.patternFormat || '', error: Boolean(err), helperText: err })));
|
|
224
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
225
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
226
|
+
}
|
|
227
|
+
return inputCell;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
// Apply pattern_format (mask) for display:
|
|
233
|
+
const patternFormat = fieldSchema.pattern_format || col.patternFormat;
|
|
234
|
+
if (patternFormat && fieldType !== 'decimal' && fieldType !== 'float') {
|
|
235
|
+
column = applyPatternFormatToColumn(column, patternFormat);
|
|
236
|
+
}
|
|
237
|
+
if (indexFieldMinWidth && !column.minWidth)
|
|
238
|
+
column.minWidth = col.field === indexField ? indexFieldMinWidth : minWidth;
|
|
239
|
+
if (indexField && col.field === indexField) {
|
|
240
|
+
column.flex = 1;
|
|
241
|
+
column.renderCell = (p) => {
|
|
242
|
+
if (LinkComponent &&
|
|
243
|
+
(customLinkDestination || indexFieldBasePath !== '') &&
|
|
244
|
+
!actions.includes('edit')) {
|
|
245
|
+
const to = customLinkDestination
|
|
246
|
+
? customLinkDestination(p)
|
|
247
|
+
: (0, utils_2.buildEditPath)(indexFieldBasePath, p.id);
|
|
248
|
+
return (react_1.default.createElement(LinkComponent, { to: `${to}`, state: stateToLink }, p.formattedValue));
|
|
249
|
+
}
|
|
250
|
+
return react_1.default.createElement(react_1.default.Fragment, null, p.formattedValue);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
if (!column.renderEditCell) {
|
|
254
|
+
column.renderEditCell = (p) => {
|
|
255
|
+
var _a;
|
|
256
|
+
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
257
|
+
const inputCell = react_1.default.createElement(GridGenericInput_1.default, Object.assign({}, p, { error: Boolean(err), helperText: err }));
|
|
258
|
+
if (conditionalVisible.filter(({ target }) => target === p.field).length > 0) {
|
|
259
|
+
return (react_1.default.createElement(ConditionalEditWrapper_1.default, Object.assign({}, p, { conditionalVisible: conditionalVisible, apiRef: apiRef }), inputCell));
|
|
260
|
+
}
|
|
261
|
+
return inputCell;
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
if (customColumnOperations)
|
|
265
|
+
column = yield customColumnOperations(column);
|
|
266
|
+
return column;
|
|
267
|
+
}));
|
|
268
|
+
return Promise.all(promises);
|
|
269
|
+
});
|
|
270
|
+
}
|