From b42dc5edc3445e451f40d9addf1acb086435f309 Mon Sep 17 00:00:00 2001 From: molotgor Date: Tue, 11 Feb 2025 15:33:45 +0400 Subject: [PATCH] fix bottom border of leafs --- src/components/JSONViewer/EmptyLeaf.tsx | 30 ++++++++++++++-- src/components/JSONViewer/TreeLeaf.tsx | 47 +++++++------------------ src/components/JSONViewer/TreeList.tsx | 12 +------ src/styles/JSONviewer.scss | 8 +++++ 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/components/JSONViewer/EmptyLeaf.tsx b/src/components/JSONViewer/EmptyLeaf.tsx index b7abd565..5e4ae8cd 100644 --- a/src/components/JSONViewer/EmptyLeaf.tsx +++ b/src/components/JSONViewer/EmptyLeaf.tsx @@ -53,8 +53,34 @@ const EmptyLeaf = ({ [`borderBottomColor`]: LEAF_COLORS[chunkColor], [`borderBottomWidth`]: isNextDifferentChunk ? '4px' : undefined, [`borderBottom${otherBorderSide}Radius`]: isNextDifferentChunk ? '0px' : undefined, - }} - /> + padding: '5px', + flexDirection: 'row', + justifyContent: borderSide === 'Left' ? 'flex-start' : 'flex-end', + alignItems: 'center', + }}> + {/* + {JSONViewerStore.isCompare && borderSide === 'Left' && ( +
{ + e.preventDefault(); + JSONViewerStore.scrollToNearest(chunkNode.chunk * JSONViewerStore.сhunkInterval, type); + }} + /> + )} + {JSONViewerStore.isCompare && borderSide === 'Right' && ( +
{ + e.preventDefault(); + JSONViewerStore.scrollToNearest(chunkNode.chunk * JSONViewerStore.сhunkInterval, type); + }} + /> + )} + */} +
); }; diff --git a/src/components/JSONViewer/TreeLeaf.tsx b/src/components/JSONViewer/TreeLeaf.tsx index 0b08e8c8..fa67cecc 100644 --- a/src/components/JSONViewer/TreeLeaf.tsx +++ b/src/components/JSONViewer/TreeLeaf.tsx @@ -16,17 +16,7 @@ import { getChunk } from '../../helpers/JSONViewer'; export const LEAF_COLORS = ['lightgray', 'black']; export const LEAF_BACKGROUND_COLORS = ['white', 'gainsboro']; -const TreeLeaf = ({ - treeNode, - type, - nextNodeTimestamp, - nextNodeChunk, -}: { - treeNode: TreeNode; - type: PanelType; - nextNodeTimestamp?: number; - nextNodeChunk?: number; -}) => { +const TreeLeaf = ({ treeNode, type }: { treeNode: TreeNode; type: PanelType }) => { const JSONViewerStore = useJSONViewerStore(); const isSelected = treeNode.id === JSONViewerStore.selectedTreeNode[type].id; const viewType = treeNode.viewType || TreeViewType.EVENTS_LIST; @@ -53,31 +43,16 @@ const TreeLeaf = ({ [treeNode.displayTimestamp, JSONViewerStore.сhunkInterval], ); - const nextChunk = useMemo( - () => nextNodeChunk || getChunk(nextNodeTimestamp, JSONViewerStore.сhunkInterval), - [nextNodeChunk, nextNodeTimestamp, JSONViewerStore.сhunkInterval], - ); - const chunkColor = useMemo(() => JSONViewerStore.intervalsColor[chunk], [chunk]); - const nextChunkColor = useMemo(() => JSONViewerStore.intervalsColor[nextChunk], [nextChunk]); - - const isNextDifferentChunk = useMemo( - () => nextChunkColor === chunkColor && nextChunk !== chunk && chunk !== -1 && nextChunk !== -1, - [chunk, nextChunk, chunkColor, nextChunkColor], - ); const leafRef = useRef(null); const borderSide = type === 'default' ? 'Right' : 'Left'; - const otherBorderSide = type === 'default' ? 'Left' : 'Right'; const borderStyle = { [`border${borderSide}Color`]: chunk !== -1 ? LEAF_COLORS[chunkColor] : undefined, [`border${borderSide}Width`]: chunk !== -1 ? '5px' : undefined, [`borderTop${borderSide}Radius`]: chunk !== -1 ? '0px' : undefined, [`borderBottom${borderSide}Radius`]: chunk !== -1 ? '0px' : undefined, - [`borderBottomColor`]: chunk !== -1 ? LEAF_COLORS[chunkColor] : undefined, - [`borderBottomWidth`]: isNextDifferentChunk ? '4px' : undefined, - [`borderBottom${otherBorderSide}Radius`]: isNextDifferentChunk ? '0px' : undefined, }; const splitContent = JSONViewerStore.compareNameResults( @@ -105,15 +80,19 @@ const TreeLeaf = ({ useEffect(() => { const resizeObserver = new ResizeObserver(entries => { - JSONViewerStore.setNodeHeight( - treeNode.id, - treeNode.displayTimestamp, + const currentHeight = JSONViewerStore.heights[type].get(treeNode.id); + const height = entries[0].borderBoxSize?.length > 0 ? entries[0].borderBoxSize[0].blockSize - : entries[0].contentRect.height, - treeNode.parentIds, - type, - ); + : entries[0].contentRect.height; + if (!currentHeight || currentHeight.height !== height) + JSONViewerStore.setNodeHeight( + treeNode.id, + treeNode.displayTimestamp, + height, + treeNode.parentIds, + type, + ); }); if (leafRef.current) { resizeObserver.observe(leafRef.current); @@ -174,7 +153,7 @@ const TreeLeaf = ({ backgroundColor: chunk !== -1 ? LEAF_BACKGROUND_COLORS[chunkColor] : undefined, ...borderStyle, }}> -
+
{JSONViewerStore.isCompare && treeNode.displayTimestamp && borderSide === 'Left' && (
{ const renderTree = React.useCallback( (index: number, dataNode: TreeNode | NotebookNode | ChunkHeightData) => { if ('id' in dataNode) { - const nextNode = JSONViewerStore.listData[type][index + 1]; - const nextTimestamp = nextNode && 'id' in nextNode ? nextNode.displayTimestamp : undefined; - const nextChunk = nextNode && 'lastElement' in nextNode ? nextNode.chunk : undefined; - return ( - - ); + return ; } if ('lastElement' in dataNode) { const nextNode = JSONViewerStore.listData[type][index + 1]; diff --git a/src/styles/JSONviewer.scss b/src/styles/JSONviewer.scss index 6ecd7d4e..972d4f78 100644 --- a/src/styles/JSONviewer.scss +++ b/src/styles/JSONviewer.scss @@ -137,6 +137,14 @@ flex-direction: row; align-items: center; padding: 1px 5px 1px 0; + &-right { + display: flex; + gap: 5px; + flex-direction: row; + align-items: center; + padding: 1px 0 1px 5px; + + } } .leaf {