drf-react-by-schema 0.28.4 → 0.28.5
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.d.ts.map +1 -1
- package/dist/api.js +14 -0
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.d.ts.map +1 -1
- package/dist/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.js +2 -17
- package/dist/components/DataGridBySchemaEditable/utils/columnFactory.js +10 -10
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts +10 -1
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.d.ts.map +1 -1
- package/dist/components/forms/inputs/AutocompleteFieldBySchema.js +11 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/utils/utils.d.ts +2 -0
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +40 -6
- package/package.json +1 -1
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EACL,IAAI,EACJ,UAAU,EACV,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,EAAE,EAGF,eAAe,EAEf,mBAAmB,EACnB,wBAAwB,EAExB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAGhB,KAAK,EAEL,MAAM,EACN,eAAe,EAChB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAA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CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,EAAE,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,cAAc,EAAE,cAAc,GAAG,IAAI,CAAC;CACvC,KAAG,OAAO,CAAC,IAAI,GAAG,UAAU,CAiF5B,CAAC"}
|
package/dist/api.js
CHANGED
|
@@ -536,6 +536,14 @@ function prepareDataBySchemaRecursive({ data: typedData, schema, }) {
|
|
|
536
536
|
dbData[key] = value.value;
|
|
537
537
|
continue;
|
|
538
538
|
}
|
|
539
|
+
// Multiple-choice lists: unwrap {value, display_name} objects to raw .value
|
|
540
|
+
// for the backend; raw values already present are passed through unchanged.
|
|
541
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === 'list' || (field === null || field === void 0 ? void 0 : field.type) === 'multiple choice') {
|
|
542
|
+
dbData[key] = Array.isArray(value)
|
|
543
|
+
? value.map((choice) => typeof choice === 'object' && choice !== null ? choice.value : choice)
|
|
544
|
+
: value;
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
539
547
|
// Date:
|
|
540
548
|
if ((field === null || field === void 0 ? void 0 : field.type) === 'date') {
|
|
541
549
|
dbData[key] = (0, dayjs_1.default)(value).format('YYYY-MM-DD');
|
|
@@ -903,6 +911,12 @@ function getGenericModelList(_a) {
|
|
|
903
911
|
: (0, utils_1.emptyByType)(field);
|
|
904
912
|
continue;
|
|
905
913
|
}
|
|
914
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === 'list' || (field === null || field === void 0 ? void 0 : field.type) === 'multiple choice') {
|
|
915
|
+
newRow[key] = Array.isArray(row[key])
|
|
916
|
+
? row[key].map((entry) => { var _a; return (0, utils_1.toChoiceItem)(entry, (_a = field.child) === null || _a === void 0 ? void 0 : _a.choices); })
|
|
917
|
+
: (0, utils_1.emptyByType)(field);
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
906
920
|
newRow[key] = row[key] ? row[key] : (0, utils_1.emptyByType)(field);
|
|
907
921
|
}
|
|
908
922
|
return newRow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useProcessRowUpdate.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAmB,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EACL,IAAI,EACJ,UAAU,EACV,EAAE,EACF,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,QAAQ,EACR,MAAM,EACP,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"useProcessRowUpdate.d.ts","sourceRoot":"","sources":["../../../../src/components/DataGridBySchemaEditable/hooks/useProcessRowUpdate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAmB,MAAM,KAAK,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAChF,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EACL,IAAI,EACJ,UAAU,EACV,EAAE,EACF,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,QAAQ,EACR,MAAM,EACP,MAAM,iBAAiB,CAAC;AAUzB,UAAU,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI;IACxD,eAAe,EAAE,0BAA0B,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;IACxD,mBAAmB,EAAE,SAAS,GAAG,IAAI,CAAC;IACtC,kBAAkB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IACxB,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;IACvD,mBAAmB,EAAE,KAAK,CAAC,QAAQ,CACjC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAChE,CAAC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACpC,eAAe,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC;IAClE,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACrC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;IACrC,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC/C;AAED,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,uPAkB1D,wBAAwB,CAAC,CAAC,CAAC;kCAEe,IAAI,CAAC,CAAC,CAAC,eAAe,IAAI,CAAC,CAAC,CAAC;CAoMzE,CAAC"}
|
|
@@ -21,21 +21,6 @@ const utils_2 = require("../utils");
|
|
|
21
21
|
function isYupValidationError(err) {
|
|
22
22
|
return err instanceof Error && err.name === 'ValidationError';
|
|
23
23
|
}
|
|
24
|
-
// Backends return choice fields as raw values; reshape them into
|
|
25
|
-
// {value, display_name} objects like populateValues does on list load, so every
|
|
26
|
-
// grid row (load + inline-save) stays consistent.
|
|
27
|
-
function enrichChoices(rawData, schema) {
|
|
28
|
-
const out = Object.assign({}, rawData);
|
|
29
|
-
for (const [key, field] of Object.entries(schema)) {
|
|
30
|
-
if (!(key in rawData) || (field === null || field === void 0 ? void 0 : field.type) !== 'choice')
|
|
31
|
-
continue;
|
|
32
|
-
const rawValue = rawData[key];
|
|
33
|
-
out[key] = rawValue
|
|
34
|
-
? { value: rawValue, display_name: (0, utils_1.getChoiceByValue)(rawValue, field.choices) }
|
|
35
|
-
: (0, utils_1.emptyByType)(field);
|
|
36
|
-
}
|
|
37
|
-
return out;
|
|
38
|
-
}
|
|
39
24
|
const useProcessRowUpdate = ({ preparedColumns, yupValidationSchema, setDataGridLoading, indexField, processingRow, setValidationErrors, modelParent, modelParentId, model, schema, addExistingModel, updateOptionsAC, apiRef, setDataGridRows, onProcessRow, handleStopEditing,
|
|
40
25
|
// extraValidators, // TODO: Check why this is missing
|
|
41
26
|
}) => {
|
|
@@ -148,7 +133,7 @@ const useProcessRowUpdate = ({ preparedColumns, yupValidationSchema, setDataGrid
|
|
|
148
133
|
return newState;
|
|
149
134
|
});
|
|
150
135
|
updateOptionsAC();
|
|
151
|
-
const newRow = enrichChoices('data' in response && 'schema' in response ? response.data : response, schema);
|
|
136
|
+
const newRow = (0, utils_1.enrichChoices)('data' in response && 'schema' in response ? response.data : response, schema);
|
|
152
137
|
if (onProcessRow) {
|
|
153
138
|
onProcessRow(newRow);
|
|
154
139
|
}
|
|
@@ -194,7 +179,7 @@ const useProcessRowUpdate = ({ preparedColumns, yupValidationSchema, setDataGrid
|
|
|
194
179
|
return newState;
|
|
195
180
|
});
|
|
196
181
|
updateOptionsAC();
|
|
197
|
-
const newRow = enrichChoices('data' in response && 'schema' in response ? response.data : response, schema);
|
|
182
|
+
const newRow = (0, utils_1.enrichChoices)('data' in response && 'schema' in response ? response.data : response, schema);
|
|
198
183
|
(0, utils_2.updateRow)({
|
|
199
184
|
newRow,
|
|
200
185
|
originalId: editedRow.id,
|
|
@@ -108,12 +108,16 @@ function buildPreparedColumns(_a) {
|
|
|
108
108
|
case 'choice':
|
|
109
109
|
case 'list':
|
|
110
110
|
column.minWidth = 150;
|
|
111
|
+
// Values are already option objects ({value, display_name} or {id,
|
|
112
|
+
// label}); single = one object, multiple = an array of objects.
|
|
113
|
+
const formatChoiceValue = (value) => {
|
|
114
|
+
if (Array.isArray(value)) {
|
|
115
|
+
return value.map((v) => (v === null || v === void 0 ? void 0 : v.label) || (v === null || v === void 0 ? void 0 : v.display_name) || '').join(', ');
|
|
116
|
+
}
|
|
117
|
+
return (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.display_name) || '';
|
|
118
|
+
};
|
|
111
119
|
if (isEditable && !col.disabled) {
|
|
112
|
-
column.valueFormatter =
|
|
113
|
-
if (Array.isArray(value))
|
|
114
|
-
return value.map((v) => v.label || v.display_name || v).join(', ');
|
|
115
|
-
return (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.display_name) || value || '';
|
|
116
|
-
};
|
|
120
|
+
column.valueFormatter = formatChoiceValue;
|
|
117
121
|
column.renderEditCell = (p) => {
|
|
118
122
|
var _a;
|
|
119
123
|
const err = (_a = validationErrors[p.id]) === null || _a === void 0 ? void 0 : _a[p.field];
|
|
@@ -125,11 +129,7 @@ function buildPreparedColumns(_a) {
|
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
else {
|
|
128
|
-
column.valueGetter =
|
|
129
|
-
if (Array.isArray(value))
|
|
130
|
-
return value.map((v) => v.label || v.display_name || v).join(', ');
|
|
131
|
-
return (value === null || value === void 0 ? void 0 : value.label) || (value === null || value === void 0 ? void 0 : value.display_name) || value || '';
|
|
132
|
-
};
|
|
132
|
+
column.valueGetter = formatChoiceValue;
|
|
133
133
|
}
|
|
134
134
|
break;
|
|
135
135
|
case 'boolean':
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { FieldBySchemaProps } from '../../../@types';
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Choice/list picker built on MUI Autocomplete.
|
|
5
|
+
*
|
|
6
|
+
* `options` must be objects, and the current form `value` must match them: a
|
|
7
|
+
* single option object, or (when `multiple`) an array of option objects. The
|
|
8
|
+
* option shape is defined by `optionIdKey`/`optionLabelKey` (defaults
|
|
9
|
+
* `'id'`/`'label'`); it is NOT raw values/strings. Seed forms with
|
|
10
|
+
* populateValues() so values are already objects in the same format as options.
|
|
11
|
+
*/
|
|
12
|
+
export default function AutocompleteFieldBySchema({ fieldKey, index, name, schema, control, errors, optionIdKey, optionLabelKey, options: optionsByProps, isSemaphoric, sx, onValueChange, autoFocus, disabled, autoComplete: _, multiple, ...other }: FieldBySchemaProps): React.JSX.Element | undefined;
|
|
4
13
|
//# sourceMappingURL=AutocompleteFieldBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/AutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"AutocompleteFieldBySchema.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/inputs/AutocompleteFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAkB,MAAM,OAAO,CAAC;AAMvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AA8DrD;;;;;;;;GAQG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,EAChD,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,MAAM,EACN,OAAO,EACP,MAAM,EACN,WAAkB,EAClB,cAAwB,EACxB,OAAO,EAAE,cAAc,EACvB,YAAoB,EACpB,EAAc,EACd,aAAa,EACb,SAAS,EACT,QAAQ,EACR,YAAY,EAAE,CAAC,EACf,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,kBAAkB,iCA+DpB"}
|
|
@@ -88,8 +88,17 @@ const renderInput = (_a) => {
|
|
|
88
88
|
}
|
|
89
89
|
return (react_1.default.createElement(TextField_1.default, Object.assign({}, params, { label: label || fieldSchema.label, required: (0, utils_1.isFieldRequired)(fieldSchema), margin: "normal", error: error, helperText: helperText, sx: sx })));
|
|
90
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Choice/list picker built on MUI Autocomplete.
|
|
93
|
+
*
|
|
94
|
+
* `options` must be objects, and the current form `value` must match them: a
|
|
95
|
+
* single option object, or (when `multiple`) an array of option objects. The
|
|
96
|
+
* option shape is defined by `optionIdKey`/`optionLabelKey` (defaults
|
|
97
|
+
* `'id'`/`'label'`); it is NOT raw values/strings. Seed forms with
|
|
98
|
+
* populateValues() so values are already objects in the same format as options.
|
|
99
|
+
*/
|
|
91
100
|
function AutocompleteFieldBySchema(_a) {
|
|
92
|
-
var { fieldKey, index, name, schema, control, errors, optionIdKey = 'id', optionLabelKey = 'label', options: optionsByProps, isSemaphoric = false, sx = { mr: 2 }, onValueChange, autoFocus, disabled, autoComplete: _ } = _a, other = __rest(_a, ["fieldKey", "index", "name", "schema", "control", "errors", "optionIdKey", "optionLabelKey", "options", "isSemaphoric", "sx", "onValueChange", "autoFocus", "disabled", "autoComplete"]);
|
|
101
|
+
var { fieldKey, index, name, schema, control, errors, optionIdKey = 'id', optionLabelKey = 'label', options: optionsByProps, isSemaphoric = false, sx = { mr: 2 }, onValueChange, autoFocus, disabled, autoComplete: _, multiple } = _a, other = __rest(_a, ["fieldKey", "index", "name", "schema", "control", "errors", "optionIdKey", "optionLabelKey", "options", "isSemaphoric", "sx", "onValueChange", "autoFocus", "disabled", "autoComplete", "multiple"]);
|
|
93
102
|
const { theme } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
94
103
|
const fieldSchema = schema[name];
|
|
95
104
|
const options = (0, react_1.useMemo)(() => optionsByProps || fieldSchema.choices, [optionsByProps, fieldSchema]);
|
|
@@ -100,7 +109,7 @@ function AutocompleteFieldBySchema(_a) {
|
|
|
100
109
|
if (fieldKey && index && index >= 0) {
|
|
101
110
|
name = `${fieldKey}.${index}.${name}`;
|
|
102
111
|
}
|
|
103
|
-
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({}, field, { key: name, id: name, options: options || [], disabled: fieldSchema.disabled === true || disabled === true, selectOnFocus: true, autoHighlight: true, autoFocus: autoFocus, isOptionEqualToValue: (option, value) => {
|
|
112
|
+
return (react_1.default.createElement(react_hook_form_1.Controller, { name: name, control: control, render: ({ field }) => (react_1.default.createElement(Autocomplete_1.default, Object.assign({}, field, { key: name, id: name, options: options || [], disabled: fieldSchema.disabled === true || disabled === true, selectOnFocus: true, autoHighlight: true, autoFocus: autoFocus, multiple: multiple, isOptionEqualToValue: (option, value) => {
|
|
104
113
|
return option[optionIdKey] === value[optionIdKey];
|
|
105
114
|
}, getOptionLabel: (option) => {
|
|
106
115
|
return option[optionLabelKey];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setAuthToken, hasJWT, clearJWT, AUTH_EXPIRED_EVENT } from './api';
|
|
2
|
-
import { emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, slugToCamelCase } from './utils';
|
|
2
|
+
import { emptyByType, getChoiceByValue, populateValues, enrichChoices, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, slugToCamelCase } from './utils';
|
|
3
3
|
import DRFReactBySchemaProvider from './context/DRFReactBySchemaProvider';
|
|
4
4
|
import { useAPIWrapper } from './context/APIWrapperContext';
|
|
5
5
|
import Form from './components/forms/Form';
|
|
@@ -30,6 +30,6 @@ export { getThemeTexts } from './styles/texts';
|
|
|
30
30
|
export type { DRFReactBySchemaTexts, GeometryTexts, FormTexts } from './styles/texts';
|
|
31
31
|
import DetailBySchema from './components/details/DetailBySchema';
|
|
32
32
|
import DetailFieldBySchema from './components/details/DetailFieldBySchema';
|
|
33
|
-
export { DRFReactBySchemaProvider, useAPIWrapper, Form, DialogFormBySchema, DataGridBySchemaEditable, GenericModelList, GenericRelatedModelList, DataTotals, DialogActions, FileTypeIcon, SelectEditInputCell, GridDateInput, GridDecimalInput, GridPatternInput, BooleanInputCell, FormWatcher, FormBySchema, FieldBySchema, TextFieldBySchema, BooleanFieldBySchema, DesktopDatePickerBySchema, DesktopDateTimePickerBySchema, EditableAutocompleteFieldBySchema, AutocompleteFieldBySchema, FloatFieldBySchema, DetailBySchema, DetailFieldBySchema, setAuthToken, emptyByType, getChoiceByValue, populateValues, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, clearJWT, hasJWT, slugToCamelCase, AUTH_EXPIRED_EVENT, };
|
|
33
|
+
export { DRFReactBySchemaProvider, useAPIWrapper, Form, DialogFormBySchema, DataGridBySchemaEditable, GenericModelList, GenericRelatedModelList, DataTotals, DialogActions, FileTypeIcon, SelectEditInputCell, GridDateInput, GridDecimalInput, GridPatternInput, BooleanInputCell, FormWatcher, FormBySchema, FieldBySchema, TextFieldBySchema, BooleanFieldBySchema, DesktopDatePickerBySchema, DesktopDateTimePickerBySchema, EditableAutocompleteFieldBySchema, AutocompleteFieldBySchema, FloatFieldBySchema, DetailBySchema, DetailFieldBySchema, setAuthToken, emptyByType, getChoiceByValue, populateValues, enrichChoices, buildGenericYupValidationSchema, errorProps, getFieldErrorsFromResponse, getTmpId, isTmpId, getPatternFormat, clearJWT, hasJWT, slugToCamelCase, AUTH_EXPIRED_EVENT, };
|
|
34
34
|
export * from './@types/index';
|
|
35
35
|
//# sourceMappingURL=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AClF,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,YAAY,EAAE,qBAAqB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGtF,OAAO,cAAc,MAAM,qCAAqC,CAAC;AACjE,OAAO,mBAAmB,MAAM,0CAA0C,CAAC;AAE3E,OAAO,EAEL,wBAAwB,EAGxB,aAAa,EAGb,IAAI,EACJ,kBAAkB,EAGlB,wBAAwB,EACxB,gBAAgB,EAChB,uBAAuB,EACvB,UAAU,EACV,aAAa,EAGb,YAAY,EAGZ,mBAAmB,EACnB,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAGhB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC7B,iCAAiC,EACjC,yBAAyB,EACzB,kBAAkB,EAGlB,cAAc,EACd,mBAAmB,EAGnB,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,+BAA+B,EAC/B,UAAU,EACV,0BAA0B,EAC1B,QAAQ,EACR,OAAO,EACP,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,eAAe,EACf,kBAAkB,GACnB,CAAC;AAEF,cAAc,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ 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.AUTH_EXPIRED_EVENT = exports.slugToCamelCase = exports.hasJWT = exports.clearJWT = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.getFieldErrorsFromResponse = exports.errorProps = exports.buildGenericYupValidationSchema = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.setAuthToken = exports.DetailFieldBySchema = exports.DetailBySchema = exports.FloatFieldBySchema = exports.AutocompleteFieldBySchema = exports.EditableAutocompleteFieldBySchema = exports.DesktopDateTimePickerBySchema = exports.DesktopDatePickerBySchema = exports.BooleanFieldBySchema = exports.TextFieldBySchema = exports.FieldBySchema = exports.FormBySchema = exports.FormWatcher = exports.BooleanInputCell = exports.GridPatternInput = exports.GridDecimalInput = exports.GridDateInput = exports.SelectEditInputCell = exports.FileTypeIcon = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.DialogFormBySchema = exports.Form = exports.useAPIWrapper = exports.DRFReactBySchemaProvider = exports.getThemeTexts = exports.applyDefaultLeafletIcon = void 0;
|
|
20
|
+
exports.AUTH_EXPIRED_EVENT = exports.slugToCamelCase = exports.hasJWT = exports.clearJWT = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.getFieldErrorsFromResponse = exports.errorProps = exports.buildGenericYupValidationSchema = exports.enrichChoices = exports.populateValues = exports.getChoiceByValue = exports.emptyByType = exports.setAuthToken = exports.DetailFieldBySchema = exports.DetailBySchema = exports.FloatFieldBySchema = exports.AutocompleteFieldBySchema = exports.EditableAutocompleteFieldBySchema = exports.DesktopDateTimePickerBySchema = exports.DesktopDatePickerBySchema = exports.BooleanFieldBySchema = exports.TextFieldBySchema = exports.FieldBySchema = exports.FormBySchema = exports.FormWatcher = exports.BooleanInputCell = exports.GridPatternInput = exports.GridDecimalInput = exports.GridDateInput = exports.SelectEditInputCell = exports.FileTypeIcon = exports.DialogActions = exports.DataTotals = exports.GenericRelatedModelList = exports.GenericModelList = exports.DataGridBySchemaEditable = exports.DialogFormBySchema = exports.Form = exports.useAPIWrapper = exports.DRFReactBySchemaProvider = exports.getThemeTexts = exports.applyDefaultLeafletIcon = void 0;
|
|
21
21
|
// Methods:
|
|
22
22
|
const api_1 = require("./api");
|
|
23
23
|
Object.defineProperty(exports, "setAuthToken", { enumerable: true, get: function () { return api_1.setAuthToken; } });
|
|
@@ -28,6 +28,7 @@ const utils_1 = require("./utils");
|
|
|
28
28
|
Object.defineProperty(exports, "emptyByType", { enumerable: true, get: function () { return utils_1.emptyByType; } });
|
|
29
29
|
Object.defineProperty(exports, "getChoiceByValue", { enumerable: true, get: function () { return utils_1.getChoiceByValue; } });
|
|
30
30
|
Object.defineProperty(exports, "populateValues", { enumerable: true, get: function () { return utils_1.populateValues; } });
|
|
31
|
+
Object.defineProperty(exports, "enrichChoices", { enumerable: true, get: function () { return utils_1.enrichChoices; } });
|
|
31
32
|
Object.defineProperty(exports, "buildGenericYupValidationSchema", { enumerable: true, get: function () { return utils_1.buildGenericYupValidationSchema; } });
|
|
32
33
|
Object.defineProperty(exports, "errorProps", { enumerable: true, get: function () { return utils_1.errorProps; } });
|
|
33
34
|
Object.defineProperty(exports, "getFieldErrorsFromResponse", { enumerable: true, get: function () { return utils_1.getFieldErrorsFromResponse; } });
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import * as geojson from 'geojson';
|
|
|
4
4
|
import { ChoiceItem, ChoiceValue, ConditionalVisible, CustomFormField, ExtraValidators, Field, FormFieldLayout, GenericValue, GeometryFieldType, GridEnrichedBySchemaColDef, Item, SchemaType, TField } from '../@types';
|
|
5
5
|
export declare const emptyByType: GenericValue;
|
|
6
6
|
export declare const getChoiceByValue: (value: ChoiceValue, choices: ChoiceItem[] | undefined) => string | null | undefined;
|
|
7
|
+
export declare const toChoiceItem: (rawValue: GenericValue, choices: ChoiceItem[] | undefined) => any;
|
|
8
|
+
export declare function enrichChoices<T extends TField = void>(rawData: Item, schema: SchemaType<T>): Item<T>;
|
|
7
9
|
export declare function populateValues({ data, schema }: {
|
|
8
10
|
data: Item;
|
|
9
11
|
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,eA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GAAI,MAAM,IAAI,KAAG,QAkB9C,CAAC;AAEF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,UAgB3C;AAED,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,eAAe,EAAE,YAwBxE;AAED,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,OAAO,WAetE;AAED,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,YAAY,OAsB3D;AAED,wBAAgB,+BAA+B,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EACrE,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,wBAgC9B;AAED,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GAAG,eAAe,EAC/B,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,EACzC,MAAM,CAAC,EAAE,YAAY,EAAE,WA+BxB;AAED,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EACpE,KAAK,EAAE,MAAM,GAAG,eAAe,EAC/B,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,EACzC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,WAwBjB;AAOD;;;;GAIG;AAEH,wBAAgB,eAAe,IAAI,GAAG,CAerC;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,8 @@ 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.getChoiceByValue = exports.emptyByType = void 0;
|
|
48
|
+
exports.convertToFormData = exports.slugify = exports.slugToCamelCase = exports.getPatternFormat = exports.isTmpId = exports.getTmpId = exports.errorProps = exports.toChoiceItem = exports.getChoiceByValue = exports.emptyByType = void 0;
|
|
49
|
+
exports.enrichChoices = enrichChoices;
|
|
49
50
|
exports.populateValues = populateValues;
|
|
50
51
|
exports.buildGenericYupValidationSchema = buildGenericYupValidationSchema;
|
|
51
52
|
exports.loadSinglePageDataHelper = loadSinglePageDataHelper;
|
|
@@ -110,6 +111,38 @@ const getChoiceByValue = (value, choices) => {
|
|
|
110
111
|
}
|
|
111
112
|
};
|
|
112
113
|
exports.getChoiceByValue = getChoiceByValue;
|
|
114
|
+
// Shapes a raw choice value into a {value, display_name} object; objects that are
|
|
115
|
+
// already enriched pass through unchanged.
|
|
116
|
+
const toChoiceItem = (rawValue, choices) => typeof rawValue === 'object' && rawValue !== null
|
|
117
|
+
? rawValue
|
|
118
|
+
: {
|
|
119
|
+
value: rawValue,
|
|
120
|
+
display_name: (0, exports.getChoiceByValue)(rawValue, choices),
|
|
121
|
+
};
|
|
122
|
+
exports.toChoiceItem = toChoiceItem;
|
|
123
|
+
// Backends return choice fields as raw values. Reshape a single 'choice' into a
|
|
124
|
+
// {value, display_name} object and a 'list'/'multiple choice' into an array of
|
|
125
|
+
// them, so forms and grid rows are consistent. list options live under
|
|
126
|
+
// field.child?.choices (FieldBySchema reads the same source).
|
|
127
|
+
function enrichChoices(rawData, schema) {
|
|
128
|
+
const out = Object.assign({}, rawData);
|
|
129
|
+
for (const [key, field] of Object.entries(schema)) {
|
|
130
|
+
if (!(key in rawData)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === 'choice') {
|
|
134
|
+
const rawValue = rawData[key];
|
|
135
|
+
out[key] = rawValue ? (0, exports.toChoiceItem)(rawValue, field.choices) : (0, exports.emptyByType)(field);
|
|
136
|
+
}
|
|
137
|
+
else if ((field === null || field === void 0 ? void 0 : field.type) === 'list' || (field === null || field === void 0 ? void 0 : field.type) === 'multiple choice') {
|
|
138
|
+
const rawValue = rawData[key];
|
|
139
|
+
if (Array.isArray(rawValue)) {
|
|
140
|
+
out[key] = rawValue.map((entry) => { var _a; return (0, exports.toChoiceItem)(entry, (_a = field.child) === null || _a === void 0 ? void 0 : _a.choices); });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
113
146
|
function populateValues({ data, schema }) {
|
|
114
147
|
var _a;
|
|
115
148
|
const values = {};
|
|
@@ -141,11 +174,12 @@ function populateValues({ data, schema }) {
|
|
|
141
174
|
continue;
|
|
142
175
|
}
|
|
143
176
|
if (field.type === 'choice') {
|
|
144
|
-
values[key] = data[key]
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
values[key] = data[key] ? (0, exports.toChoiceItem)(data[key], field.choices) : (0, exports.emptyByType)(field);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
if (field.type === 'list' || field.type === 'multiple choice') {
|
|
181
|
+
values[key] = Array.isArray(data[key])
|
|
182
|
+
? data[key].map((entry) => { var _a; return (0, exports.toChoiceItem)(entry, (_a = field.child) === null || _a === void 0 ? void 0 : _a.choices); })
|
|
149
183
|
: (0, exports.emptyByType)(field);
|
|
150
184
|
continue;
|
|
151
185
|
}
|
package/package.json
CHANGED