Add link to file in diff-view

This commit is contained in:
Florian Scholdei
2020-07-21 19:29:30 +02:00
parent 9a1ec7a5ef
commit 127a335b8f
3 changed files with 26 additions and 3 deletions

View File

@@ -21,8 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React, { FC } from "react";
import { withTranslation, WithTranslation } from "react-i18next"; import { useTranslation, withTranslation, WithTranslation } from "react-i18next";
import classNames from "classnames"; import classNames from "classnames";
import styled from "styled-components"; import styled from "styled-components";
// @ts-ignore // @ts-ignore
@@ -39,6 +39,7 @@ import HunkExpandLink from "./HunkExpandLink";
import { Modal } from "../modals"; import { Modal } from "../modals";
import ErrorNotification from "../ErrorNotification"; import ErrorNotification from "../ErrorNotification";
import HunkExpandDivider from "./HunkExpandDivider"; import HunkExpandDivider from "./HunkExpandDivider";
import Tooltip from "../Tooltip";
const EMPTY_ANNOTATION_FACTORY = {}; const EMPTY_ANNOTATION_FACTORY = {};
@@ -90,6 +91,10 @@ const ChangeTypeTag = styled(Tag)`
margin-left: 0.75rem; margin-left: 0.75rem;
`; `;
const LeftMarginSpan = styled.span`
margin-left: 0.25rem;
`;
class DiffFile extends React.Component<Props, State> { class DiffFile extends React.Component<Props, State> {
static defaultProps: Partial<Props> = { static defaultProps: Partial<Props> = {
defaultCollapse: false, defaultCollapse: false,
@@ -309,7 +314,11 @@ class DiffFile extends React.Component<Props, State> {
if (file._links?.lines) { if (file._links?.lines) {
items.push(this.createHunkHeader(expandableHunk)); items.push(this.createHunkHeader(expandableHunk));
} else if (i > 0) { } else if (i > 0) {
items.push(<Decoration><HunkDivider /></Decoration>); items.push(
<Decoration>
<HunkDivider />
</Decoration>
);
} }
items.push( items.push(
@@ -461,6 +470,7 @@ class DiffFile extends React.Component<Props, State> {
<TitleWrapper className={classNames("is-ellipsis-overflow", "is-size-6")}> <TitleWrapper className={classNames("is-ellipsis-overflow", "is-size-6")}>
{this.renderFileTitle(file)} {this.renderFileTitle(file)}
</TitleWrapper> </TitleWrapper>
<LinkToFile file={file} />
{this.renderChangeTag(file)} {this.renderChangeTag(file)}
</FullWidthTitleHeader> </FullWidthTitleHeader>
{sideBySideToggle} {sideBySideToggle}
@@ -472,4 +482,15 @@ class DiffFile extends React.Component<Props, State> {
} }
} }
const LinkToFile: FC<Props> = ({ file }) => {
const [t] = useTranslation("repos");
return (
<LeftMarginSpan>
<Tooltip location="top" message={t("diff.jumpToFile")}>
<Icon iconStyle="far" name="file-alt" color="grey" className="fa-sm" />
</Tooltip>
</LeftMarginSpan>
);
};
export default withTranslation("repos")(DiffFile); export default withTranslation("repos")(DiffFile);

View File

@@ -223,6 +223,7 @@
} }
}, },
"diff": { "diff": {
"jumpToFile": "Zur Datei springen",
"sideBySide": "Zur zweispaltigen Ansicht wechseln", "sideBySide": "Zur zweispaltigen Ansicht wechseln",
"combined": "Zur kombinierten Ansicht wechseln", "combined": "Zur kombinierten Ansicht wechseln",
"noDiffFound": "Kein Diff zwischen den ausgewählten Branches gefunden.", "noDiffFound": "Kein Diff zwischen den ausgewählten Branches gefunden.",

View File

@@ -230,6 +230,7 @@
"rename": "renamed", "rename": "renamed",
"copy": "copied" "copy": "copied"
}, },
"jumpToFile": "Jump to file",
"sideBySide": "Switch to side-by-side view", "sideBySide": "Switch to side-by-side view",
"combined": "Switch to combined view", "combined": "Switch to combined view",
"noDiffFound": "No Diff between the selected branches found.", "noDiffFound": "No Diff between the selected branches found.",