Skip to content

Commit 1190bd3

Browse files
committed
Validation Icon on ExpandPanel and ListWithDetail
1 parent d0b1dfa commit 1190bd3

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

packages/core/src/mappers/renderer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,20 @@ export const mapStateToMasterListItemProps = (
791791
state.jsonforms.i18n.translate,
792792
uischema
793793
);
794+
const subErrors = getSubErrorsAt(childPath, schema)(state);
795+
const childErrors = getCombinedErrorMessage(
796+
subErrors,
797+
getErrorTranslator()(state),
798+
getTranslator()(state),
799+
undefined,
800+
undefined,
801+
undefined
802+
);
794803

795804
return {
796805
...ownProps,
797806
childLabel,
807+
childErrors,
798808
};
799809
};
800810

@@ -823,6 +833,7 @@ export interface OwnPropsOfMasterListItem {
823833

824834
export interface StatePropsOfMasterItem extends OwnPropsOfMasterListItem {
825835
childLabel: string;
836+
childErrors: string;
826837
}
827838

828839
/**

packages/material-renderers/src/additional/ListWithDetailMasterItem.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ import {
3232
ListItemSecondaryAction,
3333
ListItemText,
3434
Tooltip,
35+
SxProps,
3536
} from '@mui/material';
3637
import DeleteIcon from '@mui/icons-material/Delete';
3738
import React from 'react';
39+
import ValidationIcon from '../complex/ValidationIcon';
40+
41+
const avatarSx: SxProps = { display: 'inline-flex' };
3842

3943
export const ListWithDetailMasterItem = ({
4044
index,
4145
childLabel,
46+
childErrors,
4247
selected,
4348
enabled,
4449
handleSelect,
@@ -50,7 +55,12 @@ export const ListWithDetailMasterItem = ({
5055
return (
5156
<ListItemButton selected={selected} onClick={handleSelect(index)}>
5257
<ListItemAvatar>
53-
<Avatar aria-label='Index'>{index + 1}</Avatar>
58+
<Avatar aria-label='Index' sx={avatarSx}>
59+
{index + 1}
60+
</Avatar>
61+
{childErrors.length !== 0 && (
62+
<ValidationIcon id='tooltip-validation' errorMessages={childErrors} />
63+
)}
5464
</ListItemAvatar>
5565
<ListItemText primary={childLabel} />
5666
{enabled && !disableRemove && (

packages/material-renderers/src/additional/MaterialListWithDetailRenderer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ export const MaterialListWithDetailRenderer = ({
7373
}: ArrayLayoutProps & { translations: ArrayTranslations }) => {
7474
const [selectedIndex, setSelectedIndex] = useState(undefined);
7575
const handleRemoveItem = useCallback(
76-
(p: string, value: any) => () => {
76+
(p: string, value: any) => (e?: React.MouseEvent) => {
77+
e?.stopPropagation();
7778
removeItems(p, [value])();
7879
if (selectedIndex === value) {
7980
setSelectedIndex(undefined);
8081
} else if (selectedIndex > value) {
8182
setSelectedIndex(selectedIndex - 1);
8283
}
8384
},
84-
[removeItems, setSelectedIndex]
85+
[removeItems, selectedIndex]
8586
);
8687
const handleListItemClick = useCallback(
8788
(index: number) => () => setSelectedIndex(index),

packages/material-renderers/src/layouts/ExpandPanelRenderer.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import {
3030
ArrayTranslations,
3131
computeChildLabel,
3232
UpdateArrayContext,
33+
subErrorsAt,
34+
fetchErrorTranslator,
35+
fetchTranslator,
36+
getCombinedErrorMessage,
3337
} from '@jsonforms/core';
3438
import {
3539
Accordion,
@@ -39,13 +43,16 @@ import {
3943
Grid,
4044
IconButton,
4145
Tooltip,
46+
SxProps,
4247
} from '@mui/material';
4348
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
4449
import ArrowUpward from '@mui/icons-material/ArrowUpward';
4550
import ArrowDownward from '@mui/icons-material/ArrowDownward';
4651
import DeleteIcon from '@mui/icons-material/Delete';
52+
import ValidationIcon from '../complex/ValidationIcon';
4753

4854
const iconStyle: any = { float: 'right' };
55+
const avatarSx: SxProps = { display: 'inline-flex', marginRight: '.25rem' };
4956

5057
interface OwnPropsOfExpandPanel {
5158
enabled: boolean;
@@ -70,6 +77,7 @@ interface OwnPropsOfExpandPanel {
7077
interface StatePropsOfExpandPanel extends OwnPropsOfExpandPanel {
7178
childLabel: string;
7279
childPath: string;
80+
childErrors: string;
7381
enableMoveUp: boolean;
7482
enableMoveDown: boolean;
7583
}
@@ -100,6 +108,7 @@ const ExpandPanelRendererComponent = (props: ExpandPanelProps) => {
100108
enabled,
101109
childLabel,
102110
childPath,
111+
childErrors,
103112
index,
104113
expanded,
105114
moveDown,
@@ -146,11 +155,19 @@ const ExpandPanelRendererComponent = (props: ExpandPanelProps) => {
146155
onChange={handleExpansion(childPath)}
147156
>
148157
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
149-
<Grid container alignItems={'center'}>
158+
<Grid container alignItems='center'>
150159
<Grid item xs={7} md={9}>
151-
<Grid container alignItems={'center'}>
160+
<Grid container alignItems='center'>
152161
<Grid item xs={2} md={1}>
153-
<Avatar aria-label='Index'>{index + 1}</Avatar>
162+
<Avatar aria-label='Index' sx={avatarSx}>
163+
{index + 1}
164+
</Avatar>
165+
{childErrors.length !== 0 && (
166+
<ValidationIcon
167+
id='tooltip-validation'
168+
errorMessages={childErrors}
169+
/>
170+
)}
154171
</Grid>
155172
<Grid item xs={10} md={11}>
156173
<span id={labelHtmlId}>{childLabel}</span>
@@ -379,12 +396,26 @@ export const withContextToExpandPanelProps = (
379396
uischema,
380397
]);
381398

399+
const childErrors = useMemo(
400+
() =>
401+
getCombinedErrorMessage(
402+
subErrorsAt(childPath, schema)(ctx.core),
403+
fetchErrorTranslator(ctx.i18n),
404+
fetchTranslator(ctx.i18n),
405+
undefined,
406+
undefined,
407+
undefined
408+
),
409+
[ctx.core.errors, ctx.core.validationMode, ctx.i18n, schema, childPath]
410+
);
411+
382412
return (
383413
<Component
384414
{...props}
385415
{...dispatchProps}
386416
childLabel={childLabel}
387417
childPath={childPath}
418+
childErrors={childErrors}
388419
uischemas={uischemas}
389420
/>
390421
);

0 commit comments

Comments
 (0)