drf-react-by-schema 0.28.7 → 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 +12 -4
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("react");
|
|
4
|
+
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
5
|
+
function RowEditingWatcher({ watchEditingRowValues }) {
|
|
6
|
+
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
7
|
+
const [rowEditingValues, rowId] = (0, x_data_grid_1.useGridSelector)(apiRef, (state) => {
|
|
8
|
+
const editState = (0, x_data_grid_1.gridEditRowsStateSelector)(state);
|
|
9
|
+
if (!editState || Object.keys(editState).length === 0) {
|
|
10
|
+
return [undefined, undefined];
|
|
11
|
+
}
|
|
12
|
+
const rowEditingId = Object.keys(editState)[0];
|
|
13
|
+
const rowEditState = editState[rowEditingId];
|
|
14
|
+
const onlyValues = {};
|
|
15
|
+
Object.keys(rowEditState).forEach((key) => {
|
|
16
|
+
onlyValues[key] = rowEditState[key].value;
|
|
17
|
+
});
|
|
18
|
+
return [onlyValues, rowEditingId];
|
|
19
|
+
});
|
|
20
|
+
const setRowEditingValues = (0, react_1.useCallback)((newValues) => {
|
|
21
|
+
if (!apiRef.current || !rowEditingValues || !rowId) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
for (const [field, newRowEditingValue] of Object.entries(newValues)) {
|
|
25
|
+
const rowEditingValue = field in rowEditingValues ? rowEditingValues[field] : undefined;
|
|
26
|
+
if (JSON.stringify(rowEditingValue) !== JSON.stringify(newRowEditingValue))
|
|
27
|
+
apiRef.current.setEditCellValue({
|
|
28
|
+
id: rowId,
|
|
29
|
+
field,
|
|
30
|
+
value: newRowEditingValue,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}, [apiRef, rowEditingValues, rowId]);
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
if (watchEditingRowValues && rowEditingValues) {
|
|
36
|
+
watchEditingRowValues({ rowEditingValues, setRowEditingValues });
|
|
37
|
+
}
|
|
38
|
+
}, [rowEditingValues, apiRef, watchEditingRowValues, setRowEditingValues]);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
exports.default = RowEditingWatcher;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSX } from 'react';
|
|
2
|
+
import { SxProps, Theme } from '@mui/material/styles';
|
|
3
|
+
import { FormFieldLayout, GenericValue, Item, GridEnrichedBySchemaColDef, TField } from '../../@types';
|
|
4
|
+
import { DialogType, OnEditModelType } from '../../context/APIWrapperContext';
|
|
5
|
+
interface SelectEditInputCellProps {
|
|
6
|
+
field: string;
|
|
7
|
+
id: number | string;
|
|
8
|
+
value?: GenericValue;
|
|
9
|
+
column: GridEnrichedBySchemaColDef;
|
|
10
|
+
type: string;
|
|
11
|
+
options?: Item[] | (() => Promise<Item[]>) | null;
|
|
12
|
+
isIndexField: boolean;
|
|
13
|
+
multiple?: boolean;
|
|
14
|
+
onEditModel?: <U extends TField = void>(p: OnEditModelType<U>) => void;
|
|
15
|
+
fieldsLayout?: FormFieldLayout[];
|
|
16
|
+
sx?: SxProps<Theme>;
|
|
17
|
+
setDialog: (x: Partial<DialogType>) => void;
|
|
18
|
+
error?: boolean;
|
|
19
|
+
helperText?: string;
|
|
20
|
+
hasFocus?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export default function SelectEditInputCell({ field, id, value, column, type, options, isIndexField, multiple, onEditModel, fieldsLayout, sx, setDialog, error, helperText, hasFocus, }: SelectEditInputCellProps): JSX.Element;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=SelectEditInputCell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,EACL,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,0BAA0B,EAE1B,MAAM,EACP,MAAM,cAAc,CAAC;AAEtB,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,SAAS,MAAM,GAAG,IAAI,EAAE,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACvE,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,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,EAC1C,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,CAgSxC"}
|
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.default = SelectEditInputCell;
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
50
|
+
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
51
|
+
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
52
|
+
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
|
|
53
|
+
const Edit_1 = __importDefault(require("@mui/icons-material/Edit"));
|
|
54
|
+
const Autocomplete_1 = __importStar(require("@mui/material/Autocomplete"));
|
|
55
|
+
const utils_1 = require("../../utils");
|
|
56
|
+
const DialogActions_1 = __importDefault(require("../DialogActions"));
|
|
57
|
+
const grid_1 = require("../../styles/grid");
|
|
58
|
+
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
59
|
+
function SelectEditInputCell({ field, id, value, column, type, options, isIndexField, multiple = false, onEditModel, fieldsLayout, sx = {}, setDialog, error, helperText, hasFocus, }) {
|
|
60
|
+
const [loadedOptions, setLoadedOptions] = (0, react_1.useState)(null);
|
|
61
|
+
// TODO: allow edit option label, as in formautocomplete!
|
|
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]);
|
|
72
|
+
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
74
|
+
apiRef.current.stopCellEditMode({ id, field });
|
|
75
|
+
});
|
|
76
|
+
const labelKey = ['field', 'nested object'].includes(type) || isIndexField ? 'label' : 'display_name';
|
|
77
|
+
const valueKey = ['field', 'nested object'].includes(type) || isIndexField ? 'id' : 'value';
|
|
78
|
+
let creatableProps = {};
|
|
79
|
+
// if (column.creatable || isIndexField) {
|
|
80
|
+
if (column.creatable) {
|
|
81
|
+
creatableProps = {
|
|
82
|
+
freeSolo: true,
|
|
83
|
+
filterOptions: (thisOptions, params) => {
|
|
84
|
+
let filtered = filter(thisOptions, params);
|
|
85
|
+
const inputValue = params.inputValue ? params.inputValue : '';
|
|
86
|
+
const inputValueSlug = (0, utils_1.slugify)(inputValue);
|
|
87
|
+
const inputValueLength = inputValueSlug.length;
|
|
88
|
+
// Suggest the creation of a new value
|
|
89
|
+
const isExisting = thisOptions.find((option) => inputValueSlug === (0, utils_1.slugify)(option[labelKey]));
|
|
90
|
+
if (inputValue !== '' && !isExisting) {
|
|
91
|
+
filtered.push({
|
|
92
|
+
inputValue,
|
|
93
|
+
[labelKey]: `Criar "${inputValue}"`,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Show first the exact match:
|
|
97
|
+
if (isExisting) {
|
|
98
|
+
filtered = [isExisting, ...filtered.filter((option) => isExisting.id !== option.id)];
|
|
99
|
+
}
|
|
100
|
+
// Show first the options that start with inputValue:
|
|
101
|
+
const startsWith = filtered.filter((option) => inputValueSlug === (0, utils_1.slugify)(option.label).substring(0, inputValueLength));
|
|
102
|
+
if (startsWith.length > 0) {
|
|
103
|
+
const startsWithIds = startsWith.map((option) => option.id);
|
|
104
|
+
filtered = [
|
|
105
|
+
...startsWith,
|
|
106
|
+
...filtered.filter((option) => !startsWithIds.includes(option.id)),
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
return filtered;
|
|
110
|
+
},
|
|
111
|
+
handleHomeEndKeys: true,
|
|
112
|
+
getOptionLabel: (option) => {
|
|
113
|
+
// Value selected with enter, right from the input
|
|
114
|
+
if (typeof option === 'string') {
|
|
115
|
+
return option;
|
|
116
|
+
}
|
|
117
|
+
// Criar "xxx" option created dynamically
|
|
118
|
+
if (option.inputValue) {
|
|
119
|
+
return option.inputValue;
|
|
120
|
+
}
|
|
121
|
+
// Regular option
|
|
122
|
+
return option[labelKey];
|
|
123
|
+
},
|
|
124
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
+
renderOption: (props, option) => {
|
|
126
|
+
return (react_1.default.createElement("li", Object.assign({ key: option[valueKey] }, props), option[labelKey]));
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const handleOpenOptions = () => {
|
|
131
|
+
setOpenOptions(true);
|
|
132
|
+
};
|
|
133
|
+
const handleCloseOptions = () => {
|
|
134
|
+
setOpenOptions(false);
|
|
135
|
+
};
|
|
136
|
+
(0, react_1.useEffect)(() => {
|
|
137
|
+
if (!options) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (Array.isArray(options)) {
|
|
141
|
+
setLoadedOptions(options);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (!loadedOptions) {
|
|
145
|
+
options().then((newOptions) => setLoadedOptions(newOptions));
|
|
146
|
+
}
|
|
147
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
148
|
+
}, [field, options]);
|
|
149
|
+
if (!options ||
|
|
150
|
+
loadedOptions === null
|
|
151
|
+
// || (Array.isArray(options) && options.length === 0) || loadedOptions.length === 0
|
|
152
|
+
) {
|
|
153
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
|
154
|
+
}
|
|
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];
|
|
157
|
+
}, getOptionLabel: (option) => {
|
|
158
|
+
if (typeof option === 'string')
|
|
159
|
+
return option;
|
|
160
|
+
if (option.inputValue)
|
|
161
|
+
return option.inputValue;
|
|
162
|
+
return option ? option[labelKey] : '';
|
|
163
|
+
}, onChange: (_e, value) => {
|
|
164
|
+
// if (!column.creatable && !isIndexField) {
|
|
165
|
+
if (!column.creatable) {
|
|
166
|
+
handleChange(value);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
let newValue = value;
|
|
170
|
+
if (typeof newValue === 'string') {
|
|
171
|
+
const tmpId = (0, utils_1.getTmpId)();
|
|
172
|
+
newValue = {
|
|
173
|
+
[valueKey]: tmpId,
|
|
174
|
+
[labelKey]: newValue,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (newValue && newValue.inputValue) {
|
|
178
|
+
const tmpId = (0, utils_1.getTmpId)();
|
|
179
|
+
if (onEditModel) {
|
|
180
|
+
// Open modal to save new item:
|
|
181
|
+
onEditModel({
|
|
182
|
+
model: field,
|
|
183
|
+
id: tmpId,
|
|
184
|
+
labelKey,
|
|
185
|
+
setValue: (_key, updatedValue) => {
|
|
186
|
+
handleChange(updatedValue);
|
|
187
|
+
},
|
|
188
|
+
getValues: () => {
|
|
189
|
+
console.log('getValues');
|
|
190
|
+
return newValue;
|
|
191
|
+
},
|
|
192
|
+
fieldsLayout,
|
|
193
|
+
initialValuesPartial: {
|
|
194
|
+
nome: newValue.inputValue, // TODO: make this "nome" generic!
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// Define new Item as an "optimistic response"
|
|
199
|
+
newValue = {
|
|
200
|
+
[valueKey]: tmpId,
|
|
201
|
+
[labelKey]: newValue.inputValue,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
handleChange(newValue);
|
|
205
|
+
}, fullWidth: true, slotProps: {
|
|
206
|
+
paper: {
|
|
207
|
+
sx: {
|
|
208
|
+
marginTop: '1px', // Gap to show the bottom cell border
|
|
209
|
+
boxShadow: 3,
|
|
210
|
+
border: '1px solid #e0e0e0',
|
|
211
|
+
'& .MuiAutocomplete-listbox': {
|
|
212
|
+
padding: 0,
|
|
213
|
+
fontSize: '0.875rem',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
}, renderInput: (params) => (react_1.default.createElement(react_1.default.Fragment, null, column.creatable ? (react_1.default.createElement(TextField_1.default, Object.assign({}, params, {
|
|
218
|
+
// margin="normal"
|
|
219
|
+
inputRef: inputCallbackRef, slotProps: {
|
|
220
|
+
htmlInput: Object.assign(Object.assign({}, params.inputProps), { 'aria-label': `Editar ${column.headerName || field}. Pressione Enter ou comece a digitar para ver as opções.` }),
|
|
221
|
+
input: Object.assign(Object.assign({}, params.InputProps), { endAdornment: (react_1.default.createElement(react_1.default.Fragment, null,
|
|
222
|
+
!multiple && onEditModel && value && (react_1.default.createElement(IconButton_1.default, { size: "small", "aria-label": "Editar", onClick: () => {
|
|
223
|
+
if ((0, utils_1.isTmpId)(value.id)) {
|
|
224
|
+
setDialog({
|
|
225
|
+
open: true,
|
|
226
|
+
loading: false,
|
|
227
|
+
title: 'Linha sendo criada',
|
|
228
|
+
Body: 'Esta linha está sendo criada agora por você. Para editar suas propriedades, salve antes, e depois você poderá editar!',
|
|
229
|
+
Actions: (react_1.default.createElement(DialogActions_1.default, { setDialog: setDialog, btnCancel: "Entendi" })),
|
|
230
|
+
});
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
onEditModel({
|
|
234
|
+
model: field,
|
|
235
|
+
id: value[valueKey],
|
|
236
|
+
labelKey,
|
|
237
|
+
setValue: (_key, updatedValue) => {
|
|
238
|
+
handleChange(updatedValue);
|
|
239
|
+
},
|
|
240
|
+
getValues: () => {
|
|
241
|
+
return value;
|
|
242
|
+
},
|
|
243
|
+
fieldsLayout,
|
|
244
|
+
});
|
|
245
|
+
} },
|
|
246
|
+
react_1.default.createElement(Edit_1.default, null))),
|
|
247
|
+
params.InputProps.endAdornment)) }),
|
|
248
|
+
}, 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: {
|
|
249
|
+
htmlInput: Object.assign(Object.assign({}, params.inputProps), { 'aria-label': `Selecionar ${column.headerName || field}` }),
|
|
250
|
+
}, error: error, helperText: helperText, sx: [grid_1.seamlessTextFieldStyle, ...(Array.isArray(sx) ? sx : [sx])] }))))) }, creatableProps, { onKeyDown: (event) => {
|
|
251
|
+
if (event.key === 'Enter') {
|
|
252
|
+
if (!openOptions) {
|
|
253
|
+
// Abrir o menu de opções
|
|
254
|
+
event.stopPropagation();
|
|
255
|
+
handleOpenOptions();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} })));
|
|
259
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geoConstants.d.ts","sourceRoot":"","sources":["../../../src/components/DataGridBySchemaEditable/geoConstants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc;;;CAA8B,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GIS_THUMB_SIZE = void 0;
|
|
4
|
+
// Shared sizing for PostGIS geometry grid cells. Matches the thumbnail image
|
|
5
|
+
// height used by image/file columns (maxHeight 100px).
|
|
6
|
+
exports.GIS_THUMB_SIZE = { w: 150, h: 100 };
|
|
@@ -0,0 +1,33 @@
|
|
|
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, FieldKey, PartialItem, TField, PaginationModel } from '../../../@types';
|
|
5
|
+
interface UseDataGridActionsProps<T extends TField = void> {
|
|
6
|
+
apiRef: RefObject<GridApiCommunity>;
|
|
7
|
+
model: string;
|
|
8
|
+
modelParent?: string;
|
|
9
|
+
modelParentId?: Id;
|
|
10
|
+
schema: SchemaType<T>;
|
|
11
|
+
emptyItem: PartialItem<T>;
|
|
12
|
+
dataGridRows: Item<T>[];
|
|
13
|
+
setDataGridRows: (value: React.SetStateAction<Item<T>[]>) => void;
|
|
14
|
+
setSelectionModel: (value: React.SetStateAction<Item<T>[]>) => void;
|
|
15
|
+
setSelectionModelIds: (value: React.SetStateAction<GridRowId[]>) => void;
|
|
16
|
+
setSnackBar: (value: React.SetStateAction<Item>) => void;
|
|
17
|
+
setDataGridLoading: (value: boolean) => void;
|
|
18
|
+
handleStartEditing: (p?: Id) => void;
|
|
19
|
+
tableAutoHeight?: boolean;
|
|
20
|
+
indexField: FieldKey<T>;
|
|
21
|
+
defaultValues?: PartialItem<T>;
|
|
22
|
+
isRowEditing?: Id;
|
|
23
|
+
onProcessRow?: (p?: Item<T>) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare const useDataGridActions: <T extends TField = void>({ apiRef, model, modelParent, modelParentId, schema, emptyItem, dataGridRows, setDataGridRows, setSelectionModel, setSelectionModelIds, setSnackBar, setDataGridLoading, handleStartEditing, tableAutoHeight, indexField, defaultValues, isRowEditing, onProcessRow, }: UseDataGridActionsProps<T>) => {
|
|
26
|
+
handleAddItem: () => void;
|
|
27
|
+
bulkUpdateData: BulkUpdateData<T>;
|
|
28
|
+
bulkDeleteData: BulkDeleteData;
|
|
29
|
+
bulkCreateData: (ids: Id[]) => Promise<void>;
|
|
30
|
+
handleExportExcel: (paginationModel: PaginationModel) => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
33
|
+
//# 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,EACL,EAAE,EACF,IAAI,EACJ,UAAU,EACV,cAAc,EACd,cAAc,EACd,QAAQ,EACR,WAAW,EACX,MAAM,EACN,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAKzB,UAAU,uBAAuB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACvD,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC1B,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IAClE,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IACpE,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,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACxB,aAAa,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC/B,YAAY,CAAC,EAAE,EAAE,CAAC;IAClB,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CACtC;AAED,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,wQAmBzD,uBAAuB,CAAC,CAAC,CAAC;;;;0BAqIQ,EAAE,EAAE;yCAWW,eAAe;CAqBlE,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
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 utils_2 = require("../utils");
|
|
20
|
+
const useDataGridActions = ({ apiRef, model, modelParent, modelParentId, schema, emptyItem, dataGridRows, setDataGridRows, setSelectionModel, setSelectionModelIds, setSnackBar, setDataGridLoading, handleStartEditing, tableAutoHeight, indexField, defaultValues, isRowEditing, onProcessRow, }) => {
|
|
21
|
+
const { rawDeleteData, rawUpdateDataBySchema, exportExcelData } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
22
|
+
const handleAddItems = (n = 1) => {
|
|
23
|
+
const newRows = [];
|
|
24
|
+
for (let i = 0; i < n; i++) {
|
|
25
|
+
const id = (0, utils_1.getTmpId)();
|
|
26
|
+
const newRow = Object.assign(Object.assign(Object.assign({}, emptyItem), defaultValues), { id });
|
|
27
|
+
apiRef.current.updateRows([newRow]);
|
|
28
|
+
newRows.push(newRow);
|
|
29
|
+
}
|
|
30
|
+
const newDataGridRows = tableAutoHeight
|
|
31
|
+
? [...dataGridRows, ...newRows]
|
|
32
|
+
: [...newRows, ...dataGridRows];
|
|
33
|
+
setDataGridRows(newDataGridRows);
|
|
34
|
+
let fieldToFocus = indexField;
|
|
35
|
+
if (!fieldToFocus) {
|
|
36
|
+
const visibleColumns = apiRef.current.getAllColumns();
|
|
37
|
+
const firstEditableCol = visibleColumns.find((col) => col.editable && col.field !== 'actions');
|
|
38
|
+
fieldToFocus = firstEditableCol === null || firstEditableCol === void 0 ? void 0 : firstEditableCol.field;
|
|
39
|
+
}
|
|
40
|
+
(0, utils_2.scrollToNewRow)(apiRef, tableAutoHeight);
|
|
41
|
+
apiRef.current.startRowEditMode({ id: newRows[0].id, fieldToFocus });
|
|
42
|
+
handleStartEditing(newRows[0].id);
|
|
43
|
+
};
|
|
44
|
+
const handleAddItem = () => {
|
|
45
|
+
if (isRowEditing) {
|
|
46
|
+
if ((0, utils_1.isTmpId)(isRowEditing)) {
|
|
47
|
+
setSnackBar({
|
|
48
|
+
open: true,
|
|
49
|
+
severity: 'info',
|
|
50
|
+
msg: 'Adicione uma linha por vez',
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
apiRef.current.stopRowEditMode({ id: isRowEditing });
|
|
55
|
+
}
|
|
56
|
+
const id = (0, utils_1.getTmpId)();
|
|
57
|
+
const newRow = Object.assign(Object.assign(Object.assign({}, emptyItem), defaultValues), { id });
|
|
58
|
+
(0, utils_2.addNewRow)({
|
|
59
|
+
newRow,
|
|
60
|
+
indexField,
|
|
61
|
+
tableAutoHeight,
|
|
62
|
+
apiRef,
|
|
63
|
+
setDataGridRows,
|
|
64
|
+
});
|
|
65
|
+
handleStartEditing(id);
|
|
66
|
+
// apiRef.current.setCellFocus(id, fieldToFocus);
|
|
67
|
+
// if (!tableAutoHeight) {
|
|
68
|
+
// apiRef.current.scrollToIndexes({ rowIndex: 0 });
|
|
69
|
+
// }
|
|
70
|
+
};
|
|
71
|
+
const bulkUpdateData = (newData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const promises = [];
|
|
73
|
+
const ids = [];
|
|
74
|
+
newData.map((item) => {
|
|
75
|
+
promises.push(rawUpdateDataBySchema({
|
|
76
|
+
model,
|
|
77
|
+
modelObjectId: item.id,
|
|
78
|
+
data: item,
|
|
79
|
+
schema,
|
|
80
|
+
}));
|
|
81
|
+
ids.push(item.id);
|
|
82
|
+
});
|
|
83
|
+
const results = yield Promise.all(promises);
|
|
84
|
+
setSelectionModel([]);
|
|
85
|
+
setSelectionModelIds([]);
|
|
86
|
+
const updatedData = dataGridRows.map((item) => {
|
|
87
|
+
const index = ids.indexOf(item.id);
|
|
88
|
+
return index === -1 ? item : newData[index];
|
|
89
|
+
});
|
|
90
|
+
setDataGridRows(updatedData);
|
|
91
|
+
setSnackBar({
|
|
92
|
+
open: true,
|
|
93
|
+
severity: 'success',
|
|
94
|
+
msg: 'Alterações salvas com sucesso',
|
|
95
|
+
});
|
|
96
|
+
return results.map((result, index) => {
|
|
97
|
+
return {
|
|
98
|
+
id: ids[index],
|
|
99
|
+
success: !axios_1.default.isAxiosError(result),
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
const bulkDeleteData = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
const promises = [];
|
|
105
|
+
ids.map((id) => {
|
|
106
|
+
promises.push(rawDeleteData(model, id));
|
|
107
|
+
apiRef.current.updateRows([{ id, _action: 'delete' }]);
|
|
108
|
+
});
|
|
109
|
+
setDataGridLoading(true);
|
|
110
|
+
const results = yield Promise.all(promises);
|
|
111
|
+
setSelectionModel([]);
|
|
112
|
+
setSelectionModelIds([]);
|
|
113
|
+
const newData = dataGridRows.filter(({ id }) => !ids.includes(id));
|
|
114
|
+
setDataGridRows(newData);
|
|
115
|
+
if (onProcessRow) {
|
|
116
|
+
onProcessRow();
|
|
117
|
+
}
|
|
118
|
+
setDataGridLoading(false);
|
|
119
|
+
setSnackBar({
|
|
120
|
+
open: true,
|
|
121
|
+
severity: 'success',
|
|
122
|
+
msg: 'Itens apagados com sucesso',
|
|
123
|
+
});
|
|
124
|
+
return results.map((result, index) => {
|
|
125
|
+
return {
|
|
126
|
+
id: ids[index],
|
|
127
|
+
success: result === true,
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
const bulkCreateData = (ids) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
handleAddItems(ids.length);
|
|
133
|
+
setSelectionModel([]);
|
|
134
|
+
setSelectionModelIds([]);
|
|
135
|
+
setSnackBar({
|
|
136
|
+
open: true,
|
|
137
|
+
severity: 'success',
|
|
138
|
+
msg: 'Linhas adicionadas com sucesso',
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
const handleExportExcel = (paginationModel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
|
+
setDataGridLoading(true);
|
|
143
|
+
const result = yield exportExcelData({ model, modelParent, modelParentId, paginationModel });
|
|
144
|
+
setDataGridLoading(false);
|
|
145
|
+
if (result !== true) {
|
|
146
|
+
setSnackBar({
|
|
147
|
+
open: true,
|
|
148
|
+
severity: 'error',
|
|
149
|
+
msg: 'Erro ao exportar para Excel',
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
handleAddItem,
|
|
155
|
+
bulkUpdateData,
|
|
156
|
+
bulkDeleteData,
|
|
157
|
+
bulkCreateData,
|
|
158
|
+
handleExportExcel,
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
exports.useDataGridActions = useDataGridActions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SchemaType, OptionsAC, GridEnrichedBySchemaColDef, FieldKey, TField } from '../../../@types';
|
|
2
|
+
interface UseOptionsACProps<T extends TField = void> {
|
|
3
|
+
columns: GridEnrichedBySchemaColDef<T>[];
|
|
4
|
+
schema: SchemaType<T>;
|
|
5
|
+
optionsACExternal?: OptionsAC<T>;
|
|
6
|
+
indexField?: FieldKey<T>;
|
|
7
|
+
addExistingModel?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const useOptionsAC: <T extends TField = void>({ columns, schema, optionsACExternal, indexField, addExistingModel, }: UseOptionsACProps<T>) => {
|
|
10
|
+
optionsAC: OptionsAC<T>;
|
|
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,EACL,UAAU,EACV,SAAS,EACT,0BAA0B,EAC1B,QAAQ,EAGR,MAAM,EACP,MAAM,iBAAiB,CAAC;AAGzB,UAAU,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACjD,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,iBAAiB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACjC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,uEAMnD,iBAAiB,CAAC,CAAC,CAAC;;;CAmDtB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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 (!(col.field in schema)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const fieldSchema = schema[col.field];
|
|
34
|
+
if (!fieldSchema) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (['field', 'nested object'].includes(fieldSchema.type) && !(col.field in newOptionsAC)) {
|
|
38
|
+
const options = yield getAutoComplete(col.field);
|
|
39
|
+
if (!axios_1.default.isAxiosError(options)) {
|
|
40
|
+
newOptionsAC[col.field] = options;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
console.log(`Couldn't load autocomplete options from '${col.field}'`);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (fieldSchema.type === 'choice' && !(col.field in newOptionsAC)) {
|
|
47
|
+
newOptionsAC[col.field] = fieldSchema.choices || [];
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (fieldSchema.type === 'list' && !(col.field in newOptionsAC)) {
|
|
51
|
+
newOptionsAC[col.field] = ((_a = fieldSchema.child) === null || _a === void 0 ? void 0 : _a.choices) || [];
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (col.field === indexField && addExistingModel && !(col.field in newOptionsAC)) {
|
|
55
|
+
const options = yield getAutoComplete(addExistingModel);
|
|
56
|
+
if (!axios_1.default.isAxiosError(options)) {
|
|
57
|
+
newOptionsAC[col.field] = options;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
setOptionsAC(newOptionsAC);
|
|
63
|
+
}), [columns, schema, optionsACExternal, indexField, addExistingModel]);
|
|
64
|
+
(0, react_1.useEffect)(() => {
|
|
65
|
+
updateOptionsAC();
|
|
66
|
+
}, [columns]);
|
|
67
|
+
return { optionsAC, updateOptionsAC };
|
|
68
|
+
};
|
|
69
|
+
exports.useOptionsAC = useOptionsAC;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GridEnrichedBySchemaColDef, TField } from '../../../@types';
|
|
2
|
+
import { BuildPreparedColumnsProps } from '../utils/columnFactory';
|
|
3
|
+
export declare const usePreparedColumns: <T extends TField = void>({ apiRef, schema, columns, isEditable, actions, LinkComponent, stateToLink, validationErrors, optionsAC, onEditModel, customFieldFormLayouts, setDialog, indexField, indexFieldMinWidth, minWidth, customColumnOperations, customLinkDestination, indexFieldBasePath, }: Omit<BuildPreparedColumnsProps<T>, "columns" | "serverEndPoint" | "conditionalVisible"> & {
|
|
4
|
+
columns: GridEnrichedBySchemaColDef<T>[];
|
|
5
|
+
}) => {
|
|
6
|
+
preparedColumns: GridEnrichedBySchemaColDef<T>[] | null;
|
|
7
|
+
setPreparedColumns: import("react").Dispatch<import("react").SetStateAction<GridEnrichedBySchemaColDef<T>[] | 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,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAwB,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAIzF,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,yQAmBzD,IAAI,CAAC,yBAAyB,CAAC,CAAC,CAAC,EAAE,SAAS,GAAG,gBAAgB,GAAG,oBAAoB,CAAC,GAAG;IAC3F,OAAO,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,CAAC;CAC1C;;;CA4DA,CAAC"}
|