drf-react-by-schema 0.17.10 → 0.17.11
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.
|
@@ -60,17 +60,34 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
60
60
|
creatableProps = {
|
|
61
61
|
freesolo: 'true',
|
|
62
62
|
filterOptions: (options, params) => {
|
|
63
|
-
|
|
63
|
+
let filtered = filter(options, params);
|
|
64
64
|
const inputValue = params.inputValue ? params.inputValue : '';
|
|
65
|
-
const
|
|
65
|
+
const inputValueSlug = (0, utils_1.slugify)(inputValue);
|
|
66
|
+
const inputValueLength = inputValueSlug.length;
|
|
66
67
|
// Suggest the creation of a new value
|
|
67
|
-
const isExisting = options.
|
|
68
|
+
const isExisting = options.find((option) => inputValueSlug === (0, utils_1.slugify)(option[labelKey]));
|
|
68
69
|
if (inputValue !== '' && !isExisting) {
|
|
69
70
|
filtered.push({
|
|
70
71
|
inputValue,
|
|
71
72
|
[labelKey]: `Criar "${inputValue}"`,
|
|
72
73
|
});
|
|
73
74
|
}
|
|
75
|
+
// Show first the exact match:
|
|
76
|
+
if (isExisting) {
|
|
77
|
+
filtered = [
|
|
78
|
+
isExisting,
|
|
79
|
+
...filtered.filter((option) => isExisting.id !== option.id),
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
// Show first the options that start with inputValue:
|
|
83
|
+
const startsWith = filtered.filter((option) => inputValueSlug === (0, utils_1.slugify)(option.label).substring(0, inputValueLength));
|
|
84
|
+
if (startsWith.length > 0) {
|
|
85
|
+
const startsWithIds = startsWith.map((option) => option.id);
|
|
86
|
+
filtered = [
|
|
87
|
+
...startsWith,
|
|
88
|
+
...filtered.filter((option) => !startsWithIds.includes(option.id)),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
74
91
|
return filtered;
|
|
75
92
|
},
|
|
76
93
|
handleHomeEndKeys: true,
|
package/package.json
CHANGED