drf-react-by-schema 0.7.4 → 0.7.5
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/SelectEditInputCell.d.ts +4 -4
- package/dist/components/DataGridBySchemaEditable/SelectEditInputCell.js +10 -17
- package/dist/components/forms/inputs/EditableAutocompleteFieldBySchema.js +2 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +11 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { SxProps } from
|
|
3
|
-
import { GridEnrichedBySchemaColDef } from
|
|
4
|
-
import { OptionsACType, OnEditModelType } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { SxProps } from '@mui/material';
|
|
3
|
+
import { GridEnrichedBySchemaColDef } from '../../utils';
|
|
4
|
+
import { OptionsACType, OnEditModelType } from '../../context/APIWrapperContext';
|
|
5
5
|
interface SelectEditInputCellProps {
|
|
6
6
|
field: string;
|
|
7
7
|
id: number | string;
|
|
@@ -67,25 +67,20 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
67
67
|
yield apiRef.current.setEditCellValue({ id, field, value: newValue });
|
|
68
68
|
apiRef.current.stopCellEditMode({ id, field });
|
|
69
69
|
});
|
|
70
|
-
const labelKey = [
|
|
71
|
-
|
|
72
|
-
: "display_name";
|
|
73
|
-
const valueKey = ["field", "nested object"].includes(type) || isIndexField
|
|
74
|
-
? "id"
|
|
75
|
-
: "value";
|
|
70
|
+
const labelKey = ['field', 'nested object'].includes(type) || isIndexField ? 'label' : 'display_name';
|
|
71
|
+
const valueKey = ['field', 'nested object'].includes(type) || isIndexField ? 'id' : 'value';
|
|
76
72
|
let creatableProps = {};
|
|
77
73
|
// if (column.creatable || isIndexField) {
|
|
78
74
|
if (column.creatable) {
|
|
79
75
|
creatableProps = {
|
|
80
|
-
freesolo:
|
|
76
|
+
freesolo: 'true',
|
|
81
77
|
filterOptions: (options, params) => {
|
|
82
78
|
const filtered = filter(options, params);
|
|
83
|
-
const inputValue = params.inputValue ? params.inputValue :
|
|
84
|
-
const inputValueLower =
|
|
79
|
+
const inputValue = params.inputValue ? params.inputValue : '';
|
|
80
|
+
const inputValueLower = (0, utils_1.slugify)(inputValue);
|
|
85
81
|
// Suggest the creation of a new value
|
|
86
|
-
const isExisting = options.some((option) => inputValueLower ===
|
|
87
|
-
|
|
88
|
-
if (inputValue !== "" && !isExisting) {
|
|
82
|
+
const isExisting = options.some((option) => inputValueLower === (0, utils_1.slugify)(option[labelKey]));
|
|
83
|
+
if (inputValue !== '' && !isExisting) {
|
|
89
84
|
filtered.push({
|
|
90
85
|
inputValue,
|
|
91
86
|
[labelKey]: `Criar "${inputValue}"`,
|
|
@@ -96,7 +91,7 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
96
91
|
handleHomeEndKeys: true,
|
|
97
92
|
getOptionLabel: (option) => {
|
|
98
93
|
// Value selected with enter, right from the input
|
|
99
|
-
if (typeof option ===
|
|
94
|
+
if (typeof option === 'string') {
|
|
100
95
|
return option;
|
|
101
96
|
}
|
|
102
97
|
// Criar "xxx" option created dynamically
|
|
@@ -111,9 +106,7 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
111
106
|
},
|
|
112
107
|
};
|
|
113
108
|
}
|
|
114
|
-
return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, id: field, value: value, options: optionsAC.current && optionsAC.current[field]
|
|
115
|
-
? optionsAC.current[field]
|
|
116
|
-
: [], selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option, value) => {
|
|
109
|
+
return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, id: field, value: value, options: optionsAC.current && optionsAC.current[field] ? optionsAC.current[field] : [], selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option, value) => {
|
|
117
110
|
return option[labelKey] === value[labelKey];
|
|
118
111
|
}, getOptionLabel: (option) => {
|
|
119
112
|
return option[labelKey];
|
|
@@ -124,7 +117,7 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
124
117
|
return;
|
|
125
118
|
}
|
|
126
119
|
let newValue = value;
|
|
127
|
-
if (typeof newValue ===
|
|
120
|
+
if (typeof newValue === 'string') {
|
|
128
121
|
const tmpId = (0, utils_1.getTmpId)();
|
|
129
122
|
newValue = {
|
|
130
123
|
[valueKey]: tmpId,
|
|
@@ -152,8 +152,9 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
|
|
|
152
152
|
params.InputProps.endAdornment)) }) }, other))), freeSolo: true, filterOptions: (options, params) => {
|
|
153
153
|
const filtered = filter(options, params);
|
|
154
154
|
const { inputValue } = params;
|
|
155
|
+
const inputValueSlug = (0, utils_1.slugify)(inputValue);
|
|
155
156
|
// Suggest the creation of a new value
|
|
156
|
-
const isExisting = options.some((option) =>
|
|
157
|
+
const isExisting = options.some((option) => inputValueSlug === (0, utils_1.slugify)(option.label));
|
|
157
158
|
if (inputValue !== '' && !isExisting) {
|
|
158
159
|
filtered.push({
|
|
159
160
|
inputValue,
|
package/dist/utils.d.ts
CHANGED
|
@@ -137,4 +137,5 @@ export declare const getPatternFormat: (type: string) => string;
|
|
|
137
137
|
export type AddParametersToEnd<TFunction extends (...args: any) => any, TParameters extends [...args: any]> = (...args: [...Parameters<TFunction>, ...TParameters]) => ReturnType<TFunction>;
|
|
138
138
|
export declare function buildDateFormatBySchema(dateViews: string[] | null | undefined): "DD/MM/yyyy" | "MM/yyyy" | "yyyy" | "MM" | "DD";
|
|
139
139
|
export declare const slugToCamelCase: (str: string) => string;
|
|
140
|
+
export declare const slugify: (text: string) => string;
|
|
140
141
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.slugToCamelCase = exports.buildDateFormatBySchema = exports.getPatternFormat = exports.reducer = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
26
|
+
exports.slugify = exports.slugToCamelCase = exports.buildDateFormatBySchema = exports.getPatternFormat = exports.reducer = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
27
27
|
const Yup = __importStar(require("yup"));
|
|
28
28
|
const emptyByType = (field, forDatabase = false) => {
|
|
29
29
|
if (field.model_default) {
|
|
@@ -318,3 +318,13 @@ const slugToCamelCase = (str) => {
|
|
|
318
318
|
return ret;
|
|
319
319
|
};
|
|
320
320
|
exports.slugToCamelCase = slugToCamelCase;
|
|
321
|
+
const slugify = (text) => text
|
|
322
|
+
.toString()
|
|
323
|
+
.normalize('NFD')
|
|
324
|
+
.replace(/[\u0300-\u036f]/g, '')
|
|
325
|
+
.toLowerCase()
|
|
326
|
+
.trim()
|
|
327
|
+
.replace(/\s+/g, '-')
|
|
328
|
+
.replace(/[^\w-]+/g, '')
|
|
329
|
+
.replace(/--+/g, '-');
|
|
330
|
+
exports.slugify = slugify;
|
package/package.json
CHANGED