From 1cddccff9fd21544d364a5698deb7bf659d221e3 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Mon, 15 Jun 2020 13:07:18 +0200 Subject: [PATCH] fixed overflow of code and popover --- scm-ui/ui-components/src/Annotate.tsx | 183 ++++++++++++++++++-------- 1 file changed, 125 insertions(+), 58 deletions(-) diff --git a/scm-ui/ui-components/src/Annotate.tsx b/scm-ui/ui-components/src/Annotate.tsx index 31dd10e327..d34d977174 100644 --- a/scm-ui/ui-components/src/Annotate.tsx +++ b/scm-ui/ui-components/src/Annotate.tsx @@ -22,7 +22,7 @@ * SOFTWARE. */ -import React, { FC } from "react"; +import React, { FC, useRef, useState, MouseEvent, useLayoutEffect } from "react"; import { Person, Repository } from "@scm-manager/ui-types"; // @ts-ignore @@ -32,7 +32,6 @@ import styled from "styled-components"; import DateShort from "./DateShort"; import { SingleContributor } from "./repos/changesets"; import DateFromNow from "./DateFromNow"; -import { Link } from "react-router-dom"; // TODO move types to ui-types @@ -55,32 +54,33 @@ type Props = { repository: Repository; }; -type LineElementProps = { - newAnnotation: boolean; -}; +const LineElement = styled.div` + display: inline-block; + margin: 0; + padding: 0; + height: 100%; + vertical-align: top; +`; -const Author = styled.span` +const Author = styled(LineElement)` width: 8em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - float: left; - - visibility: ${({ newAnnotation }) => (newAnnotation ? "visible" : "hidden")}; `; -const When = styled.span` +const When = styled(LineElement)` + display: inline-block; + width: 6.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; - float: left; margin: 0 0.5em; - visibility: ${({ newAnnotation }) => (newAnnotation ? "visible" : "hidden")}; `; -const LineNumber = styled.span` +const LineNumber = styled(LineElement)` width: 3em; overflow: hidden; text-overflow: ellipsis; @@ -90,20 +90,14 @@ const LineNumber = styled.span` border-right: 1px solid lightgrey; text-align: right; - float: left; padding: 0 0.5em; `; -const Popover = styled.div` +const PopoverContainer = styled.div` position: absolute; - left: -16.5em; - bottom: 0.1em; - + left: 2.25em; z-index: 100; - visibility: hidden; - overflow: visible; - width: 35em; &:before { @@ -128,17 +122,15 @@ const Popover = styled.div` } `; -const Line = styled.span` - position: relative; - z-index: 10; - - &:hover .changeset-details { - visibility: visible !important; - } +const Line = styled.div` + margin: 0; + padding: 0; + height: 1.5em; + vertical-align: top; `; const PreTag = styled.pre` - overflow-x: visible !important; + position: relative; `; const SmallHr = styled.hr` @@ -160,7 +152,90 @@ const shortRevision = (revision: string) => { return revision; }; +type LineProps = { + annotation: AnnotatedLine; + showAnnotation: boolean; + nr: number; + repository: Repository; + setPopOver: (popover: React.ReactNode) => void; +}; + +type PopoverProps = { + annotation: AnnotatedLine; + offsetTop?: number; +}; + +const Popover: FC = ({ annotation, offsetTop }) => { + const [height, setHeight] = useState(125); + const ref = useRef(null); + useLayoutEffect(() => { + if (ref.current) { + setHeight(ref.current.clientHeight); + } + }, [ref]); + + const top = (offsetTop || 0) - height - 5; + return ( + + + + + + +

Changeset {shortRevision(annotation.revision)}

+ {annotation.description} +
+ ); +}; + +const Metadata = styled(LineElement)` + cursor: help; +`; + +const EmptyMetadata = styled(LineElement)` + width: 16.7em; +`; + +const AnnotateLine: FC = ({ annotation, showAnnotation, setPopOver, nr, children }) => { + const link = useRef(null); + + const onMouseEnter = (e: MouseEvent) => { + if (showAnnotation) { + setPopOver(); + } + }; + + const OnMouseLeave = (e: MouseEvent) => { + if (showAnnotation) { + setPopOver(null); + } + }; + + if (!showAnnotation) { + return ( + + + {nr} {children} + + ); + } + + return ( + + + {annotation.author.name}{" "} + + + {" "} + + {nr} {children} + + ); +}; + const Annotate: FC = ({ source, repository }) => { + const [popOver, setPopOver] = useState(null); + const defaultRenderer = ({ rows, stylesheet, useInlineStyles }: any) => { let lastRevision = ""; return rows.map((node: any, i: number) => { @@ -176,26 +251,15 @@ const Annotate: FC = ({ source, repository }) => { const newAnnotation = annotation.revision !== lastRevision; lastRevision = annotation.revision; return ( - - - - - - - -

Changeset {shortRevision(annotation.revision)}

- {annotation.description} -
- - - {annotation.author.name} - - {" "} - - - {" "} - {i + 1} {line} -
+ + {line} + ); } @@ -209,15 +273,18 @@ const Annotate: FC = ({ source, repository }) => { }, ""); return ( - - {code} - +
+ {popOver} + + {code} + +
); };