drf-react-by-schema 0.18.3 → 0.18.4

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.
@@ -56,7 +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
+ const [loadedOptionsAC, setLoadedOptionsAC] = (0, react_1.useState)(null);
60
60
  // TODO: allow edit option label, as in formautocomplete!
61
61
  const apiRef = (0, x_data_grid_1.useGridApiContext)();
62
62
  const handleChange = (newValue) => __awaiter(this, void 0, void 0, function* () {
@@ -122,17 +122,19 @@ function SelectEditInputCell({ field, id, value, column, type, optionsAC, isInde
122
122
  }
123
123
  (0, react_1.useEffect)(() => {
124
124
  if (!optionsAC || !(field in optionsAC)) {
125
- setOptions([]);
126
125
  return;
127
126
  }
128
- const thisOptionsAC = optionsAC[field];
129
- if (Array.isArray(thisOptionsAC)) {
130
- setOptions(thisOptionsAC);
127
+ const thisOptions = optionsAC[field];
128
+ if (Array.isArray(thisOptions)) {
129
+ setLoadedOptionsAC(Object.assign(Object.assign({}, loadedOptionsAC), { [field]: thisOptions }));
131
130
  return;
132
131
  }
133
- thisOptionsAC().then((newOptions) => setOptions(newOptions));
132
+ thisOptions().then((newOptions) => setLoadedOptionsAC(Object.assign(Object.assign({}, loadedOptionsAC), { [field]: newOptions })));
134
133
  }, [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) => {
134
+ if (loadedOptionsAC === null) {
135
+ return react_1.default.createElement(react_1.default.Fragment, null);
136
+ }
137
+ return (react_1.default.createElement(Autocomplete_1.default, Object.assign({ key: field, id: field, value: value, options: loadedOptionsAC[field], selectOnFocus: true, autoHighlight: true, multiple: multiple, isOptionEqualToValue: (option, value) => {
136
138
  return option[labelKey] === value[labelKey];
137
139
  }, getOptionLabel: (option) => {
138
140
  return option ? option[labelKey] : '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drf-react-by-schema",
3
- "version": "0.18.3",
3
+ "version": "0.18.4",
4
4
  "description": "Components and Tools for building a React App having Django Rest Framework (DRF) as server",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",