From 1f2cc6b742649c4d83850e16f930380cf20e1e36 Mon Sep 17 00:00:00 2001 From: Klaus Eckelt Date: Fri, 29 Dec 2023 09:48:05 +0000 Subject: [PATCH] show number of changed row/columns in data diff sidebar --- src/Detail/DataDiff.tsx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Detail/DataDiff.tsx b/src/Detail/DataDiff.tsx index e5cd333..f048f85 100644 --- a/src/Detail/DataDiff.tsx +++ b/src/Detail/DataDiff.tsx @@ -3,6 +3,7 @@ import { useStyles } from './DiffDetail'; import { IHTMLDiffProps } from './HTMLDiff'; import { tabletojson } from 'tabletojson'; import * as d3 from 'd3-selection'; +import { makePlural } from '../util'; export const TacoDiff = ({ newCell, oldCell }: IHTMLDiffProps) => { const { classes, cx } = useStyles(); @@ -13,6 +14,9 @@ export const TacoDiff = ({ newCell, oldCell }: IHTMLDiffProps) => { setDiffMode(event.target.value); }; + const [rowChanges, setRowChanges] = React.useState(0); + const [colChanges, setColumnChanges] = React.useState(0); + const unifiedParent = useRef(null); const sideOldParent = useRef(null); const sideNewParent = useRef(null); @@ -27,6 +31,16 @@ export const TacoDiff = ({ newCell, oldCell }: IHTMLDiffProps) => { createSummaryVisualization(unifiedParent.current, newTable[0], oldTable[0], true, true, '#F05268', '#66C2A5'); createSummaryVisualization(sideNewParent.current, newTable[0], oldTable[0], false, true, '#F05268', '#66C2A5'); createSummaryVisualization(sideOldParent.current, oldTable[0], newTable[0], false, true); + + const rowChange = oldOutput + ? Number(newOutput.match(/(\d+) rows/)?.[1] ?? 0) - Number(oldOutput.match(/(\d+) rows/)?.[1] ?? 0) + : 0; + setRowChanges(rowChange); + + const colChange = oldOutput + ? Number(newOutput.match(/(\d+) columns/)?.[1] ?? 0) - Number(oldOutput.match(/(\d+) columns/)?.[1] ?? 0) + : 0; + setColumnChanges(colChange); }); }, []); @@ -84,6 +98,28 @@ export const TacoDiff = ({ newCell, oldCell }: IHTMLDiffProps) => { Unified + {rowChanges || colChanges ? ( + Dataframe Changes + ) : ( + <> + )} + + {rowChanges ? ( + 0 ? '#66C2A5' : '#F05268' }}> + {(rowChanges < 0 ? '' : '+') + rowChanges + makePlural(' row', rowChanges)} + + ) : ( + <> + )} + {rowChanges && colChanges ? ', ' : <>} + {colChanges ? ( + 0 ? '#66C2A5' : '#F05268' }}> + {(colChanges < 0 ? '' : '+') + colChanges + makePlural(' column', colChanges)} + + ) : ( + <> + )} +