mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-05 04:55:50 +01:00
fixed overflow of code and popover
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { FC } from "react";
|
import React, { FC, useRef, useState, MouseEvent, useLayoutEffect } from "react";
|
||||||
import { Person, Repository } from "@scm-manager/ui-types";
|
import { Person, Repository } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -32,7 +32,6 @@ import styled from "styled-components";
|
|||||||
import DateShort from "./DateShort";
|
import DateShort from "./DateShort";
|
||||||
import { SingleContributor } from "./repos/changesets";
|
import { SingleContributor } from "./repos/changesets";
|
||||||
import DateFromNow from "./DateFromNow";
|
import DateFromNow from "./DateFromNow";
|
||||||
import { Link } from "react-router-dom";
|
|
||||||
|
|
||||||
// TODO move types to ui-types
|
// TODO move types to ui-types
|
||||||
|
|
||||||
@@ -55,32 +54,33 @@ type Props = {
|
|||||||
repository: Repository;
|
repository: Repository;
|
||||||
};
|
};
|
||||||
|
|
||||||
type LineElementProps = {
|
const LineElement = styled.div`
|
||||||
newAnnotation: boolean;
|
display: inline-block;
|
||||||
};
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
height: 100%;
|
||||||
|
vertical-align: top;
|
||||||
|
`;
|
||||||
|
|
||||||
const Author = styled.span<LineElementProps>`
|
const Author = styled(LineElement)`
|
||||||
width: 8em;
|
width: 8em;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
float: left;
|
|
||||||
|
|
||||||
visibility: ${({ newAnnotation }) => (newAnnotation ? "visible" : "hidden")};
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const When = styled.span<LineElementProps>`
|
const When = styled(LineElement)`
|
||||||
|
display: inline-block;
|
||||||
|
|
||||||
width: 6.5em;
|
width: 6.5em;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
float: left;
|
|
||||||
|
|
||||||
margin: 0 0.5em;
|
margin: 0 0.5em;
|
||||||
visibility: ${({ newAnnotation }) => (newAnnotation ? "visible" : "hidden")};
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const LineNumber = styled.span`
|
const LineNumber = styled(LineElement)`
|
||||||
width: 3em;
|
width: 3em;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
@@ -90,20 +90,14 @@ const LineNumber = styled.span`
|
|||||||
border-right: 1px solid lightgrey;
|
border-right: 1px solid lightgrey;
|
||||||
|
|
||||||
text-align: right;
|
text-align: right;
|
||||||
float: left;
|
|
||||||
|
|
||||||
padding: 0 0.5em;
|
padding: 0 0.5em;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Popover = styled.div`
|
const PopoverContainer = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: -16.5em;
|
left: 2.25em;
|
||||||
bottom: 0.1em;
|
|
||||||
|
|
||||||
z-index: 100;
|
z-index: 100;
|
||||||
visibility: hidden;
|
|
||||||
overflow: visible;
|
|
||||||
|
|
||||||
width: 35em;
|
width: 35em;
|
||||||
|
|
||||||
&:before {
|
&:before {
|
||||||
@@ -128,17 +122,15 @@ const Popover = styled.div`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const Line = styled.span`
|
const Line = styled.div`
|
||||||
position: relative;
|
margin: 0;
|
||||||
z-index: 10;
|
padding: 0;
|
||||||
|
height: 1.5em;
|
||||||
&:hover .changeset-details {
|
vertical-align: top;
|
||||||
visibility: visible !important;
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const PreTag = styled.pre`
|
const PreTag = styled.pre`
|
||||||
overflow-x: visible !important;
|
position: relative;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const SmallHr = styled.hr`
|
const SmallHr = styled.hr`
|
||||||
@@ -160,7 +152,90 @@ const shortRevision = (revision: string) => {
|
|||||||
return revision;
|
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<PopoverProps> = ({ annotation, offsetTop }) => {
|
||||||
|
const [height, setHeight] = useState(125);
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
if (ref.current) {
|
||||||
|
setHeight(ref.current.clientHeight);
|
||||||
|
}
|
||||||
|
}, [ref]);
|
||||||
|
|
||||||
|
const top = (offsetTop || 0) - height - 5;
|
||||||
|
return (
|
||||||
|
<PopoverContainer ref={ref} className="box changeset-details is-family-primary" style={{ top: `${top}px` }}>
|
||||||
|
<PopoverHeading className="is-clearfix">
|
||||||
|
<SingleContributor className="is-pulled-left" person={annotation.author} />
|
||||||
|
<DateFromNow className="is-pulled-right" date={annotation.when} />
|
||||||
|
</PopoverHeading>
|
||||||
|
<SmallHr />
|
||||||
|
<p className="has-text-info">Changeset {shortRevision(annotation.revision)}</p>
|
||||||
|
<PopoverDescription className="content">{annotation.description}</PopoverDescription>
|
||||||
|
</PopoverContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const Metadata = styled(LineElement)`
|
||||||
|
cursor: help;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const EmptyMetadata = styled(LineElement)`
|
||||||
|
width: 16.7em;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const AnnotateLine: FC<LineProps> = ({ annotation, showAnnotation, setPopOver, nr, children }) => {
|
||||||
|
const link = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const onMouseEnter = (e: MouseEvent) => {
|
||||||
|
if (showAnnotation) {
|
||||||
|
setPopOver(<Popover annotation={annotation} offsetTop={link.current?.offsetTop} />);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const OnMouseLeave = (e: MouseEvent) => {
|
||||||
|
if (showAnnotation) {
|
||||||
|
setPopOver(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!showAnnotation) {
|
||||||
|
return (
|
||||||
|
<Line>
|
||||||
|
<EmptyMetadata />
|
||||||
|
<LineNumber>{nr}</LineNumber> <LineElement>{children}</LineElement>
|
||||||
|
</Line>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Line>
|
||||||
|
<Metadata className="has-text-info" onMouseOver={onMouseEnter} onMouseOut={OnMouseLeave} ref={link}>
|
||||||
|
<Author className="trigger">{annotation.author.name}</Author>{" "}
|
||||||
|
<When>
|
||||||
|
<DateShort value={annotation.when} />
|
||||||
|
</When>{" "}
|
||||||
|
</Metadata>
|
||||||
|
<LineNumber>{nr}</LineNumber> <LineElement>{children}</LineElement>
|
||||||
|
</Line>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const Annotate: FC<Props> = ({ source, repository }) => {
|
const Annotate: FC<Props> = ({ source, repository }) => {
|
||||||
|
const [popOver, setPopOver] = useState<React.ReactNode | null>(null);
|
||||||
|
|
||||||
const defaultRenderer = ({ rows, stylesheet, useInlineStyles }: any) => {
|
const defaultRenderer = ({ rows, stylesheet, useInlineStyles }: any) => {
|
||||||
let lastRevision = "";
|
let lastRevision = "";
|
||||||
return rows.map((node: any, i: number) => {
|
return rows.map((node: any, i: number) => {
|
||||||
@@ -176,26 +251,15 @@ const Annotate: FC<Props> = ({ source, repository }) => {
|
|||||||
const newAnnotation = annotation.revision !== lastRevision;
|
const newAnnotation = annotation.revision !== lastRevision;
|
||||||
lastRevision = annotation.revision;
|
lastRevision = annotation.revision;
|
||||||
return (
|
return (
|
||||||
<Line>
|
<AnnotateLine
|
||||||
<Popover className="box changeset-details is-family-primary">
|
setPopOver={setPopOver}
|
||||||
<PopoverHeading className="is-clearfix">
|
annotation={annotation}
|
||||||
<SingleContributor className="is-pulled-left" person={annotation.author} />
|
showAnnotation={newAnnotation}
|
||||||
<DateFromNow className="is-pulled-right" date={annotation.when} />
|
nr={i + 1}
|
||||||
</PopoverHeading>
|
repository={repository}
|
||||||
<SmallHr />
|
>
|
||||||
<p className="has-text-info">Changeset {shortRevision(annotation.revision)}</p>
|
{line}
|
||||||
<PopoverDescription className="content">{annotation.description}</PopoverDescription>
|
</AnnotateLine>
|
||||||
</Popover>
|
|
||||||
<Author className="trigger" newAnnotation={newAnnotation}>
|
|
||||||
<Link to={`/repo/${repository.namespace}/${repository.name}/code/changeset/${annotation.revision}`}>
|
|
||||||
{annotation.author.name}
|
|
||||||
</Link>
|
|
||||||
</Author>{" "}
|
|
||||||
<When newAnnotation={newAnnotation}>
|
|
||||||
<DateShort value={annotation.when} />
|
|
||||||
</When>{" "}
|
|
||||||
<LineNumber>{i + 1}</LineNumber> {line}
|
|
||||||
</Line>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +273,8 @@ const Annotate: FC<Props> = ({ source, repository }) => {
|
|||||||
}, "");
|
}, "");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div style={{ position: "relative" }}>
|
||||||
|
{popOver}
|
||||||
<ReactSyntaxHighlighter
|
<ReactSyntaxHighlighter
|
||||||
showLineNumbers={false}
|
showLineNumbers={false}
|
||||||
language={source.language}
|
language={source.language}
|
||||||
@@ -218,6 +284,7 @@ const Annotate: FC<Props> = ({ source, repository }) => {
|
|||||||
>
|
>
|
||||||
{code}
|
{code}
|
||||||
</ReactSyntaxHighlighter>
|
</ReactSyntaxHighlighter>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user