/* * Copyright (c) 2020 - present Cloudogu GmbH * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ import React, { FC, useState, useRef, useLayoutEffect, Dispatch } from "react"; import styled from "styled-components"; import { Link } from "react-router-dom"; import DateFromNow from "../../DateFromNow"; import { SingleContributor } from "../changesets"; import { DateInput } from "../../useDateFormatter"; import { Repository, AnnotatedLine } from "@scm-manager/ui-types"; import AuthorImage from "./AuthorImage"; import { Action } from "./actions"; import { useTranslation } from "react-i18next"; const PopoverContainer = styled.div` position: absolute; left: 2.25em; z-index: 100; width: 30em; display: block; &:before { position: absolute; content: ""; border-style: solid; pointer-events: none; height: 0; width: 0; top: 100%; left: 5.5em; border-color: transparent; border-bottom-color: var(--scm-popover-border-color); border-left-color: var(--scm-popover-border-color); border-width: 0.4rem; margin-left: -0.4rem; margin-top: -0.4rem; -webkit-transform-origin: center; transform-origin: center; box-shadow: -1px 1px 2px rgba(10, 10, 10, 0.2); transform: rotate(-45deg); } `; const PopoverHeading = styled.div` height: 1.5em; `; const PopoverDescription = styled.p` overflow-wrap: break-word; `; const shortRevision = (revision: string) => { if (revision.length > 7) { return revision.substring(0, 7); } return revision; }; type PopoverProps = { annotation: AnnotatedLine; offsetTop?: number; repository: Repository; baseDate?: DateInput; dispatch: Dispatch; }; const AnnotatePopover: FC = ({ annotation, offsetTop, repository, baseDate, dispatch }) => { const [t] = useTranslation("repos"); const [height, setHeight] = useState(125); const ref = useRef(null); useLayoutEffect(() => { if (ref.current) { setHeight(ref.current.clientHeight); } }, [ref]); const onMouseEnter = () => { dispatch({ type: "enter-popover", }); }; const OnMouseLeave = () => { dispatch({ type: "leave-popover", }); }; const top = (offsetTop || 0) - height - 5; return (

{t("changeset.label") + " "} {shortRevision(annotation.revision)}

{annotation.description}
); }; export default AnnotatePopover;