drf-react-by-schema 0.7.4 → 0.7.6

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
@@ -502,7 +502,7 @@ const signUp = (data, serverEndPoint) => __awaiter(void 0, void 0, void 0, funct
502
502
  const url = serverEndPoint.signUp;
503
503
  try {
504
504
  const response = yield axios_1.default.post(url, data);
505
- console.log(response);
505
+ // console.log(response);
506
506
  return response;
507
507
  }
508
508
  catch (e) {
@@ -1,7 +1,7 @@
1
- import React from "react";
2
- import { SxProps } from "@mui/material";
3
- import { GridEnrichedBySchemaColDef } from "../../utils";
4
- import { OptionsACType, OnEditModelType } from "../../context/APIWrapperContext";
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 = ["field", "nested object"].includes(type) || isIndexField
71
- ? "label"
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: "true",
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 = inputValue.trim().toLowerCase();
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
- option[labelKey].trim().toLowerCase());
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 === "string") {
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 === "string") {
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) => inputValue === option.label);
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,
@@ -21,11 +21,15 @@ const DRFReactBySchemaProvider = ({ serverEndPoint, theme, isInBatches, firstBat
21
21
  'autocomplete',
22
22
  'api',
23
23
  ['JSONSchema', 'jsonschema'],
24
- ['getToken', ''],
24
+ 'getToken',
25
25
  ['refreshToken', 'refresh'],
26
26
  ['verifyToken', 'verify'],
27
27
  ];
28
28
  for (const key of defaultKeys) {
29
+ if (key === 'getToken') {
30
+ serverEndPoint[key] = serverEndPoint.apiTokenUrl;
31
+ continue;
32
+ }
29
33
  const hybridKey = typeof key === 'string'
30
34
  ? key
31
35
  : key[0];
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drf-react-by-schema",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
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",