From 2e460b16fdba556bf3f20acf92ad9e405e41990e Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Thu, 19 Jun 2025 10:08:28 +0200 Subject: [PATCH] Chore(1 3836)/no changes in json diff (#10175) Contains several improvements for the new json diff render: 1. Removes extra left-inset of the +/- icons for changed lines. This means that the +/- icons will now show up in the change request popover, whereas they were hidden (pushed outside the frame) previously). 2. Change styling based on whether it's an edit or a full replacement. If it's an edit, keep the +/- icons per changed line. If it's a full replacement (e.g. the object has been created or deleted), don't show the +/- icons, and make the whole object the right color (specifically: this also colors the surrounding braces that weren't colored before). Not showing +/- for new/deleted objects is in line with how the previous system worked. 3. If there are no changes, show `(no changes)`, as we did before. Unfortunately, I don't think the component has any fallback for this case, so we can't render arbitrary code. However, when it does happen, the .diff container doesn't have any children, so we can render it with CSS. It's not ideal for accessibility reasons etc, but it's better than nothing, I think. 4. Adds a +/- to the button to open and close the full diff to indicate better what it does. Also, only shows the button if it's an edit. When it's a replacement, we show the full diff anyway, so the button has no effect. 5. Does not exclude any keys by default anymore, but makes it a parameter ## Left inset change + no excluded keys: Before: image After: image ## Edit vs full replacement Before: image (notice the surrounding braces (`{}`) aren't the right color) image After: image image ## No changes Before: image After: image (The show all props button will show the whole object regardless): image ## Button Before: image After: image --- .../component/events/EventDiff/EventDiff.tsx | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/frontend/src/component/events/EventDiff/EventDiff.tsx b/frontend/src/component/events/EventDiff/EventDiff.tsx index c0b3c8dfd9..f5bc7bf8fd 100644 --- a/frontend/src/component/events/EventDiff/EventDiff.tsx +++ b/frontend/src/component/events/EventDiff/EventDiff.tsx @@ -23,6 +23,7 @@ interface IEventDiffProps { * @deprecated remove with flag improvedJsonDiff */ sort?: (a: IEventDiffResult, b: IEventDiffResult) => number; + excludeKeys?: string[]; } const DiffStyles = styled('div')(({ theme }) => ({ @@ -37,7 +38,6 @@ const DiffStyles = styled('div')(({ theme }) => ({ position: 'absolute', left: 0, top: 0, - marginLeft: '-10px', }, }, @@ -47,35 +47,65 @@ const DiffStyles = styled('div')(({ theme }) => ({ content: '"+"', }, }, + '.deletion': { color: theme.palette.eventLog.diffSub, '::before': { content: '"-"', }, }, + + '&[data-change-type="replacement"]': { + ':has(.addition)': { + color: theme.palette.eventLog.diffAdd, + }, + ':has(.deletion)': { + color: theme.palette.eventLog.diffSub, + }, + '.addition::before, .deletion::before': { + content: 'none', + }, + }, + + '.diff:not(:has(*))': { + '::before': { + content: '"(no changes)"', + }, + }, })); -const NewEventDiff: FC = ({ entry }) => { +const ButtonIcon = styled('span')(({ theme }) => ({ + marginInlineEnd: theme.spacing(0.5), +})); + +const NewEventDiff: FC = ({ entry, excludeKeys }) => { + const changeType = entry.preData && entry.data ? 'edit' : 'replacement'; + const showExpandButton = changeType === 'edit'; const [full, setFull] = useState(false); const diffId = useId(); return ( <> - - + {showExpandButton ? ( + + ) : null} +