drf-react-by-schema 0.18.2 → 0.18.3
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SxProps } from '@mui/material';
|
|
2
|
-
import { FormFieldLayout, GenericValue,
|
|
2
|
+
import { FormFieldLayout, GenericValue, OptionsACWithLoaders } from '../../utils';
|
|
3
3
|
import { GridEnrichedBySchemaColDef } from '../../utils';
|
|
4
4
|
import { DialogType, OnEditModelType } from '../../context/APIWrapperContext';
|
|
5
5
|
interface SelectEditInputCellProps {
|
|
@@ -8,7 +8,7 @@ interface SelectEditInputCellProps {
|
|
|
8
8
|
value?: GenericValue;
|
|
9
9
|
column: GridEnrichedBySchemaColDef;
|
|
10
10
|
type: string;
|
|
11
|
-
optionsAC:
|
|
11
|
+
optionsAC: OptionsACWithLoaders | null;
|
|
12
12
|
isIndexField: boolean;
|
|
13
13
|
multiple?: boolean;
|
|
14
14
|
onEditModel?: (x: OnEditModelType) => void;
|
|
@@ -46,7 +46,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
48
|
exports.SelectEditInputCell = SelectEditInputCell;
|
|
49
|
-
const react_1 =
|
|
49
|
+
const react_1 = __importStar(require("react"));
|
|
50
50
|
const x_data_grid_1 = require("@mui/x-data-grid");
|
|
51
51
|
const TextField_1 = __importDefault(require("@mui/material/TextField"));
|
|
52
52
|
const IconButton_1 = __importDefault(require("@mui/material/IconButton"));
|
|
@@ -56,6 +56,7 @@ const utils_1 = require("../../utils");
|
|
|
56
56
|
const DialogActions_1 = __importDefault(require("../DialogActions"));
|
|
57
57
|
const filter = (0, Autocomplete_1.createFilterOptions)();
|
|
58
58
|
function SelectEditInputCell({ field, id, value, column, type, optionsAC, isIndexField, multiple = false, onEditModel, fieldsLayout, sx = {}, setDialog, }) {
|
|
59
|
+
const [options, setOptions] = (0, react_1.useState)([]);
|
|
59
60
|
// TODO: allow edit option label, as in formautocomplete!
|
|
60
61
|
const apiRef = (0, x_data_grid_1.useGridApiContext)();
|
|
61
62
|
const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -119,7 +120,19 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
|
|
|
119
120
|
},
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
|
-
|
|
123
|
+
(0, react_1.useEffect)(() => {
|
|
124
|
+
if (!optionsAC || !(field in optionsAC)) {
|
|
125
|
+
setOptions([]);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const thisOptionsAC = optionsAC[field];
|
|
129
|
+
if (Array.isArray(thisOptionsAC)) {
|
|
130
|
+
setOptions(thisOptionsAC);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
thisOptionsAC().then((newOptions) => setOptions(newOptions));
|
|
134
|
+
}, [optionsAC, field]);
|
|
135
|
+
return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, id: field, value: value, options: options, selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option, value) => {
|
|
123
136
|
return option[labelKey] === value[labelKey];
|
|
124
137
|
}, getOptionLabel: (option) => {
|
|
125
138
|
return option ? option[labelKey] : '';
|
package/dist/utils.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type Id = string | number | null;
|
|
|
10
10
|
export type GenericValue = any;
|
|
11
11
|
export type Item = Record<string, GenericValue>;
|
|
12
12
|
export type OptionsAC = Record<string, Item[]>;
|
|
13
|
+
export type OptionsACWithLoaders = Record<string, Item[] | (() => Promise<Item[]>)>;
|
|
13
14
|
export type PaginatedResult = {
|
|
14
15
|
count: number;
|
|
15
16
|
next: number;
|
package/package.json
CHANGED