drf-react-by-schema 0.17.5 → 0.17.7

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/api.js CHANGED
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAllModels = exports.getGenericModel = exports.getGenericModelList = exports.signUp = exports.getSignUpOptions = exports.isLoggedIn = exports.setAuthToken = exports.hasJWT = exports.clearJWT = exports.loginByPayload = exports.getAutoComplete = exports.addExistingRelatedModel = exports.updateDataBySchema = exports.createOrUpdateData = exports.deleteData = exports.createData = exports.partialUpdateData = exports.updateData = exports.getRawData = void 0;
16
16
  const axios_1 = __importDefault(require("axios"));
17
17
  const moment_1 = __importDefault(require("moment"));
18
+ const dayjs_1 = __importDefault(require("dayjs"));
18
19
  const utils_1 = require("./utils");
19
20
  const expiredTokenMessage = 'Token expired! System must login again';
20
21
  const noServerEndPointMessage = 'There is not API definition (serverEndPoint)!';
@@ -449,8 +450,7 @@ const prepareDataBySchema = ({ data, schema }) => {
449
450
  }
450
451
  // Date:
451
452
  if (field.type === 'date') {
452
- const date = (0, moment_1.default)(data[key]);
453
- dbData[key] = date.format('YYYY-MM-DD');
453
+ dbData[key] = (0, dayjs_1.default)(data[key]).format('YYYY-MM-DD');
454
454
  continue;
455
455
  }
456
456
  // DateTime:
@@ -613,7 +613,7 @@ const getSignUpOptions = (serverEndPoint) => __awaiter(void 0, void 0, void 0, f
613
613
  const url = serverEndPoint.signUp;
614
614
  try {
615
615
  const { data } = yield axios_1.default.options(url);
616
- return data.actions.POST;
616
+ return data.action.POST;
617
617
  }
618
618
  catch (e) {
619
619
  const message = `Error fetching options from ${url}`;
@@ -18,6 +18,7 @@ const x_data_grid_1 = require("@mui/x-data-grid");
18
18
  const DesktopDatePicker_1 = require("@mui/x-date-pickers/DesktopDatePicker");
19
19
  const LocalizationProvider_1 = require("@mui/x-date-pickers/LocalizationProvider");
20
20
  const AdapterDayjs_1 = require("@mui/x-date-pickers/AdapterDayjs");
21
+ const dayjs_1 = __importDefault(require("dayjs"));
21
22
  const utils_1 = require("../../utils");
22
23
  function buildOpenTo(dateViews) {
23
24
  if (!dateViews || dateViews.includes('day')) {
@@ -37,7 +38,7 @@ const GridDateInput = ({ id, value, field, dateViews }) => {
37
38
  });
38
39
  const openTo = buildOpenTo(dateViews);
39
40
  return (react_1.default.createElement(LocalizationProvider_1.LocalizationProvider, { dateAdapter: AdapterDayjs_1.AdapterDayjs, adapterLocale: "pt-br" },
40
- react_1.default.createElement(DesktopDatePicker_1.DesktopDatePicker, { key: field, value: value, onChange: handleChange, views: dateViews, openTo: openTo, format: inputFormat, slotProps: {
41
+ react_1.default.createElement(DesktopDatePicker_1.DesktopDatePicker, { key: field, value: (0, dayjs_1.default)(value), onChange: handleChange, views: dateViews, openTo: openTo, format: inputFormat, slotProps: {
41
42
  textField: {
42
43
  margin: 'normal',
43
44
  },
@@ -165,17 +165,35 @@ const EditableAutocompleteFieldBySchema = react_1.default.forwardRef((_a, ref) =
165
165
  if (filteredOptions.length === 0) {
166
166
  return [];
167
167
  }
168
- const filtered = filter(filteredOptions, params);
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.some((option) => inputValueSlug === (0, utils_1.slugify)(option.label));
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
@@ -35,6 +35,11 @@ export type SchemaOptionsType = {
35
35
  verbose_name: string;
36
36
  verbose_name_plural: string;
37
37
  };
38
+ export type SchemaOptionsSingleActionType = Omit<SchemaOptionsType, 'actions'> & {
39
+ action: {
40
+ POST: SchemaType;
41
+ };
42
+ };
38
43
  export type modelOptionsType = Omit<SchemaOptionsType, 'actions' | 'renders' | 'parses'>;
39
44
  export type ChoiceValue = string | number;
40
45
  export interface Choice {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drf-react-by-schema",
3
- "version": "0.17.5",
3
+ "version": "0.17.7",
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",