drf-react-by-schema 0.28.24 → 0.28.26
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/@types/index.d.ts +115 -6
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/api.d.ts +2 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +18 -9
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +1 -4
- package/dist/components/details/DetailBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailBySchema.js +152 -29
- package/dist/components/details/DetailFieldBySchema.d.ts +2 -2
- package/dist/components/details/DetailFieldBySchema.d.ts.map +1 -1
- package/dist/components/details/DetailFieldBySchema.js +49 -26
- package/dist/components/details/DetailPage.d.ts +8 -0
- package/dist/components/details/DetailPage.d.ts.map +1 -0
- package/dist/components/details/DetailPage.js +123 -0
- package/dist/components/details/detailPaths.d.ts +8 -0
- package/dist/components/details/detailPaths.d.ts.map +1 -0
- package/dist/components/details/detailPaths.js +41 -0
- package/dist/components/forms/FormBySchema.d.ts.map +1 -1
- package/dist/components/forms/FormBySchema.js +12 -1
- package/dist/hooks/useDetailData.d.ts +7 -0
- package/dist/hooks/useDetailData.d.ts.map +1 -0
- package/dist/hooks/useDetailData.js +70 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/utils/utils.d.ts +11 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +19 -2
- package/package.json +8 -3
|
@@ -114,6 +114,9 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
114
114
|
console.log(`there is no schema for field ${field}!`);
|
|
115
115
|
continue;
|
|
116
116
|
}
|
|
117
|
+
if (typeof field === 'string' && (0, utils_1.isReadOnlyField)(schema[field])) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
117
120
|
if (typeof field === 'string' &&
|
|
118
121
|
['field', 'nested object'].includes(schema[field].type) &&
|
|
119
122
|
!newOptionsACModels.includes(field)) {
|
|
@@ -150,7 +153,7 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
150
153
|
}
|
|
151
154
|
continue;
|
|
152
155
|
}
|
|
153
|
-
if (!(
|
|
156
|
+
if (!(0, utils_1.isReadOnlyField)(field)) {
|
|
154
157
|
rows.push(key);
|
|
155
158
|
}
|
|
156
159
|
}
|
|
@@ -249,6 +252,10 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
249
252
|
return null;
|
|
250
253
|
}
|
|
251
254
|
const field = row;
|
|
255
|
+
// Read-only fields may still be listed by an older layout.
|
|
256
|
+
if ((0, utils_1.isReadOnlyField)(schema[field])) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
252
259
|
const fieldProps = fieldsProps && field in fieldsProps
|
|
253
260
|
? fieldsProps[field]
|
|
254
261
|
: {};
|
|
@@ -283,6 +290,10 @@ sxRow, sxRowMultiple, sxSection, sxSectionTitle,
|
|
|
283
290
|
if (typeof field === 'string' && (hiddenFields === null || hiddenFields === void 0 ? void 0 : hiddenFields.includes(field))) {
|
|
284
291
|
return null;
|
|
285
292
|
}
|
|
293
|
+
if (typeof field === 'string' &&
|
|
294
|
+
(0, utils_1.isReadOnlyField)(schema[field])) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
286
297
|
const mr = i + 1 === j.length ? 0 : 2;
|
|
287
298
|
const key = typeof field === 'string' ? field : field.key;
|
|
288
299
|
const fieldProps = fieldsProps && key in fieldsProps
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TField, UseDetailDataProps, UseDetailDataResult } from '../@types';
|
|
2
|
+
/**
|
|
3
|
+
* Loads one detail record (schema + columns + values) in a single request.
|
|
4
|
+
* Independent from the router and from `pageForm`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useDetailData<T extends TField = void>({ model, objId, }: UseDetailDataProps<T>): UseDetailDataResult<T>;
|
|
7
|
+
//# sourceMappingURL=useDetailData.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDetailData.d.ts","sourceRoot":"","sources":["../../src/hooks/useDetailData.ts"],"names":[],"mappings":"AAGA,OAAO,EAIL,MAAM,EACN,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,WAAW,CAAC;AAInB;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EACrD,KAAK,EACL,KAAK,GACN,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsDhD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.useDetailData = useDetailData;
|
|
16
|
+
const react_1 = require("react");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const APIWrapperContext_1 = require("../context/APIWrapperContext");
|
|
19
|
+
const utils_1 = require("../utils/utils");
|
|
20
|
+
/**
|
|
21
|
+
* Loads one detail record (schema + columns + values) in a single request.
|
|
22
|
+
* Independent from the router and from `pageForm`.
|
|
23
|
+
*/
|
|
24
|
+
function useDetailData({ model, objId, }) {
|
|
25
|
+
const { getGenericModel } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
26
|
+
const [values, setValues] = (0, react_1.useState)(null);
|
|
27
|
+
const [schema, setSchema] = (0, react_1.useState)(null);
|
|
28
|
+
const [columns, setColumns] = (0, react_1.useState)([]);
|
|
29
|
+
const [loading, setLoading] = (0, react_1.useState)(Boolean(objId));
|
|
30
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
31
|
+
const [reloadIndex, setReloadIndex] = (0, react_1.useState)(0);
|
|
32
|
+
const requestId = (0, react_1.useRef)(0);
|
|
33
|
+
const reload = (0, react_1.useCallback)(() => setReloadIndex((index) => index + 1), []);
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
const currentRequest = ++requestId.current;
|
|
36
|
+
if (!objId) {
|
|
37
|
+
setValues(null);
|
|
38
|
+
setSchema(null);
|
|
39
|
+
setColumns([]);
|
|
40
|
+
setError(null);
|
|
41
|
+
setLoading(false);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setLoading(true);
|
|
45
|
+
setError(null);
|
|
46
|
+
const load = () => __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const response = yield getGenericModel({ model, id: objId });
|
|
48
|
+
if (currentRequest !== requestId.current) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (axios_1.default.isAxiosError(response)) {
|
|
52
|
+
setError(response);
|
|
53
|
+
setValues(null);
|
|
54
|
+
setSchema(null);
|
|
55
|
+
setColumns([]);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
setValues((0, utils_1.populateValues)({
|
|
59
|
+
data: response.data,
|
|
60
|
+
schema: response.schema,
|
|
61
|
+
}));
|
|
62
|
+
setSchema(response.schema);
|
|
63
|
+
setColumns(response.columns || []);
|
|
64
|
+
}
|
|
65
|
+
setLoading(false);
|
|
66
|
+
});
|
|
67
|
+
load();
|
|
68
|
+
}, [model, objId, getGenericModel, reloadIndex]);
|
|
69
|
+
return { values, schema, columns, loading, error, reload };
|
|
70
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { setAuthToken, hasJWT, clearJWT, AUTH_EXPIRED_EVENT } from './api';
|
|
2
|
-
import { emptyByType, getChoiceByValue, populateValues, enrichChoices, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, slugToCamelCase } from './utils';
|
|
1
|
+
import { setAuthToken, hasJWT, clearJWT, AUTH_EXPIRED_EVENT, getDataGridColumns } from './api';
|
|
2
|
+
import { emptyByType, getChoiceByValue, populateValues, enrichChoices, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, slugToCamelCase, isReadOnlyField, isRelationField } from './utils';
|
|
3
3
|
import DRFReactBySchemaProvider from './context/DRFReactBySchemaProvider';
|
|
4
4
|
import { useAPIWrapper } from './context/APIWrapperContext';
|
|
5
5
|
import Form from './components/forms/Form';
|
|
@@ -35,6 +35,8 @@ export { getThemeTexts } from './styles/texts';
|
|
|
35
35
|
export type { DRFReactBySchemaTexts, GeometryTexts, FormTexts, AuthTexts, RichTextTexts, } from './styles/texts';
|
|
36
36
|
import DetailBySchema from './components/details/DetailBySchema';
|
|
37
37
|
import DetailFieldBySchema from './components/details/DetailFieldBySchema';
|
|
38
|
-
|
|
38
|
+
import DetailPage from './components/details/DetailPage';
|
|
39
|
+
import { useDetailData } from './hooks/useDetailData';
|
|
40
|
+
export { DRFReactBySchemaProvider, useAPIWrapper, Form, DialogFormBySchema, ChangePasswordForm, ForgotPasswordForm, DataGridBySchemaEditable, GenericModelList, GenericRelatedModelList, DataTotals, DialogActions, FileTypeIcon, HtmlContent, SelectEditInputCell, GridDateInput, GridDecimalInput, GridPatternInput, BooleanInputCell, FormWatcher, FormBySchema, FieldBySchema, TextFieldBySchema, HtmlFieldBySchema, BooleanFieldBySchema, DesktopDatePickerBySchema, DesktopDateTimePickerBySchema, EditableAutocompleteFieldBySchema, AutocompleteFieldBySchema, FloatFieldBySchema, DetailBySchema, DetailFieldBySchema, DetailPage, useDetailData, setAuthToken, emptyByType, getChoiceByValue, populateValues, enrichChoices, buildGenericYupValidationSchema, getDataGridColumns, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, isReadOnlyField, isRelationField, getPatternFormat, clearJWT, hasJWT, slugToCamelCase, AUTH_EXPIRED_EVENT, };
|
|
39
41
|
export * from './@types/index';
|
|
40
42
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAC/F,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,+BAA+B,EAC/B,UAAU,EACV,0BAA0B,EAC1B,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EAChB,MAAM,SAAS,CAAC;AAGjB,OAAO,wBAAwB,MAAM,oCAAoC,CAAC;AAG1E,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,kBAAkB,MAAM,uCAAuC,CAAC;AACvE,OAAO,kBAAkB,MAAM,uCAAuC,CAAC;AACvE,OAA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AM,gBAAgB,CAAC;AAGxB,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,mBAAmB,MAAM,0CAA0C,CAAC;AAC3E,OAAO,UAAU,MAAM,iCAAiC,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,OAAO,EAEL,wBAAwB,EAGxB,aAAa,EAGb,IAAI,EACJ,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAGlB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,aAAa,EAGb,YAAY,EACZ,WAAW,EAGX,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAGhB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,iCAAiC,EACjC,yBAAyB,EACzB,kBAAkB,EAGlB,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,aAAa,EAGb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,+BAA+B,EAC/B,kBAAkB,EAClB,UAAU,EACV,0BAA0B,EAC1B,QAAQ,EACR,OAAO,EACP,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,eAAe,EACf,kBAAkB,GACnB,CAAC;AAEF,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,14 +17,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17
17
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.
|
|
21
|
-
exports.AUTH_EXPIRED_EVENT = void 0;
|
|
20
|
+
exports.isReadOnlyField = exports.isTmpId = exports.getTmpId = exports.getFieldErrorsFromResponse = exports.errorProps = exports.getDataGridColumns = exports.buildGenericYupValidationSchema = exports.enrichChoices = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.setAuthToken = exports.useDetailData = exports.DetailPage = exports.DetailFieldBySchema = exports.DetailBySchema = exports.FloatFieldBySchema = exports.AutocompleteFieldBySchema = exports.EditableAutocompleteFieldBySchema = exports.DesktopDateTimePickerBySchema = exports.DesktopDatePickerBySchema = exports.BooleanFieldBySchema = exports.HtmlFieldBySchema = exports.TextFieldBySchema = exports.FieldBySchema = exports.FormBySchema = exports.FormWatcher = exports.BooleanInputCell = exports.GridPatternInput = exports.GridDecimalInput = exports.GridDateInput = exports.SelectEditInputCell = exports.HtmlContent = exports.FileTypeIcon = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.ForgotPasswordForm = exports.ChangePasswordForm = exports.DialogFormBySchema = exports.Form = exports.useAPIWrapper = exports.DRFReactBySchemaProvider = exports.getThemeTexts = exports.DEFAULT_LAYERS = exports.DRF_REACT_BY_SCHEMA_MARKER_ICON = exports.applyThemeMarkerIcon = exports.applyDefaultLeafletIcon = void 0;
|
|
21
|
+
exports.AUTH_EXPIRED_EVENT = exports.slugToCamelCase = exports.hasJWT = exports.clearJWT = exports.getPatternFormat = exports.isRelationField = void 0;
|
|
22
22
|
// Methods:
|
|
23
23
|
const api_1 = require("./api");
|
|
24
24
|
Object.defineProperty(exports, "setAuthToken", { enumerable: true, get: function () { return api_1.setAuthToken; } });
|
|
25
25
|
Object.defineProperty(exports, "hasJWT", { enumerable: true, get: function () { return api_1.hasJWT; } });
|
|
26
26
|
Object.defineProperty(exports, "clearJWT", { enumerable: true, get: function () { return api_1.clearJWT; } });
|
|
27
27
|
Object.defineProperty(exports, "AUTH_EXPIRED_EVENT", { enumerable: true, get: function () { return api_1.AUTH_EXPIRED_EVENT; } });
|
|
28
|
+
Object.defineProperty(exports, "getDataGridColumns", { enumerable: true, get: function () { return api_1.getDataGridColumns; } });
|
|
28
29
|
const utils_1 = require("./utils");
|
|
29
30
|
Object.defineProperty(exports, "emptyByType", { enumerable: true, get: function () { return utils_1.emptyByType; } });
|
|
30
31
|
Object.defineProperty(exports, "getChoiceByValue", { enumerable: true, get: function () { return utils_1.getChoiceByValue; } });
|
|
@@ -37,6 +38,8 @@ Object.defineProperty(exports, "getTmpId", { enumerable: true, get: function ()
|
|
|
37
38
|
Object.defineProperty(exports, "isTmpId", { enumerable: true, get: function () { return utils_1.isTmpId; } });
|
|
38
39
|
Object.defineProperty(exports, "getPatternFormat", { enumerable: true, get: function () { return utils_1.getPatternFormat; } });
|
|
39
40
|
Object.defineProperty(exports, "slugToCamelCase", { enumerable: true, get: function () { return utils_1.slugToCamelCase; } });
|
|
41
|
+
Object.defineProperty(exports, "isReadOnlyField", { enumerable: true, get: function () { return utils_1.isReadOnlyField; } });
|
|
42
|
+
Object.defineProperty(exports, "isRelationField", { enumerable: true, get: function () { return utils_1.isRelationField; } });
|
|
40
43
|
// Overall Provider:
|
|
41
44
|
const DRFReactBySchemaProvider_1 = __importDefault(require("./context/DRFReactBySchemaProvider"));
|
|
42
45
|
exports.DRFReactBySchemaProvider = DRFReactBySchemaProvider_1.default;
|
|
@@ -114,4 +117,8 @@ const DetailBySchema_1 = __importDefault(require("./components/details/DetailByS
|
|
|
114
117
|
exports.DetailBySchema = DetailBySchema_1.default;
|
|
115
118
|
const DetailFieldBySchema_1 = __importDefault(require("./components/details/DetailFieldBySchema"));
|
|
116
119
|
exports.DetailFieldBySchema = DetailFieldBySchema_1.default;
|
|
120
|
+
const DetailPage_1 = __importDefault(require("./components/details/DetailPage"));
|
|
121
|
+
exports.DetailPage = DetailPage_1.default;
|
|
122
|
+
const useDetailData_1 = require("./hooks/useDetailData");
|
|
123
|
+
Object.defineProperty(exports, "useDetailData", { enumerable: true, get: function () { return useDetailData_1.useDetailData; } });
|
|
117
124
|
__exportStar(require("./@types/index"), exports);
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -10,6 +10,17 @@ export declare function populateValues({ data, schema }: {
|
|
|
10
10
|
data: Item;
|
|
11
11
|
schema: SchemaType;
|
|
12
12
|
}): Record<string, any>;
|
|
13
|
+
/**
|
|
14
|
+
* Relation fields (FK/M2M) are serialized with `read_only: true` by DRF, but the
|
|
15
|
+
* backend still writes them from the raw request body (`update_related`).
|
|
16
|
+
* They must stay editable and be sent, unlike derived (method) fields.
|
|
17
|
+
*/
|
|
18
|
+
export declare const isRelationField: (field?: Field | null) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a field is read-only for the client: derived values (SerializerMethod
|
|
21
|
+
* fields, ids, timestamps) must not be validated, sent or edited inline.
|
|
22
|
+
*/
|
|
23
|
+
export declare const isReadOnlyField: (field?: Field | null) => boolean;
|
|
13
24
|
export declare function buildGenericYupValidationSchema({ data, schema, many, skipFields, extraValidators, uiFields, }: {
|
|
14
25
|
data: Item;
|
|
15
26
|
schema: SchemaType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAEnC,OAAO,EACL,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,2BAA2B,EAE3B,eAAe,EACf,eAAe,EACf,KAAK,EAEL,eAAe,EACf,YAAY,EAEZ,iBAAiB,EACjB,0BAA0B,EAC1B,IAAI,EACJ,UAAU,EACV,MAAM,EACP,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,WAAW,EAAE,YA4BzB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,OAAO,WAAW,EAAE,SAAS,UAAU,EAAE,GAAG,SAAS,8BASrF,CAAC;AAIF,eAAO,MAAM,YAAY,GAAI,UAAU,YAAY,EAAE,SAAS,UAAU,EAAE,GAAG,S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CActC;AAED,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,YAAY,GAAG,MAAM,CAQjE;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC1B,OAAO,EAAE,iBAAiB,EAC1B,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,EAAE,GAAG,IAAI,CAaxD"}
|
package/dist/utils/utils.js
CHANGED
|
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
45
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
46
|
};
|
|
47
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.convertToFormData = exports.slugify = exports.slugToCamelCase = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.toChoiceItem = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
48
|
+
exports.convertToFormData = exports.slugify = exports.slugToCamelCase = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.isReadOnlyField = exports.isRelationField = exports.toChoiceItem = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
49
49
|
exports.enrichChoices = enrichChoices;
|
|
50
50
|
exports.populateValues = populateValues;
|
|
51
51
|
exports.buildGenericYupValidationSchema = buildGenericYupValidationSchema;
|
|
@@ -273,6 +273,19 @@ const getYupValidator = (type) => {
|
|
|
273
273
|
}
|
|
274
274
|
return yupFunc.transform((v) => (v === '' ? null : v)).nullable();
|
|
275
275
|
};
|
|
276
|
+
/**
|
|
277
|
+
* Relation fields (FK/M2M) are serialized with `read_only: true` by DRF, but the
|
|
278
|
+
* backend still writes them from the raw request body (`update_related`).
|
|
279
|
+
* They must stay editable and be sent, unlike derived (method) fields.
|
|
280
|
+
*/
|
|
281
|
+
const isRelationField = (field) => !!field && ['field', 'nested object'].includes(field.type);
|
|
282
|
+
exports.isRelationField = isRelationField;
|
|
283
|
+
/**
|
|
284
|
+
* Whether a field is read-only for the client: derived values (SerializerMethod
|
|
285
|
+
* fields, ids, timestamps) must not be validated, sent or edited inline.
|
|
286
|
+
*/
|
|
287
|
+
const isReadOnlyField = (field) => !!(field === null || field === void 0 ? void 0 : field.read_only) && !(0, exports.isRelationField)(field);
|
|
288
|
+
exports.isReadOnlyField = isReadOnlyField;
|
|
276
289
|
// Applies the "required" rules (including the at-least-one rule for many-fields)
|
|
277
290
|
// to an already built schema, used both statically and inside `when` conditions.
|
|
278
291
|
const buildRequiredSchema = (fieldSchema, schema) => {
|
|
@@ -292,7 +305,11 @@ function buildGenericYupValidationSchema({ data, schema, many = false, skipField
|
|
|
292
305
|
const conditionalVisible = buildConditionalVisibleBySchema(schema);
|
|
293
306
|
for (const entry of Object.entries(schema)) {
|
|
294
307
|
const [field, fieldSchema] = entry;
|
|
295
|
-
if (!data ||
|
|
308
|
+
if (!data ||
|
|
309
|
+
!(field in data) ||
|
|
310
|
+
field === 'id' ||
|
|
311
|
+
skipFields.includes(field) ||
|
|
312
|
+
(0, exports.isReadOnlyField)(fieldSchema)) {
|
|
296
313
|
continue;
|
|
297
314
|
}
|
|
298
315
|
// OneToMany or ManyToMany (built as an array-of-object schema):
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drf-react-by-schema",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.26",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "vitest run",
|
|
9
9
|
"build": "tsc --build",
|
|
10
10
|
"release:prepare": "npm run build",
|
|
11
11
|
"release:major": "npm run release:prepare && npm version major && git push origin master --tags && git push origin master:published",
|
|
12
12
|
"release:minor": "npm run release:prepare && npm version minor && git push origin master --tags && git push origin master:published",
|
|
13
|
-
"release:patch": "npm run release:prepare && npm version patch && git push origin master --tags && git push origin master:published"
|
|
13
|
+
"release:patch": "npm run release:prepare && npm version patch && git push origin master --tags && git push origin master:published",
|
|
14
|
+
"test:watch": "vitest"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|
|
@@ -47,6 +48,8 @@
|
|
|
47
48
|
"@mui/material": "^6",
|
|
48
49
|
"@mui/x-data-grid": "^7",
|
|
49
50
|
"@mui/x-date-pickers": "^7",
|
|
51
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
52
|
+
"@testing-library/react": "^16.3.3",
|
|
50
53
|
"@types/leaflet": "^1.9.22",
|
|
51
54
|
"@types/leaflet-draw": "^1.0.13",
|
|
52
55
|
"@types/node": "^18.11.15",
|
|
@@ -61,6 +64,7 @@
|
|
|
61
64
|
"eslint-plugin-prettier": "^5.0.0",
|
|
62
65
|
"eslint-plugin-react": "^7.37.5",
|
|
63
66
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
67
|
+
"jsdom": "^26.1.0",
|
|
64
68
|
"leaflet": "^1.9.4",
|
|
65
69
|
"leaflet-draw": "^1.0.4",
|
|
66
70
|
"prettier": "^3.0.0",
|
|
@@ -74,6 +78,7 @@
|
|
|
74
78
|
"string-mask": "^0.3.0",
|
|
75
79
|
"ts-loader": "^9.4.2",
|
|
76
80
|
"typescript": "^5.7.3",
|
|
81
|
+
"vitest": "^3.2.7",
|
|
77
82
|
"webpack": "^5.75.0",
|
|
78
83
|
"yup": "^1"
|
|
79
84
|
},
|