From 87f3d78148de427f9527cbf03bd4a90f3a19b001 Mon Sep 17 00:00:00 2001 From: Konstantin Schaper Date: Mon, 10 Aug 2020 11:50:56 +0200 Subject: [PATCH] adjust displayed links depending on type of change --- .../ui-components/src/repos/Diff.stories.tsx | 24 +++++----- scm-ui/ui-components/src/repos/Diff.tsx | 3 +- scm-ui/ui-components/src/repos/DiffFile.tsx | 44 ++++++++++++++----- .../src/repos/JumpToFileButton.tsx | 5 +-- .../ui-components/src/repos/LoadingDiff.tsx | 3 +- .../src/repos/changesets/ChangesetDiff.tsx | 2 +- scm-ui/ui-webapp/public/locales/de/repos.json | 3 +- scm-ui/ui-webapp/public/locales/en/repos.json | 3 +- 8 files changed, 57 insertions(+), 30 deletions(-) diff --git a/scm-ui/ui-components/src/repos/Diff.stories.tsx b/scm-ui/ui-components/src/repos/Diff.stories.tsx index e221d5ccd8..1f347872ad 100644 --- a/scm-ui/ui-components/src/repos/Diff.stories.tsx +++ b/scm-ui/ui-components/src/repos/Diff.stories.tsx @@ -35,6 +35,7 @@ import { getPath } from "./diffs"; import DiffButton from "./DiffButton"; import styled from "styled-components"; import { MemoryRouter } from "react-router-dom"; +import {one} from "../__resources__/changesets"; const diffFiles = parser.parse(simpleDiff); @@ -47,12 +48,13 @@ const RoutingDecorator = (story: () => ReactNode) => {storyFn()}) - .add("Default", () => ) - .add("Side-By-Side", () => ) - .add("Collapsed", () => ) + .add("Default", () => ) + .add("Side-By-Side", () => ) + .add("Collapsed", () => ) .add("File Controls", () => ( ( ( [

Custom File annotation for {file.newPath}

]} /> )) .add("Line Annotation", () => ( { return { N2:

Line Annotation

@@ -90,7 +94,7 @@ storiesOf("Diff", module) return ( <> {changeId && } - + ); }; @@ -98,11 +102,11 @@ storiesOf("Diff", module) }) .add("Hunks", () => { const hunkDiffFiles = parser.parse(hunksDiff); - return ; + return ; }) .add("Binaries", () => { const binaryDiffFiles = parser.parse(binaryDiff); - return ; + return ; }) .add("SyntaxHighlighting", () => { const filesWithLanguage = diffFiles.map((file: File) => { @@ -114,22 +118,22 @@ storiesOf("Diff", module) } return file; }); - return ; + return ; }) .add("CollapsingWithFunction", () => ( - oldPath.endsWith(".java")} /> + oldPath.endsWith(".java")} /> )) .add("Expandable", () => { const filesWithLanguage = diffFiles.map((file: File) => { file._links = { lines: { href: "http://example.com/" } }; return file; }); - return ; + return ; }) .add("WithLinkToFile", () => ( )); diff --git a/scm-ui/ui-components/src/repos/Diff.tsx b/scm-ui/ui-components/src/repos/Diff.tsx index f666174476..8978c61d72 100644 --- a/scm-ui/ui-components/src/repos/Diff.tsx +++ b/scm-ui/ui-components/src/repos/Diff.tsx @@ -26,11 +26,12 @@ import DiffFile from "./DiffFile"; import { DiffObjectProps, File } from "./DiffTypes"; import Notification from "../Notification"; import { WithTranslation, withTranslation } from "react-i18next"; +import {Changeset} from "@scm-manager/ui-types"; type Props = WithTranslation & DiffObjectProps & { diff: File[]; - changesetId?: string; + changeset: Changeset; baseUrl?: string; }; diff --git a/scm-ui/ui-components/src/repos/DiffFile.tsx b/scm-ui/ui-components/src/repos/DiffFile.tsx index acf3bff822..dc5070ddd3 100644 --- a/scm-ui/ui-components/src/repos/DiffFile.tsx +++ b/scm-ui/ui-components/src/repos/DiffFile.tsx @@ -40,13 +40,14 @@ import { Modal } from "../modals"; import ErrorNotification from "../ErrorNotification"; import HunkExpandDivider from "./HunkExpandDivider"; import JumpToFileButton from "./JumpToFileButton"; +import {Changeset} from "@scm-manager/ui-types"; const EMPTY_ANNOTATION_FACTORY = {}; type Props = DiffObjectProps & WithTranslation & { file: File; - changesetId?: string; + changeset: Changeset; baseUrl?: string; }; @@ -394,7 +395,7 @@ class DiffFile extends React.Component { hasContent = (file: File) => file && !file.isBinary && file.hunks && file.hunks.length > 0; render() { - const { fileControlFactory, fileAnnotationFactory, changesetId, baseUrl, t } = this.props; + const { fileControlFactory, fileAnnotationFactory, changeset: { id: changesetId, _embedded: { parents } }, baseUrl, t } = this.props; const { file, collapsed, sideBySide, diffExpander, expansionError } = this.state; const viewType = sideBySide ? "split" : "unified"; @@ -418,14 +419,29 @@ class DiffFile extends React.Component { } const collapseIcon = this.hasContent(file) ? : null; const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null; - const jumpToFile = - changesetId && baseUrl ? ( - - ) : null; + let jumpToSource = null; + let jumpToTarget = null; + if (changesetId && baseUrl) { + const jumpToSourceButton = ; + const jumpToTargetButton = parents?.length === 1 && ; + switch (file.type) { + case "add": + jumpToSource = jumpToSourceButton; + break; + case "delete": + jumpToTarget = jumpToTargetButton; + break; + default: + jumpToSource = jumpToSourceButton; + jumpToTarget = jumpToTargetButton; + } + } const sideBySideToggle = file.hunks && file.hunks.length > 0 ? ( @@ -446,12 +462,16 @@ class DiffFile extends React.Component { )} {fileControls} - {jumpToFile} + {jumpToSource} + {jumpToTarget} ) : ( - {jumpToFile} + + {jumpToSource} + {jumpToTarget} + ); diff --git a/scm-ui/ui-components/src/repos/JumpToFileButton.tsx b/scm-ui/ui-components/src/repos/JumpToFileButton.tsx index 6acd91a7a3..59052af3df 100644 --- a/scm-ui/ui-components/src/repos/JumpToFileButton.tsx +++ b/scm-ui/ui-components/src/repos/JumpToFileButton.tsx @@ -38,11 +38,10 @@ const Button = styled(Link)` type Props = { link: string; + tooltip: string; }; -const JumpToFileButton: FC = ({ link }) => { - const [t] = useTranslation("repos"); - const tooltip = t("diff.jumpToFile"); +const JumpToFileButton: FC = ({ link, tooltip }) => { return (