diff --git a/packages/core/src/util/label.ts b/packages/core/src/util/label.ts
index 64cd4ef2c..80e9fd8ef 100644
--- a/packages/core/src/util/label.ts
+++ b/packages/core/src/util/label.ts
@@ -132,7 +132,12 @@ export const computeChildLabel = (
return '';
}
- const currentValue = get(childData, childLabelProp, '');
+ const currentValue = get(childData, childLabelProp);
+
+ // in case there is no value, then we can't map it to an enum or oneOf
+ if (currentValue === undefined) {
+ return '';
+ }
// check whether the value is part of a oneOf or enum and needs to be translated
const childSchema = Resolve.schema(
diff --git a/packages/core/src/util/renderer.ts b/packages/core/src/util/renderer.ts
index 004e75a8a..33346064a 100644
--- a/packages/core/src/util/renderer.ts
+++ b/packages/core/src/util/renderer.ts
@@ -31,7 +31,6 @@ import {
LabelElement,
UISchemaElement,
} from '../models';
-import find from 'lodash/find';
import {
getUISchemas,
getAjv,
@@ -53,7 +52,7 @@ import type {
} from '../reducers';
import type { RankedTester } from '../testers';
import { hasShowRule, isInherentlyEnabled, isVisible } from './runtime';
-import { createLabelDescriptionFrom } from './label';
+import { computeChildLabel, createLabelDescriptionFrom } from './label';
import type { CombinatorKeyword } from './combinators';
import { moveDown, moveUp } from './array';
import type { AnyAction, Dispatch } from './type';
@@ -689,20 +688,17 @@ export const mapStateToMasterListItemProps = (
state: JsonFormsState,
ownProps: OwnPropsOfMasterListItem
): StatePropsOfMasterItem => {
- const { schema, path, index } = ownProps;
- const firstPrimitiveProp = schema.properties
- ? find(Object.keys(schema.properties), (propName) => {
- const prop = schema.properties[propName];
- return (
- prop.type === 'string' ||
- prop.type === 'number' ||
- prop.type === 'integer'
- );
- })
- : undefined;
+ const { schema, path, uischema, childLabelProp, index } = ownProps;
const childPath = composePaths(path, `${index}`);
- const childData = Resolve.data(getData(state), childPath);
- const childLabel = firstPrimitiveProp ? childData[firstPrimitiveProp] : '';
+ const childLabel = computeChildLabel(
+ getData(state),
+ childPath,
+ childLabelProp,
+ schema,
+ getSchema(state),
+ state.jsonforms.i18n.translate,
+ uischema
+ );
return {
...ownProps,
@@ -725,6 +721,8 @@ export interface OwnPropsOfMasterListItem {
path: string;
enabled: boolean;
schema: JsonSchema;
+ uischema: UISchemaElement;
+ childLabelProp?: string;
handleSelect(index: number): () => void;
removeItem(path: string, value: number): () => void;
translations: ArrayTranslations;
diff --git a/packages/material-renderers/src/additional/ListWithDetailMasterItem.tsx b/packages/material-renderers/src/additional/ListWithDetailMasterItem.tsx
index 23b46689b..40458f16d 100644
--- a/packages/material-renderers/src/additional/ListWithDetailMasterItem.tsx
+++ b/packages/material-renderers/src/additional/ListWithDetailMasterItem.tsx
@@ -31,6 +31,7 @@ import {
ListItemAvatar,
ListItemSecondaryAction,
ListItemText,
+ Tooltip,
} from '@mui/material';
import { Delete as DeleteIcon } from '@mui/icons-material';
import React from 'react';
@@ -53,13 +54,19 @@ export const ListWithDetailMasterItem = ({
No data
+{translations.noDataMessage}
)} diff --git a/packages/material-renderers/test/renderers/MaterialListWithDetailRenderer.test.tsx b/packages/material-renderers/test/renderers/MaterialListWithDetailRenderer.test.tsx index f55dad99d..ca57afe32 100644 --- a/packages/material-renderers/test/renderers/MaterialListWithDetailRenderer.test.tsx +++ b/packages/material-renderers/test/renderers/MaterialListWithDetailRenderer.test.tsx @@ -23,18 +23,25 @@ THE SOFTWARE. */ import './MatchMediaMock'; -import { ControlElement, JsonSchema7 } from '@jsonforms/core'; +import { + ArrayTranslationEnum, + ControlElement, + JsonSchema7, + Scoped, + UISchemaElement, +} from '@jsonforms/core'; import * as React from 'react'; -import { materialRenderers } from '../../src'; +import { ArrayLayoutToolbar, materialRenderers } from '../../src'; import MaterialListWithDetailRenderer, { materialListWithDetailTester, } from '../../src/additional/MaterialListWithDetailRenderer'; import Enzyme, { mount, ReactWrapper } from 'enzyme'; import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; import { JsonFormsStateProvider } from '@jsonforms/react'; -import { ListItem } from '@mui/material'; -import { initCore } from './util'; +import { ListItem, Typography } from '@mui/material'; +import { initCore, testTranslator } from './util'; +import { checkTooltip, checkTooltipTranslation } from './tooltipChecker'; Enzyme.configure({ adapter: new Adapter() }); @@ -47,6 +54,23 @@ const data = [ message: 'Yolo', }, ]; + +const emptyData: any[] = []; + +const enumOrOneOfData = [ + { + message: 'El Barto was here', + messageType: 'MSG_TYPE_1', + }, + { + message: 'El Barto was not here', + messageType: 'MSG_TYPE_2', + }, + { + message: 'Yolo', + }, +]; + const schema: JsonSchema7 = { type: 'array', items: { @@ -69,6 +93,24 @@ const uischema: ControlElement = { scope: '#', }; +const uischemaListWithDetail: UISchemaElement & Scoped = { + type: 'ListWithDetail', + scope: '#', +}; + +const enumSchema: JsonSchema7 = { + type: 'array', + items: { + type: 'object', + properties: { + messageType: { + type: 'string', + enum: ['MSG_TYPE_1', 'MSG_TYPE_2'], + }, + }, + }, +}; + const nestedSchema: JsonSchema7 = { type: 'array', items: { @@ -346,4 +388,131 @@ describe('Material list with detail renderer', () => { const lis = wrapper.find(ListItem); expect(lis).toHaveLength(1); }); + + it('should render first simple property', () => { + const core = initCore(schema, uischema, data); + wrapper = mount( +