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
|
@@ -60,57 +60,171 @@ const AccordionDetails_1 = __importDefault(require("@mui/material/AccordionDetai
|
|
|
60
60
|
const ExpandMore_1 = __importDefault(require("@mui/icons-material/ExpandMore"));
|
|
61
61
|
const styles_1 = require("../../styles");
|
|
62
62
|
const utils_1 = require("../../utils");
|
|
63
|
+
const detailPaths_1 = require("./detailPaths");
|
|
63
64
|
const DetailFieldBySchema_1 = __importDefault(require("./DetailFieldBySchema"));
|
|
64
65
|
const APIWrapperContext_1 = require("../../context/APIWrapperContext");
|
|
65
|
-
|
|
66
|
+
/** Every string path referenced by a detail layout (dotted paths included). */
|
|
67
|
+
function getLayoutPaths(fieldsLayout) {
|
|
68
|
+
const paths = [];
|
|
69
|
+
for (const section of fieldsLayout || []) {
|
|
70
|
+
for (const row of section.rows || []) {
|
|
71
|
+
if (typeof row === 'string') {
|
|
72
|
+
paths.push(row);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(row)) {
|
|
76
|
+
for (const field of row) {
|
|
77
|
+
if (typeof field === 'string') {
|
|
78
|
+
paths.push(field);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return paths;
|
|
85
|
+
}
|
|
86
|
+
/** A section is empty only when it has rows and all of them are empty. */
|
|
87
|
+
function sectionHasContent(section, values) {
|
|
88
|
+
if (section.CustomElement || !section.rows || section.rows.length === 0) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
for (const row of section.rows) {
|
|
92
|
+
if (typeof row === 'string') {
|
|
93
|
+
if (!(0, detailPaths_1.isEmptyDetailValue)((0, detailPaths_1.getValueByPath)(values, row))) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(row)) {
|
|
99
|
+
for (const field of row) {
|
|
100
|
+
if (typeof field === 'string') {
|
|
101
|
+
if (!(0, detailPaths_1.isEmptyDetailValue)((0, detailPaths_1.getValueByPath)(values, field))) {
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
// A custom element without its own field always counts as content.
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function getFieldProps(fieldsProps, path) {
|
|
117
|
+
if (fieldsProps && path in fieldsProps && fieldsProps[path]) {
|
|
118
|
+
return fieldsProps[path];
|
|
119
|
+
}
|
|
120
|
+
return {};
|
|
121
|
+
}
|
|
122
|
+
function SectionContent({ sectionRows, item, values, schema, fieldsProps, SectionCustomElement, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
123
|
+
const resolveFormatted = (path) => {
|
|
124
|
+
const existing = item[path];
|
|
125
|
+
if (existing) {
|
|
126
|
+
return existing;
|
|
127
|
+
}
|
|
128
|
+
// Keeps the previous behavior for fields missing from `columns`: `-`.
|
|
129
|
+
return undefined;
|
|
130
|
+
};
|
|
66
131
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
67
132
|
SectionCustomElement && react_1.default.createElement(react_1.default.Fragment, null, SectionCustomElement),
|
|
68
133
|
sectionRows && (react_1.default.createElement(react_1.default.Fragment, null, sectionRows.map((row, rowIdx) => {
|
|
69
134
|
if (typeof row === 'string') {
|
|
70
135
|
const field = row;
|
|
71
|
-
const fieldProps = fieldsProps
|
|
72
|
-
|
|
73
|
-
|
|
136
|
+
const fieldProps = getFieldProps(fieldsProps, field);
|
|
137
|
+
if (fieldProps.hideIfEmpty && (0, detailPaths_1.isEmptyDetailValue)((0, detailPaths_1.getValueByPath)(values, field))) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
74
140
|
return (react_1.default.createElement(Box_1.default, { key: field, sx: sxRow },
|
|
75
|
-
react_1.default.createElement(DetailFieldBySchema_1.default, Object.assign({ fieldKey: field, fieldSchema:
|
|
141
|
+
react_1.default.createElement(DetailFieldBySchema_1.default, Object.assign({ fieldKey: field, fieldSchema: (0, detailPaths_1.getFieldSchemaByPath)(schema, field), value: resolveFormatted(field), item: values, sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps))));
|
|
76
142
|
}
|
|
77
143
|
if (Array.isArray(row)) {
|
|
78
144
|
return (react_1.default.createElement(Box_1.default, { key: `row_${rowIdx}`, sx: sxRowMultiple }, row.map((field, fieldIdx) => {
|
|
79
145
|
const key = typeof field === 'string' ? field : field.key;
|
|
80
|
-
const fieldProps = fieldsProps
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
146
|
+
const fieldProps = getFieldProps(fieldsProps, key);
|
|
147
|
+
if (fieldProps.hideIfEmpty && (0, detailPaths_1.isEmptyDetailValue)((0, detailPaths_1.getValueByPath)(values, key))) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return (react_1.default.createElement(react_1.default.Fragment, { key: `field_${rowIdx}_${fieldIdx}` }, typeof field === 'string' ? (react_1.default.createElement(DetailFieldBySchema_1.default, Object.assign({ fieldKey: field, fieldSchema: (0, detailPaths_1.getFieldSchemaByPath)(schema, field), value: resolveFormatted(field), item: values, sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps))) : (react_1.default.createElement(field.CustomElement, Object.assign({ value: (0, detailPaths_1.getValueByPath)(values, key), item: values, fieldSchema: (0, detailPaths_1.getFieldSchemaByPath)(schema, key), sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps)))));
|
|
84
151
|
})));
|
|
85
152
|
}
|
|
86
|
-
const fieldProps = fieldsProps
|
|
87
|
-
return (react_1.default.createElement(row.CustomElement, Object.assign({ key: `field_customElement_row_${rowIdx}`, sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps)));
|
|
153
|
+
const fieldProps = getFieldProps(fieldsProps, row.key);
|
|
154
|
+
return (react_1.default.createElement(row.CustomElement, Object.assign({ key: `field_customElement_row_${rowIdx}`, value: (0, detailPaths_1.getValueByPath)(values, row.key), item: values, fieldSchema: (0, detailPaths_1.getFieldSchemaByPath)(schema, row.key), sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }, fieldProps)));
|
|
88
155
|
})))));
|
|
89
156
|
}
|
|
90
157
|
function DetailBySchema({ values, schema, columns, loading, editLink, editLabel, fieldsLayout: fieldsLayoutInitial, hiddenFields = ['id'], fieldsProps, elevation = 2, sxSection, sxSectionTitle, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
91
158
|
const { isMobile } = (0, APIWrapperContext_1.useAPIWrapper)();
|
|
92
159
|
const [preparedColumns, setPreparedColumns] = (0, react_1.useState)(null);
|
|
160
|
+
const layoutPaths = (0, react_1.useMemo)(() => getLayoutPaths(fieldsLayoutInitial), [fieldsLayoutInitial]);
|
|
161
|
+
// Dotted paths (`contratacao.valor`) need a synthetic column/schema entry so
|
|
162
|
+
// the shared formatters from `initViewColumns` still apply.
|
|
163
|
+
const { finalColumns, schemaWithPaths } = (0, react_1.useMemo)(() => {
|
|
164
|
+
const existing = new Set((columns || []).map((column) => String(column.field)));
|
|
165
|
+
const extraColumns = [];
|
|
166
|
+
for (const path of layoutPaths) {
|
|
167
|
+
if (!path.includes('.') || existing.has(path)) {
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const fieldSchema = (0, detailPaths_1.getFieldSchemaByPath)(schema, path);
|
|
171
|
+
if (!fieldSchema) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
existing.add(path);
|
|
175
|
+
extraColumns.push({
|
|
176
|
+
field: path,
|
|
177
|
+
headerName: fieldSchema.label,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
const allColumns = [...(columns || []), ...extraColumns];
|
|
181
|
+
const extendedSchema = Object.assign({}, schema);
|
|
182
|
+
for (const column of allColumns) {
|
|
183
|
+
const path = String(column.field);
|
|
184
|
+
if (!path.includes('.') || extendedSchema[path]) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const fieldSchema = (0, detailPaths_1.getFieldSchemaByPath)(schema, path);
|
|
188
|
+
if (fieldSchema) {
|
|
189
|
+
extendedSchema[path] = fieldSchema;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return {
|
|
193
|
+
finalColumns: allColumns,
|
|
194
|
+
schemaWithPaths: extendedSchema,
|
|
195
|
+
};
|
|
196
|
+
}, [columns, layoutPaths, schema]);
|
|
93
197
|
const formattedValues = (0, react_1.useMemo)(() => {
|
|
94
198
|
if (!preparedColumns || !values) {
|
|
95
199
|
return;
|
|
96
200
|
}
|
|
97
201
|
const newFormattedValues = {};
|
|
98
202
|
for (const column of preparedColumns) {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
203
|
+
const path = String(column.field);
|
|
204
|
+
const fieldSchema = (0, detailPaths_1.getFieldSchemaByPath)(schema, path);
|
|
205
|
+
if (!path.includes('.')) {
|
|
206
|
+
// Preserve the historical behavior for plain fields missing from the payload.
|
|
207
|
+
if (!(path in values)) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else if (!fieldSchema) {
|
|
212
|
+
continue;
|
|
110
213
|
}
|
|
214
|
+
const rawValue = (0, detailPaths_1.getValueByPath)(values, path);
|
|
215
|
+
const valueStr = !rawValue && typeof rawValue !== 'boolean'
|
|
216
|
+
? '-'
|
|
217
|
+
: column.valueFormatter
|
|
218
|
+
? column.valueFormatter(rawValue, values, column, undefined)
|
|
219
|
+
: rawValue;
|
|
220
|
+
newFormattedValues[path] = {
|
|
221
|
+
title: column.headerName || '',
|
|
222
|
+
valueStr,
|
|
223
|
+
value: rawValue,
|
|
224
|
+
};
|
|
111
225
|
}
|
|
112
226
|
return newFormattedValues;
|
|
113
|
-
}, [preparedColumns, values]);
|
|
227
|
+
}, [preparedColumns, values, schema]);
|
|
114
228
|
const fieldsLayout = (0, react_1.useMemo)(() => {
|
|
115
229
|
if (!isMobile && fieldsLayoutInitial && fieldsLayoutInitial.length > 0) {
|
|
116
230
|
return fieldsLayoutInitial;
|
|
@@ -145,25 +259,34 @@ function DetailBySchema({ values, schema, columns, loading, editLink, editLabel,
|
|
|
145
259
|
}
|
|
146
260
|
}
|
|
147
261
|
return [{ rows }];
|
|
148
|
-
}, [fieldsLayoutInitial, schema, hiddenFields]);
|
|
262
|
+
}, [fieldsLayoutInitial, schema, hiddenFields, isMobile]);
|
|
263
|
+
const visibleFieldsLayout = (0, react_1.useMemo)(() => fieldsLayout.filter((section) => {
|
|
264
|
+
if (section.hidden && section.hidden(values)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (section.hideIfEmpty && !sectionHasContent(section, values)) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return true;
|
|
271
|
+
}), [fieldsLayout, values]);
|
|
149
272
|
(0, react_1.useEffect)(() => {
|
|
150
273
|
const initColumns = () => __awaiter(this, void 0, void 0, function* () {
|
|
151
274
|
const preparedColumns = yield (0, utils_1.initViewColumns)({
|
|
152
|
-
columns:
|
|
153
|
-
schema:
|
|
275
|
+
columns: finalColumns,
|
|
276
|
+
schema: schemaWithPaths,
|
|
154
277
|
});
|
|
155
278
|
setPreparedColumns(preparedColumns);
|
|
156
279
|
});
|
|
157
280
|
initColumns();
|
|
158
|
-
}, [
|
|
281
|
+
}, [finalColumns, schemaWithPaths]);
|
|
159
282
|
if (!fieldsLayout || loading || !formattedValues) {
|
|
160
283
|
return (react_1.default.createElement(Card_1.default, { sx: styles_1.Layout.formCard },
|
|
161
284
|
react_1.default.createElement(CardContent_1.default, null,
|
|
162
285
|
react_1.default.createElement(Box_1.default, { sx: styles_1.Layout.loadingBoxWhite },
|
|
163
286
|
react_1.default.createElement(CircularProgress_1.default, null)))));
|
|
164
287
|
}
|
|
165
|
-
const SectionContentComponent = ({ section }) => (react_1.default.createElement(SectionContent, { sectionRows: section.rows, item: formattedValues, schema: schema, fieldsProps: fieldsProps, SectionCustomElement: section.CustomElement, sxRow: section.sxRow || sxRow, sxRowMultiple: section.sxRowMultiple || sxRowMultiple, sxField: section.sxField || sxField, sxLabel: section.sxLabel || sxLabel, sxValue: section.sxValue || sxValue, sxValueList: section.sxValueList || sxValueList, sxValueListItem: section.sxValueListItem || sxValueListItem, sxValueListItemText: section.sxValueListItemText || sxValueListItemText }));
|
|
166
|
-
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
288
|
+
const SectionContentComponent = ({ section }) => (react_1.default.createElement(SectionContent, { sectionRows: section.rows, item: formattedValues, values: values, schema: schema, fieldsProps: fieldsProps, SectionCustomElement: section.CustomElement, sxRow: section.sxRow || sxRow, sxRowMultiple: section.sxRowMultiple || sxRowMultiple, sxField: section.sxField || sxField, sxLabel: section.sxLabel || sxLabel, sxValue: section.sxValue || sxValue, sxValueList: section.sxValueList || sxValueList, sxValueListItem: section.sxValueListItem || sxValueListItem, sxValueListItemText: section.sxValueListItemText || sxValueListItemText }));
|
|
289
|
+
return (react_1.default.createElement(react_1.default.Fragment, null, visibleFieldsLayout.map((section, sectionIndex) => {
|
|
167
290
|
return (react_1.default.createElement(Card_1.default, { sx: sxSection || styles_1.Layout.formCard, elevation: elevation, key: `section_${sectionIndex}` },
|
|
168
291
|
section.title && !section.isAccordion && (react_1.default.createElement(CardHeader_1.default, { title: section.title, sx: section.sxSectionTitle || sxSectionTitle, action: sectionIndex === 0 && editLink ? (react_1.default.createElement(Stack_1.default, { direction: "row", justifyContent: "flex-end" },
|
|
169
292
|
react_1.default.createElement(Button_1.default, { href: editLink, variant: "contained" }, editLabel))) : (react_1.default.createElement(react_1.default.Fragment, null)) })),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DetailFieldBySchemaProps } from '../../@types';
|
|
3
|
-
export default function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailFieldBySchemaProps): React.JSX.Element | null;
|
|
2
|
+
import { DetailFieldBySchemaProps, TField } from '../../@types';
|
|
3
|
+
export default function DetailFieldBySchema<T extends TField = void>({ fieldKey, fieldSchema, value, item, valueFormatter, renderValue, emptyValue, hideIfEmpty, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailFieldBySchemaProps<T>): React.JSX.Element | null;
|
|
4
4
|
//# sourceMappingURL=DetailFieldBySchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DetailFieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/details/DetailFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"DetailFieldBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/details/DetailFieldBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAY1B,OAAO,EAAE,wBAAwB,EAAsB,MAAM,EAAE,MAAM,cAAc,CAAC;AAUpF,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EACnE,QAAQ,EACR,WAAW,EACX,KAAK,EACL,IAAI,EACJ,cAAc,EACd,WAAW,EACX,UAAU,EACV,WAAW,EACX,OAAO,EACP,OAAO,EACP,OAAO,EACP,WAAW,EACX,eAAe,EACf,mBAAmB,GACpB,EAAE,wBAAwB,CAAC,CAAC,CAAC,4BA+N7B"}
|
|
@@ -19,19 +19,42 @@ const Image_1 = __importDefault(require("../Image"));
|
|
|
19
19
|
const FileTypeIcon_1 = __importDefault(require("../FileTypeIcon"));
|
|
20
20
|
const HtmlContent_1 = __importDefault(require("../HtmlContent"));
|
|
21
21
|
const GeoThumbCell_1 = __importDefault(require("../DataGridBySchemaEditable/GeoThumbCell"));
|
|
22
|
-
|
|
22
|
+
const detailPaths_1 = require("./detailPaths");
|
|
23
|
+
function DetailFieldBySchema({ fieldKey, fieldSchema, value, item, valueFormatter, renderValue, emptyValue, hideIfEmpty, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
23
24
|
const { serverEndPoint } = (0, DRFReactBySchemaContext_1.useDRFReactBySchema)();
|
|
24
25
|
if (!fieldSchema) {
|
|
25
26
|
console.error(`DetailFieldBySchema: could not find schema for field ${fieldKey}`);
|
|
26
27
|
return null;
|
|
27
28
|
}
|
|
28
29
|
if (!value) {
|
|
29
|
-
return react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
30
|
+
return react_1.default.createElement(Box_1.default, { sx: sxField }, emptyValue === undefined ? '-' : emptyValue);
|
|
30
31
|
}
|
|
32
|
+
const rawValue = value.value;
|
|
33
|
+
const isEmpty = (0, detailPaths_1.isEmptyDetailValue)(rawValue);
|
|
34
|
+
const resolvedItem = (item || {});
|
|
35
|
+
const label = value.title;
|
|
36
|
+
if (isEmpty && hideIfEmpty) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (isEmpty && emptyValue !== undefined) {
|
|
40
|
+
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
41
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
42
|
+
emptyValue));
|
|
43
|
+
}
|
|
44
|
+
if (renderValue) {
|
|
45
|
+
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
46
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
47
|
+
renderValue({ value: rawValue, item: resolvedItem, fieldSchema, label })));
|
|
48
|
+
}
|
|
49
|
+
const formatted = !isEmpty && valueFormatter
|
|
50
|
+
? valueFormatter(rawValue, resolvedItem, fieldSchema)
|
|
51
|
+
: value.valueStr;
|
|
52
|
+
const valueStr = typeof formatted === 'string' ? formatted : (formatted !== null && formatted !== void 0 ? formatted : '');
|
|
53
|
+
const valueStrParts = String(valueStr).split(', ');
|
|
31
54
|
if (fieldSchema.model_html) {
|
|
32
|
-
const html = typeof
|
|
55
|
+
const html = typeof rawValue === 'string' ? rawValue : valueStr;
|
|
33
56
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
34
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
57
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
35
58
|
react_1.default.createElement(HtmlContent_1.default, { html: html, sx: sxValue })));
|
|
36
59
|
}
|
|
37
60
|
const fieldType = fieldSchema.type;
|
|
@@ -41,55 +64,55 @@ function DetailFieldBySchema({ fieldKey, fieldSchema, value, sxField, sxLabel, s
|
|
|
41
64
|
const multiple = fieldSchema.many || false;
|
|
42
65
|
if (multiple) {
|
|
43
66
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
44
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
45
|
-
value.value.length > 0 ? (react_1.default.createElement(List_1.default, { sx: sxValueList },
|
|
67
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
68
|
+
value.value && value.value.length > 0 ? (react_1.default.createElement(List_1.default, { sx: sxValueList }, valueStrParts.map((singleValue, index) => (react_1.default.createElement(ListItem_1.default, { key: `${label}_${index}`, sx: sxValueListItem },
|
|
46
69
|
react_1.default.createElement(ListItemText_1.default, { sx: sxValueListItemText }, singleValue)))))) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, "-"))));
|
|
47
70
|
}
|
|
48
71
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
49
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
50
|
-
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
72
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
73
|
+
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, valueStr)));
|
|
51
74
|
case 'choice':
|
|
52
75
|
case 'list':
|
|
53
76
|
const multipleChoice = fieldType === 'list' || fieldSchema.many ? true : false;
|
|
54
77
|
if (multipleChoice) {
|
|
55
78
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
56
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
57
|
-
value.value.length > 0 ? (react_1.default.createElement(List_1.default, { sx: sxValueList },
|
|
79
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
80
|
+
value.value && value.value.length > 0 ? (react_1.default.createElement(List_1.default, { sx: sxValueList }, valueStrParts.map((singleValue, index) => (react_1.default.createElement(ListItem_1.default, { key: `${label}_${index}`, sx: sxValueListItem },
|
|
58
81
|
react_1.default.createElement(ListItemText_1.default, { sx: sxValueListItemText }, singleValue)))))) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, "-"))));
|
|
59
82
|
}
|
|
60
83
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
61
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
62
|
-
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
84
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
85
|
+
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, valueStr)));
|
|
63
86
|
case 'email':
|
|
64
87
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
65
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
88
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
66
89
|
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
67
|
-
react_1.default.createElement("a", { href: `mailto: ${
|
|
90
|
+
react_1.default.createElement("a", { href: `mailto: ${valueStr}` }, valueStr))));
|
|
68
91
|
case 'file upload':
|
|
69
92
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
70
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
71
|
-
|
|
72
|
-
react_1.default.createElement(FileTypeIcon_1.default, { name:
|
|
93
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
94
|
+
rawValue ? (react_1.default.createElement(Stack_1.default, { direction: "row", spacing: 1, alignItems: "center" },
|
|
95
|
+
react_1.default.createElement(FileTypeIcon_1.default, { name: rawValue.name }),
|
|
73
96
|
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
74
|
-
react_1.default.createElement(Button_1.default, { href: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${
|
|
97
|
+
react_1.default.createElement(Button_1.default, { href: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${rawValue.url}`, target: "_blank", variant: "outlined", startIcon: react_1.default.createElement(Download_1.default, null) }, valueStr)))) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, "-"))));
|
|
75
98
|
case 'image upload':
|
|
76
99
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
77
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
78
|
-
|
|
79
|
-
react_1.default.createElement(Image_1.default, { sx: styles_1.Layout.detailFieldImg, src: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${
|
|
100
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
101
|
+
rawValue ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
102
|
+
react_1.default.createElement(Image_1.default, { sx: styles_1.Layout.detailFieldImg, src: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${rawValue.url}`, alt: valueStr }),
|
|
80
103
|
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
81
|
-
react_1.default.createElement(Button_1.default, { href: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${
|
|
104
|
+
react_1.default.createElement(Button_1.default, { href: `${serverEndPoint === null || serverEndPoint === void 0 ? void 0 : serverEndPoint.url}${rawValue.url}`, target: "_blank", variant: "contained", startIcon: react_1.default.createElement(Download_1.default, null) }, valueStr)))) : (react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, "-"))));
|
|
82
105
|
case 'point':
|
|
83
106
|
case 'polygon':
|
|
84
107
|
case 'multipoint':
|
|
85
108
|
case 'multipolygon':
|
|
86
109
|
case 'geometrycollection':
|
|
87
110
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
88
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
89
|
-
react_1.default.createElement(GeoThumbCell_1.default, { geometry: fieldType, value:
|
|
111
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
112
|
+
react_1.default.createElement(GeoThumbCell_1.default, { geometry: fieldType, value: rawValue })));
|
|
90
113
|
default:
|
|
91
114
|
return (react_1.default.createElement(Box_1.default, { sx: sxField },
|
|
92
|
-
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel },
|
|
93
|
-
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue },
|
|
115
|
+
react_1.default.createElement(Typography_1.default, { variant: "h5", sx: sxLabel }, label),
|
|
116
|
+
react_1.default.createElement(Typography_1.default, { variant: "body2", sx: sxValue }, valueStr)));
|
|
94
117
|
}
|
|
95
118
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DetailPageProps, TField } from '../../@types';
|
|
3
|
+
/**
|
|
4
|
+
* Schema-driven detail page: header (back/title/edit), optional hero, tabs
|
|
5
|
+
* rendered from `sections` and/or `render` escape hatches. No router import.
|
|
6
|
+
*/
|
|
7
|
+
export default function DetailPage<T extends TField = void>({ model, objId, titleField, title: titleProp, backLink, backLabel, onBack, editLink, editLabel, hero, tabs, sections, fieldsLayout, hiddenFields, fieldsProps, elevation, renderHeader, renderShell, emptyLabel, errorLabel, retryLabel, sxSection, sxSectionTitle, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }: DetailPageProps<T>): React.JSX.Element;
|
|
8
|
+
//# sourceMappingURL=DetailPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DetailPage.d.ts","sourceRoot":"","sources":["../../../src/components/details/DetailPage.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAU5D,OAAO,EAAE,eAAe,EAAmC,MAAM,EAAE,MAAM,cAAc,CAAC;AAYxF;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAC1D,KAAK,EACL,KAAK,EACL,UAAU,EACV,KAAK,EAAE,SAAS,EAChB,QAAQ,EACR,SAAkB,EAClB,MAAM,EACN,QAAQ,EACR,SAAkB,EAClB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,SAAa,EACb,YAAY,EACZ,WAAW,EACX,UAA+B,EAC/B,UAAU,EACV,UAAoB,EACpB,SAAS,EACT,cAAc,EACd,KAAK,EACL,aAAa,EACb,OAAO,EACP,OAAO,EACP,OAAO,EACP,WAAW,EACX,eAAe,EACf,mBAAmB,GACpB,EAAE,eAAe,CAAC,CAAC,CAAC,qBAqKpB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.default = DetailPage;
|
|
40
|
+
const react_1 = __importStar(require("react"));
|
|
41
|
+
const Alert_1 = __importDefault(require("@mui/material/Alert"));
|
|
42
|
+
const Box_1 = __importDefault(require("@mui/material/Box"));
|
|
43
|
+
const Button_1 = __importDefault(require("@mui/material/Button"));
|
|
44
|
+
const CircularProgress_1 = __importDefault(require("@mui/material/CircularProgress"));
|
|
45
|
+
const Stack_1 = __importDefault(require("@mui/material/Stack"));
|
|
46
|
+
const Tab_1 = __importDefault(require("@mui/material/Tab"));
|
|
47
|
+
const Tabs_1 = __importDefault(require("@mui/material/Tabs"));
|
|
48
|
+
const Typography_1 = __importDefault(require("@mui/material/Typography"));
|
|
49
|
+
const DetailBySchema_1 = __importDefault(require("./DetailBySchema"));
|
|
50
|
+
const useDetailData_1 = require("../../hooks/useDetailData");
|
|
51
|
+
function tabLabel(tab, values) {
|
|
52
|
+
const count = tab.count ? tab.count(values) : undefined;
|
|
53
|
+
return count === undefined ? tab.label : `${tab.label} (${count})`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Schema-driven detail page: header (back/title/edit), optional hero, tabs
|
|
57
|
+
* rendered from `sections` and/or `render` escape hatches. No router import.
|
|
58
|
+
*/
|
|
59
|
+
function DetailPage({ model, objId, titleField, title: titleProp, backLink, backLabel = 'Back', onBack, editLink, editLabel = 'Edit', hero, tabs, sections, fieldsLayout, hiddenFields, fieldsProps, elevation = 0, renderHeader, renderShell, emptyLabel = 'No record found.', errorLabel, retryLabel = 'Retry', sxSection, sxSectionTitle, sxRow, sxRowMultiple, sxField, sxLabel, sxValue, sxValueList, sxValueListItem, sxValueListItemText, }) {
|
|
60
|
+
const { values, schema, columns, loading, error, reload } = (0, useDetailData_1.useDetailData)({
|
|
61
|
+
model,
|
|
62
|
+
objId,
|
|
63
|
+
titleField,
|
|
64
|
+
});
|
|
65
|
+
const [tabIndex, setTabIndex] = (0, react_1.useState)(0);
|
|
66
|
+
(0, react_1.useEffect)(() => {
|
|
67
|
+
setTabIndex(0);
|
|
68
|
+
}, [model, objId]);
|
|
69
|
+
const title = (0, react_1.useMemo)(() => {
|
|
70
|
+
if (titleProp) {
|
|
71
|
+
return titleProp;
|
|
72
|
+
}
|
|
73
|
+
if (titleField && values && values[titleField] != null) {
|
|
74
|
+
return String(values[titleField]);
|
|
75
|
+
}
|
|
76
|
+
return model;
|
|
77
|
+
}, [titleProp, titleField, values, model]);
|
|
78
|
+
const renderProps = {
|
|
79
|
+
values,
|
|
80
|
+
schema,
|
|
81
|
+
columns,
|
|
82
|
+
id: objId,
|
|
83
|
+
title,
|
|
84
|
+
};
|
|
85
|
+
const visibleTabs = (0, react_1.useMemo)(() => (tabs || []).filter((tab) => !(values && tab.hidden && tab.hidden(values))), [tabs, values]);
|
|
86
|
+
const activeTabIndex = visibleTabs.length > 0 ? Math.min(tabIndex, visibleTabs.length - 1) : 0;
|
|
87
|
+
let body;
|
|
88
|
+
if (loading) {
|
|
89
|
+
body = (react_1.default.createElement(Box_1.default, { sx: { display: 'flex', alignItems: 'center', justifyContent: 'center', minHeight: 160 } },
|
|
90
|
+
react_1.default.createElement(CircularProgress_1.default, null)));
|
|
91
|
+
}
|
|
92
|
+
else if (error) {
|
|
93
|
+
body = (react_1.default.createElement(Alert_1.default, { severity: "error", action: react_1.default.createElement(Button_1.default, { color: "inherit", size: "small", onClick: reload }, retryLabel) }, errorLabel || error.message || 'Could not load the record.'));
|
|
94
|
+
}
|
|
95
|
+
else if (!values || !schema) {
|
|
96
|
+
body = react_1.default.createElement(Alert_1.default, { severity: "info" }, emptyLabel);
|
|
97
|
+
}
|
|
98
|
+
else if (visibleTabs.length === 0) {
|
|
99
|
+
body = (react_1.default.createElement(DetailBySchema_1.default, { values: values, schema: schema, columns: columns, fieldsLayout: sections || fieldsLayout, hiddenFields: hiddenFields, fieldsProps: fieldsProps, elevation: elevation, sxSection: sxSection, sxSectionTitle: sxSectionTitle, sxRow: sxRow, sxRowMultiple: sxRowMultiple, sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText }));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const activeTab = visibleTabs[activeTabIndex];
|
|
103
|
+
body = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
104
|
+
react_1.default.createElement(Tabs_1.default, { value: activeTabIndex, onChange: (_event, value) => setTabIndex(value), variant: "scrollable", allowScrollButtonsMobile: true }, visibleTabs.map((tab) => (react_1.default.createElement(Tab_1.default, { key: tab.key, label: tabLabel(tab, values), icon: tab.icon })))),
|
|
105
|
+
react_1.default.createElement(Box_1.default, { sx: { mt: 2 } }, activeTab.sections ? (react_1.default.createElement(DetailBySchema_1.default, { values: values, schema: schema, columns: columns, fieldsLayout: activeTab.sections, hiddenFields: hiddenFields, fieldsProps: fieldsProps, elevation: elevation, sxSection: sxSection, sxSectionTitle: sxSectionTitle, sxRow: sxRow, sxRowMultiple: sxRowMultiple, sxField: sxField, sxLabel: sxLabel, sxValue: sxValue, sxValueList: sxValueList, sxValueListItem: sxValueListItem, sxValueListItemText: sxValueListItemText })) : activeTab.render ? (activeTab.render({
|
|
106
|
+
values,
|
|
107
|
+
schema,
|
|
108
|
+
columns,
|
|
109
|
+
id: objId,
|
|
110
|
+
label: activeTab.label,
|
|
111
|
+
})) : null)));
|
|
112
|
+
}
|
|
113
|
+
const header = renderHeader ? (react_1.default.createElement(react_1.default.Fragment, null, renderHeader(renderProps))) : (react_1.default.createElement(Stack_1.default, { direction: "row", alignItems: "center", spacing: 2, justifyContent: "space-between", sx: { mb: 2 } },
|
|
114
|
+
react_1.default.createElement(Stack_1.default, { direction: "row", alignItems: "center", spacing: 2 },
|
|
115
|
+
(onBack || backLink) && (react_1.default.createElement(Button_1.default, { variant: "outlined", onClick: onBack, href: onBack ? undefined : backLink }, backLabel)),
|
|
116
|
+
react_1.default.createElement(Typography_1.default, { variant: "h4" }, title)),
|
|
117
|
+
editLink && (react_1.default.createElement(Button_1.default, { variant: "contained", href: editLink }, editLabel))));
|
|
118
|
+
const content = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
119
|
+
header,
|
|
120
|
+
hero,
|
|
121
|
+
body));
|
|
122
|
+
return react_1.default.createElement(react_1.default.Fragment, null, renderShell ? renderShell(content, renderProps) : content);
|
|
123
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Field, GenericValue, Item, SchemaType } from '../../@types';
|
|
2
|
+
/** Reads a possibly dotted path (`contratacao.valor`) from a detail item. */
|
|
3
|
+
export declare function getValueByPath(item: Item | null | undefined, path: string): GenericValue;
|
|
4
|
+
/** Resolves the field metadata for a possibly dotted path. */
|
|
5
|
+
export declare function getFieldSchemaByPath(schema: SchemaType | null | undefined, path: string): Field | undefined;
|
|
6
|
+
/** Empty means "nothing to render" (`0` and `false` are values). */
|
|
7
|
+
export declare function isEmptyDetailValue(value: GenericValue): boolean;
|
|
8
|
+
//# sourceMappingURL=detailPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detailPaths.d.ts","sourceRoot":"","sources":["../../../src/components/details/detailPaths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAErE,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAaxF;AAED,8DAA8D;AAC9D,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACrC,IAAI,EAAE,MAAM,GACX,KAAK,GAAG,SAAS,CAcnB;AAED,oEAAoE;AACpE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAO/D"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValueByPath = getValueByPath;
|
|
4
|
+
exports.getFieldSchemaByPath = getFieldSchemaByPath;
|
|
5
|
+
exports.isEmptyDetailValue = isEmptyDetailValue;
|
|
6
|
+
/** Reads a possibly dotted path (`contratacao.valor`) from a detail item. */
|
|
7
|
+
function getValueByPath(item, path) {
|
|
8
|
+
if (!item) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
if (!path.includes('.')) {
|
|
12
|
+
return item[path];
|
|
13
|
+
}
|
|
14
|
+
return path
|
|
15
|
+
.split('.')
|
|
16
|
+
.reduce((acc, key) => (acc === null || acc === undefined ? undefined : acc[key]), item);
|
|
17
|
+
}
|
|
18
|
+
/** Resolves the field metadata for a possibly dotted path. */
|
|
19
|
+
function getFieldSchemaByPath(schema, path) {
|
|
20
|
+
var _a;
|
|
21
|
+
if (!schema) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (!path.includes('.')) {
|
|
25
|
+
return schema[path];
|
|
26
|
+
}
|
|
27
|
+
const segments = path.split('.');
|
|
28
|
+
let current = schema[segments[0]];
|
|
29
|
+
for (let index = 1; index < segments.length && current; index++) {
|
|
30
|
+
const children = current.children || ((_a = current.child) === null || _a === void 0 ? void 0 : _a.children);
|
|
31
|
+
current = children === null || children === void 0 ? void 0 : children[segments[index]];
|
|
32
|
+
}
|
|
33
|
+
return current;
|
|
34
|
+
}
|
|
35
|
+
/** Empty means "nothing to render" (`0` and `false` are values). */
|
|
36
|
+
function isEmptyDetailValue(value) {
|
|
37
|
+
return (value === null ||
|
|
38
|
+
value === undefined ||
|
|
39
|
+
value === '' ||
|
|
40
|
+
(Array.isArray(value) && value.length === 0));
|
|
41
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWjE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"FormBySchema.d.ts","sourceRoot":"","sources":["../../../src/components/forms/FormBySchema.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAiB,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWjE,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,sBAAsB,EACtB,uBAAuB,EACvB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,QAAQ,EAER,SAAS,EACT,MAAM,EACP,MAAM,cAAc,CAAC;AAatB,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,IAAI,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG;IAEtF,YAAY,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,sBAAsB,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACzC,uBAAuB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,GAAG,UAAU,CAAC,CAAC;IACtF,WAAW,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,CAAC;IAC1C,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,EAAE,EAC5D,MAAM,EACN,OAAO,EACP,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAgC,EAChC,KAAK,EACL,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EAAE,iBAAiB,EAC9B,OAAO,EACP,YAAY,EACZ,KAAK,EACL,YAAgB,EAEhB,YAAY,EAAE,mBAAmB,EACjC,sBAAsB,EACtB,kBAAkB,EAClB,aAAa,EAEb,WAAW,EACX,YAAY,EACZ,uBAAuB,EACvB,eAAe,EACf,cAAc,EACd,SAAS,EAKT,KAAK,EACL,aAAa,EACb,SAAS,EACT,cAAc,GAKf,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACrB,IAAI,CACF,uBAAuB,EACrB,IAAI,GACJ,SAAS,GACT,SAAS,GACT,SAAS,GACT,aAAa,GACb,iBAAiB,GACjB,qBAAqB,CACxB,qBAscF"}
|