drf-react-by-schema 0.17.6 → 0.17.8
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/components/DataGridBySchemaEditable.d.ts +2 -1
- package/dist/components/DataGridBySchemaEditable.js +13 -5
- package/dist/components/GenericModelList.d.ts +3 -2
- package/dist/components/GenericModelList.js +2 -2
- package/dist/components/GenericRelatedModelList.js +2 -2
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +20 -2
- package/dist/utils.d.ts +7 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { GridRowId, GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
3
|
import { SxProps } from '@mui/material';
|
|
4
|
-
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType, OnSelectActions, OptionsAC, FormFieldLayout } from '../utils';
|
|
4
|
+
import { Item, SchemaType, Id, GridEnrichedBySchemaColDef, PaginationModel, ActionType, OnSelectActions, OptionsAC, FormFieldLayout, CustomAction } from '../utils';
|
|
5
5
|
import { OnEditModelType } from '../context/APIWrapperContext';
|
|
6
6
|
interface DataGridBySchemaEditableProps {
|
|
7
7
|
schema: SchemaType;
|
|
@@ -44,6 +44,7 @@ interface DataGridBySchemaEditableProps {
|
|
|
44
44
|
hideToolbarComponent?: boolean;
|
|
45
45
|
tableAutoHeight?: boolean;
|
|
46
46
|
actions?: Partial<ActionType>[];
|
|
47
|
+
customActions?: CustomAction[];
|
|
47
48
|
optionsAC?: OptionsAC;
|
|
48
49
|
}
|
|
49
50
|
declare const DataGridBySchemaEditable: React.ForwardRefExoticComponent<DataGridBySchemaEditableProps & React.RefAttributes<unknown>>;
|
|
@@ -63,7 +63,7 @@ const BooleanInputCell_1 = require("./DataGridBySchemaEditable/BooleanInputCell"
|
|
|
63
63
|
const FooterToolbar_1 = require("./DataGridBySchemaEditable/FooterToolbar");
|
|
64
64
|
const ConfirmDialog_1 = require("./DataGridBySchemaEditable/ConfirmDialog");
|
|
65
65
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
66
|
-
const DataGridBySchemaEditable = (0, react_1.forwardRef)(({ schema, data, rowCount = 0, columns, model, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', indexFieldViewBasePath, stateToLink = {}, minWidth = 80, loading, modelParent, modelParentId, customColumnOperations, customFieldFormLayouts, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, hasBulkSelect = false, onSelectActions, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions = ['editInline', 'remove'], optionsAC: optionsACExternal, }, ref) => {
|
|
66
|
+
const DataGridBySchemaEditable = (0, react_1.forwardRef)(({ schema, data, rowCount = 0, columns, model, name = Math.floor(Math.random() * 1000000).toString(), indexField = 'nome', addExistingModel, indexFieldMinWidth = 350, indexFieldBasePath = '', indexFieldViewBasePath, stateToLink = {}, minWidth = 80, loading, modelParent, modelParentId, customColumnOperations, customFieldFormLayouts, customLinkDestination, LinkComponent, onProcessRow, onDataChange, onEditModel, isEditable = false, hasBulkSelect = false, onSelectActions, isAutoHeight = false, defaultValues = {}, hideFooterPagination = false, setVisibleRows, paginationModel = undefined, setPaginationModel = undefined, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions = ['editInline', 'remove'], customActions, optionsAC: optionsACExternal, }, ref) => {
|
|
67
67
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
68
68
|
const apiContext = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
69
69
|
const initialSnackBar = {
|
|
@@ -205,6 +205,13 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)(({ schema, data, rowCou
|
|
|
205
205
|
break;
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
|
+
// React.ReactElement<any, string | React.JSXElementConstructor<any>>
|
|
209
|
+
// React.ReactElement<any, string | React.JSXElementConstructor<any>>
|
|
210
|
+
if (customActions) {
|
|
211
|
+
customActions.map((customAction) => {
|
|
212
|
+
actionItems.push(react_1.default.createElement(x_data_grid_1.GridActionsCellItem, { key: `${customAction.key}_${id}`, icon: customAction.icon, label: customAction.label, onClick: () => customAction.handleClick(dataGrid.data.find((row) => row.id === id)), onResize: () => null, onResizeCapture: () => null, showInMenu: false, placeholder: '' }));
|
|
213
|
+
});
|
|
214
|
+
}
|
|
208
215
|
return actionItems;
|
|
209
216
|
},
|
|
210
217
|
});
|
|
@@ -576,10 +583,11 @@ const DataGridBySchemaEditable = (0, react_1.forwardRef)(({ schema, data, rowCou
|
|
|
576
583
|
});
|
|
577
584
|
}, [data]);
|
|
578
585
|
(0, react_1.useEffect)(() => {
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
586
|
+
// I don't undedrstand why I had this. I'm commenting out....
|
|
587
|
+
// if (optionsAC.current) {
|
|
588
|
+
// initColumns();
|
|
589
|
+
// return;
|
|
590
|
+
// }
|
|
583
591
|
updateOptionsAC().then(() => {
|
|
584
592
|
initColumns();
|
|
585
593
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { GridFilterModel, GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
|
-
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions, OptionsAC, FormFieldLayout } from '../utils';
|
|
3
|
+
import { GridEnrichedBySchemaColDef, ActionType, Item, OnSelectActions, OptionsAC, FormFieldLayout, CustomAction } from '../utils';
|
|
4
4
|
import { SumRowsType } from '../api';
|
|
5
5
|
interface GenericModelListProps {
|
|
6
6
|
model: string;
|
|
@@ -33,9 +33,10 @@ interface GenericModelListProps {
|
|
|
33
33
|
hideToolbarComponent?: boolean;
|
|
34
34
|
tableAutoHeight?: boolean;
|
|
35
35
|
actions?: Partial<ActionType>[];
|
|
36
|
+
customActions?: CustomAction[];
|
|
36
37
|
optionsAC?: OptionsAC;
|
|
37
38
|
defaultValues?: Item;
|
|
38
39
|
disableScreenLoading?: boolean;
|
|
39
40
|
}
|
|
40
|
-
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, reloadAfterRowUpdate, customColumnOperations, customFieldFormLayouts, customLinkDestination, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, defaultValues, disableScreenLoading, }: GenericModelListProps) => React.JSX.Element;
|
|
41
|
+
declare const GenericModelList: ({ model, columnFields, hiddenFields, creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, reloadAfterRowUpdate, customColumnOperations, customFieldFormLayouts, customLinkDestination, isEditable, hasBulkSelect, onSelectActions, sumRows, isAutoHeight, forceReload, LinkComponent, hasHeader, paginationMode, defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, customActions, optionsAC, defaultValues, disableScreenLoading, }: GenericModelListProps) => React.JSX.Element;
|
|
41
42
|
export default GenericModelList;
|
|
@@ -50,7 +50,7 @@ const utils_1 = require("../utils");
|
|
|
50
50
|
const api_1 = require("../api");
|
|
51
51
|
const DRFReactBySchemaContext_1 = require("../context/DRFReactBySchemaContext");
|
|
52
52
|
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
53
|
-
const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, reloadAfterRowUpdate, customColumnOperations, customFieldFormLayouts, customLinkDestination, isEditable, hasBulkSelect = false, onSelectActions, sumRows, isAutoHeight = true, forceReload = false, LinkComponent = null, hasHeader = false, paginationMode = 'client', defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, optionsAC, defaultValues, disableScreenLoading, }) => {
|
|
53
|
+
const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFields, disabledFields, minWidthFields, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, onProcessRow, reloadAfterRowUpdate, customColumnOperations, customFieldFormLayouts, customLinkDestination, isEditable, hasBulkSelect = false, onSelectActions, sumRows, isAutoHeight = true, forceReload = false, LinkComponent = null, hasHeader = false, paginationMode = 'client', defaultFilter, queryParams, hideFooterComponent, hideToolbarComponent, tableAutoHeight, actions, customActions, optionsAC, defaultValues, disableScreenLoading, }) => {
|
|
54
54
|
const { serverEndPoint, isInBatches, firstBatchLength } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
55
55
|
const { onEditModel } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
56
56
|
const [data, setData] = (0, react_1.useState)(false);
|
|
@@ -151,7 +151,7 @@ const GenericModelList = ({ model, columnFields, hiddenFields = [], creatableFie
|
|
|
151
151
|
react_1.default.createElement(LinkComponent, { to: `novo` },
|
|
152
152
|
react_1.default.createElement(Button_1.default, { variant: "contained", size: "medium", sx: { alignSelf: 'stretch' }, startIcon: react_1.default.createElement(AddCircleOutline_1.default, null) }, "Adicionar")))))),
|
|
153
153
|
react_1.default.createElement(Box_1.default, { sx: tableAutoHeight ? {} : styles_1.Layout.dataGridWithTabs },
|
|
154
|
-
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, loading: loading, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onSelectActions: onSelectActions, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, customFieldFormLayouts: customFieldFormLayouts, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, customLinkDestination: customLinkDestination, actions: actions, optionsAC: optionsAC, defaultValues: defaultValues, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
154
|
+
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema || {}, model: model, loading: loading, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onSelectActions: onSelectActions, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, customFieldFormLayouts: customFieldFormLayouts, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, customLinkDestination: customLinkDestination, actions: actions, customActions: customActions, optionsAC: optionsAC, defaultValues: defaultValues, onProcessRow: onProcessRow, onDataChange: (newData) => {
|
|
155
155
|
if (reloadAfterRowUpdate) {
|
|
156
156
|
loadObjectList();
|
|
157
157
|
return;
|
|
@@ -49,9 +49,9 @@ const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
|
49
49
|
const utils_1 = require("../utils");
|
|
50
50
|
const api_1 = require("../api");
|
|
51
51
|
const styles_1 = require("../styles");
|
|
52
|
-
const ContentTable = ({ data, relatedModel, model, loading, id, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, hideFooterComponent, hideToolbarComponent, onProcessRow, onDataChange, sumRows, visibleRows, paginationMode = 'client', paginationModel, setPaginationModel, hasBulkSelect, onSelectActions, tableAutoHeight, actions, optionsAC, defaultValues, LinkComponent, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
52
|
+
const ContentTable = ({ data, relatedModel, model, loading, id, indexField, indexFieldBasePath, indexFieldViewBasePath, addExistingModel, isEditable, onEditModel, finalCustomColumnOperations, setVisibleRows, isAutoHeight, hideFooterPagination, hideFooterComponent, hideToolbarComponent, onProcessRow, onDataChange, sumRows, visibleRows, paginationMode = 'client', paginationModel, setPaginationModel, hasBulkSelect, onSelectActions, tableAutoHeight, actions, customActions, optionsAC, defaultValues, LinkComponent, }) => (react_1.default.createElement(react_1.default.Fragment, null,
|
|
53
53
|
data.columns ? (react_1.default.createElement(Box_1.default, { sx: tableAutoHeight ? {} : styles_1.Layout.dataGridFixedHeight },
|
|
54
|
-
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema, model: relatedModel, modelParent: model, modelParentId: id, loading: loading, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onSelectActions: onSelectActions, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, actions: actions, optionsAC: optionsAC, defaultValues: defaultValues, onProcessRow: onProcessRow, onDataChange: onDataChange, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
54
|
+
react_1.default.createElement(DataGridBySchemaEditable_1.default, { data: data.data, columns: data.columns, schema: data.schema, model: relatedModel, modelParent: model, modelParentId: id, loading: loading, indexField: indexField, indexFieldBasePath: indexFieldBasePath, indexFieldViewBasePath: indexFieldViewBasePath, addExistingModel: addExistingModel, isEditable: isEditable, hasBulkSelect: hasBulkSelect, onSelectActions: onSelectActions, onEditModel: onEditModel, isAutoHeight: isAutoHeight, tableAutoHeight: tableAutoHeight, customColumnOperations: finalCustomColumnOperations, setVisibleRows: setVisibleRows, hideFooterPagination: hideFooterPagination, hideFooterComponent: hideFooterComponent, hideToolbarComponent: hideToolbarComponent, actions: actions, customActions: customActions, optionsAC: optionsAC, defaultValues: defaultValues, onProcessRow: onProcessRow, onDataChange: onDataChange, paginationModel: paginationMode === 'server' ? paginationModel : undefined, setPaginationModel: paginationMode === 'server' ? setPaginationModel : undefined, rowCount: paginationMode === 'client'
|
|
55
55
|
? undefined
|
|
56
56
|
: typeof data.rowCount !== undefined
|
|
57
57
|
? data.rowCount
|
|
@@ -165,17 +165,35 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
|
|
|
165
165
|
if (filteredOptions.length === 0) {
|
|
166
166
|
return [];
|
|
167
167
|
}
|
|
168
|
-
|
|
168
|
+
let filtered = filter(filteredOptions, params);
|
|
169
169
|
const { inputValue } = params;
|
|
170
170
|
const inputValueSlug = (0, utils_1.slugify)(inputValue);
|
|
171
|
+
const inputValueLength = inputValueSlug.length;
|
|
171
172
|
// Suggest the creation of a new value
|
|
172
|
-
const isExisting = filteredOptions.
|
|
173
|
+
const isExisting = filteredOptions.find((option) => inputValueSlug === (0, utils_1.slugify)(option.label));
|
|
173
174
|
if (inputValue !== '' && !isExisting) {
|
|
174
175
|
filtered.push({
|
|
175
176
|
inputValue,
|
|
176
177
|
label: `Criar "${inputValue}"`,
|
|
177
178
|
});
|
|
178
179
|
}
|
|
180
|
+
// Show first the exact match:
|
|
181
|
+
if (isExisting) {
|
|
182
|
+
filtered = [
|
|
183
|
+
isExisting,
|
|
184
|
+
...filtered.filter((option) => isExisting.id !== option.id),
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
// Show first the options that start with inputValue:
|
|
188
|
+
const startsWith = filtered.filter((option) => inputValueSlug ===
|
|
189
|
+
(0, utils_1.slugify)(option.label).substring(0, inputValueLength));
|
|
190
|
+
if (startsWith.length > 0) {
|
|
191
|
+
const startsWithIds = startsWith.map((option) => option.id);
|
|
192
|
+
filtered = [
|
|
193
|
+
...startsWith,
|
|
194
|
+
...filtered.filter((option) => !startsWithIds.includes(option.id)),
|
|
195
|
+
];
|
|
196
|
+
}
|
|
179
197
|
return filtered;
|
|
180
198
|
}, handleHomeEndKeys: true, getOptionLabel: getOptionLabel
|
|
181
199
|
? getOptionLabel
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import * as Yup from 'yup';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
3
|
import { GridActionsColDef, GridColDef, GridFilterModel, GridSortModel } from '@mui/x-data-grid';
|
|
4
4
|
import { Control, FieldValues, UseFormGetValues, UseFormSetValue } from 'react-hook-form';
|
|
5
5
|
import { AutocompleteRenderOptionState, SxProps } from '@mui/material';
|
|
@@ -183,6 +183,12 @@ export declare const slugToCamelCase: (str: string) => string;
|
|
|
183
183
|
export declare const slugify: (text: string | null) => string;
|
|
184
184
|
export declare function mergeFilterItems(defaultFilter: GridFilterModel | undefined, filter: GridFilterModel | undefined): GridFilterModel | undefined;
|
|
185
185
|
export type ActionType = 'editInline' | 'remove' | 'edit' | 'view';
|
|
186
|
+
export interface CustomAction {
|
|
187
|
+
key: string;
|
|
188
|
+
icon: ReactElement;
|
|
189
|
+
label: string;
|
|
190
|
+
handleClick: (item: Item | undefined) => undefined;
|
|
191
|
+
}
|
|
186
192
|
export type BulkUpdateData = (newData: Item[]) => Promise<{
|
|
187
193
|
id: Id;
|
|
188
194
|
success: boolean;
|
package/package.json
CHANGED