refactor to use file control factory

This commit is contained in:
Konstantin Schaper
2020-08-10 20:48:08 +02:00
parent 08efc9421d
commit c69ab4ea65
12 changed files with 226 additions and 190 deletions

View File

@@ -29,13 +29,15 @@ import parser from "gitdiff-parser";
import simpleDiff from "../__resources__/Diff.simple"; import simpleDiff from "../__resources__/Diff.simple";
import hunksDiff from "../__resources__/Diff.hunks"; import hunksDiff from "../__resources__/Diff.hunks";
import binaryDiff from "../__resources__/Diff.binary"; import binaryDiff from "../__resources__/Diff.binary";
import { DiffEventContext, File } from "./DiffTypes"; import {DiffEventContext, File, FileControlFactory} from "./DiffTypes";
import Toast from "../toast/Toast"; import Toast from "../toast/Toast";
import { getPath } from "./diffs"; import { getPath } from "./diffs";
import DiffButton from "./DiffButton"; import DiffButton from "./DiffButton";
import styled from "styled-components"; import styled from "styled-components";
import { MemoryRouter } from "react-router-dom"; import { MemoryRouter } from "react-router-dom";
import {one} from "../__resources__/changesets"; import {one, two} from "../__resources__/changesets";
import {Changeset} from "@scm-manager/ui-types";
import JumpToFileButton from "./JumpToFileButton";
const diffFiles = parser.parse(simpleDiff); const diffFiles = parser.parse(simpleDiff);
@@ -45,16 +47,50 @@ const Container = styled.div`
const RoutingDecorator = (story: () => ReactNode) => <MemoryRouter initialEntries={["/"]}>{story()}</MemoryRouter>; const RoutingDecorator = (story: () => ReactNode) => <MemoryRouter initialEntries={["/"]}>{story()}</MemoryRouter>;
const fileControlFactory: (changeset: Changeset) => FileControlFactory = (changeset) => (file) => {
const baseUrl = "/repo/hitchhiker/heartOfGold/code/changeset";
const sourceLink = {
url: `${baseUrl}/${changeset.id}/${file.newPath}/`,
label: "Jump to source"
};
const targetLink = changeset._embedded?.parents?.length === 1 && {
url: `${baseUrl}/${changeset._embedded.parents[0].id}/${file.oldPath}`,
label: "Jump to target"
};
const links = [];
switch (file.type) {
case "add":
links.push(sourceLink);
break;
case "delete":
if (targetLink) {
links.push(targetLink);
}
break;
default:
if (targetLink) {
links.push(sourceLink, targetLink);
} else {
links.push(sourceLink);
}
}
return links.map(({url, label}) => <JumpToFileButton
tooltip={label}
link={url}
/>);
};
storiesOf("Diff", module) storiesOf("Diff", module)
.addDecorator(RoutingDecorator) .addDecorator(RoutingDecorator)
.addDecorator(storyFn => <Container>{storyFn()}</Container>) .addDecorator(storyFn => <Container>{storyFn()}</Container>)
.add("Default", () => <Diff diff={diffFiles} changeset={one} />) .add("Default", () => <Diff diff={diffFiles} />)
.add("Side-By-Side", () => <Diff diff={diffFiles} sideBySide={true} changeset={one} />) .add("Side-By-Side", () => <Diff diff={diffFiles} sideBySide={true} />)
.add("Collapsed", () => <Diff diff={diffFiles} defaultCollapse={true} changeset={one} />) .add("Collapsed", () => <Diff diff={diffFiles} defaultCollapse={true} fileControlFactory={fileControlFactory(two)} />)
.add("File Controls", () => ( .add("File Controls", () => (
<Diff <Diff
diff={diffFiles} diff={diffFiles}
changeset={one}
fileControlFactory={() => ( fileControlFactory={() => (
<DiffButton <DiffButton
tooltip="A skull and crossbones or death's head is a symbol consisting of a human skull and two long bones crossed together under or behind the skull. The design originates in the Late Middle Ages as a symbol of death and especially as a memento mori on tombstones." tooltip="A skull and crossbones or death's head is a symbol consisting of a human skull and two long bones crossed together under or behind the skull. The design originates in the Late Middle Ages as a symbol of death and especially as a memento mori on tombstones."
@@ -67,14 +103,12 @@ storiesOf("Diff", module)
.add("File Annotation", () => ( .add("File Annotation", () => (
<Diff <Diff
diff={diffFiles} diff={diffFiles}
changeset={one}
fileAnnotationFactory={file => [<p key={file.newPath}>Custom File annotation for {file.newPath}</p>]} fileAnnotationFactory={file => [<p key={file.newPath}>Custom File annotation for {file.newPath}</p>]}
/> />
)) ))
.add("Line Annotation", () => ( .add("Line Annotation", () => (
<Diff <Diff
diff={diffFiles} diff={diffFiles}
changeset={one}
annotationFactory={ctx => { annotationFactory={ctx => {
return { return {
N2: <p key="N2">Line Annotation</p> N2: <p key="N2">Line Annotation</p>
@@ -94,7 +128,7 @@ storiesOf("Diff", module)
return ( return (
<> <>
{changeId && <Toast type="info" title={"Change " + changeId} />} {changeId && <Toast type="info" title={"Change " + changeId} />}
<Diff diff={diffFiles} changeset={one} onClick={onClick} /> <Diff diff={diffFiles} onClick={onClick} />
</> </>
); );
}; };
@@ -102,11 +136,11 @@ storiesOf("Diff", module)
}) })
.add("Hunks", () => { .add("Hunks", () => {
const hunkDiffFiles = parser.parse(hunksDiff); const hunkDiffFiles = parser.parse(hunksDiff);
return <Diff diff={hunkDiffFiles} changeset={one} />; return <Diff diff={hunkDiffFiles} />;
}) })
.add("Binaries", () => { .add("Binaries", () => {
const binaryDiffFiles = parser.parse(binaryDiff); const binaryDiffFiles = parser.parse(binaryDiff);
return <Diff diff={binaryDiffFiles} changeset={one} />; return <Diff diff={binaryDiffFiles} />;
}) })
.add("SyntaxHighlighting", () => { .add("SyntaxHighlighting", () => {
const filesWithLanguage = diffFiles.map((file: File) => { const filesWithLanguage = diffFiles.map((file: File) => {
@@ -118,22 +152,20 @@ storiesOf("Diff", module)
} }
return file; return file;
}); });
return <Diff diff={filesWithLanguage} changeset={one} />; return <Diff diff={filesWithLanguage} />;
}) })
.add("CollapsingWithFunction", () => ( .add("CollapsingWithFunction", () => (
<Diff diff={diffFiles} changeset={one} defaultCollapse={(oldPath, newPath) => oldPath.endsWith(".java")} /> <Diff diff={diffFiles} defaultCollapse={(oldPath, newPath) => oldPath.endsWith(".java")} />
)) ))
.add("Expandable", () => { .add("Expandable", () => {
const filesWithLanguage = diffFiles.map((file: File) => { const filesWithLanguage = diffFiles.map((file: File) => {
file._links = { lines: { href: "http://example.com/" } }; file._links = { lines: { href: "http://example.com/" } };
return file; return file;
}); });
return <Diff diff={filesWithLanguage} changeset={one} />; return <Diff diff={filesWithLanguage} />;
}) })
.add("WithLinkToFile", () => ( .add("WithLinkToFile", () => (
<Diff <Diff
diff={diffFiles} diff={diffFiles}
changeset={one}
baseUrl="/repo/hitchhiker/heartOfGold/code/changeset"
/> />
)); ));

View File

@@ -23,17 +23,15 @@
*/ */
import React from "react"; import React from "react";
import DiffFile from "./DiffFile"; import DiffFile from "./DiffFile";
import { DiffObjectProps, File } from "./DiffTypes"; import {DiffObjectProps, File, FileControlFactory} from "./DiffTypes";
import Notification from "../Notification"; import Notification from "../Notification";
import { WithTranslation, withTranslation } from "react-i18next"; import {WithTranslation, withTranslation} from "react-i18next";
import {Changeset} from "@scm-manager/ui-types";
type Props = WithTranslation & type Props = WithTranslation &
DiffObjectProps & { DiffObjectProps & {
diff: File[]; diff: File[];
changeset: Changeset; fileControlFactory?: FileControlFactory;
baseUrl?: string; };
};
class Diff extends React.Component<Props> { class Diff extends React.Component<Props> {
static defaultProps: Partial<Props> = { static defaultProps: Partial<Props> = {
@@ -41,7 +39,7 @@ class Diff extends React.Component<Props> {
}; };
render() { render() {
const { diff, t, ...fileProps } = this.props; const {diff, t, ...fileProps} = this.props;
return ( return (
<> <>
{diff.length === 0 ? ( {diff.length === 0 ? (

View File

@@ -22,34 +22,30 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React from "react";
import { withTranslation, WithTranslation } from "react-i18next"; import {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
import { Decoration, getChangeKey, Hunk } from "react-diff-view"; import {Decoration, getChangeKey, Hunk} from "react-diff-view";
import { ButtonGroup } from "../buttons"; import {ButtonGroup} from "../buttons";
import Tag from "../Tag"; import Tag from "../Tag";
import Icon from "../Icon"; import Icon from "../Icon";
import { Change, ChangeEvent, DiffObjectProps, File, Hunk as HunkType } from "./DiffTypes"; import {Change, ChangeEvent, DiffObjectProps, File, Hunk as HunkType} from "./DiffTypes";
import TokenizedDiffView from "./TokenizedDiffView"; import TokenizedDiffView from "./TokenizedDiffView";
import DiffButton from "./DiffButton"; import DiffButton from "./DiffButton";
import { MenuContext } from "@scm-manager/ui-components"; import {MenuContext} from "@scm-manager/ui-components";
import DiffExpander, { ExpandableHunk } from "./DiffExpander"; import DiffExpander, {ExpandableHunk} from "./DiffExpander";
import HunkExpandLink from "./HunkExpandLink"; 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 JumpToFileButton from "./JumpToFileButton";
import {Changeset} from "@scm-manager/ui-types";
const EMPTY_ANNOTATION_FACTORY = {}; const EMPTY_ANNOTATION_FACTORY = {};
type Props = DiffObjectProps & type Props = DiffObjectProps &
WithTranslation & { WithTranslation & {
file: File; file: File;
changeset: Changeset; };
baseUrl?: string;
};
type Collapsible = { type Collapsible = {
collapsed?: boolean; collapsed?: boolean;
@@ -119,7 +115,7 @@ class DiffFile extends React.Component<Props, State> {
} }
defaultCollapse: () => boolean = () => { defaultCollapse: () => boolean = () => {
const { defaultCollapse, file } = this.props; const {defaultCollapse, file} = this.props;
if (typeof defaultCollapse === "boolean") { if (typeof defaultCollapse === "boolean") {
return defaultCollapse; return defaultCollapse;
} else if (typeof defaultCollapse === "function") { } else if (typeof defaultCollapse === "function") {
@@ -130,7 +126,7 @@ class DiffFile extends React.Component<Props, State> {
}; };
toggleCollapse = () => { toggleCollapse = () => {
const { file } = this.state; const {file} = this.state;
if (this.hasContent(file)) { if (this.hasContent(file)) {
this.setState(state => ({ this.setState(state => ({
collapsed: !state.collapsed collapsed: !state.collapsed
@@ -161,7 +157,7 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-double-up"} icon={"fa-angle-double-up"}
onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)} onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandHeadRange })} text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandHeadRange})}
/> />
</HunkExpandDivider> </HunkExpandDivider>
); );
@@ -171,19 +167,19 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-up"} icon={"fa-angle-up"}
onClick={this.expandHead(expandableHunk, 10)} onClick={this.expandHead(expandableHunk, 10)}
text={this.props.t("diff.expandByLines", { count: 10 })} text={this.props.t("diff.expandByLines", {count: 10})}
/>{" "} />{" "}
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-double-up"} icon={"fa-angle-double-up"}
onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)} onClick={this.expandHead(expandableHunk, expandableHunk.maxExpandHeadRange)}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandHeadRange })} text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandHeadRange})}
/> />
</HunkExpandDivider> </HunkExpandDivider>
); );
} }
} }
// hunk header must be defined // hunk header must be defined
return <span />; return <span/>;
}; };
createHunkFooter = (expandableHunk: ExpandableHunk) => { createHunkFooter = (expandableHunk: ExpandableHunk) => {
@@ -194,7 +190,7 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-double-down"} icon={"fa-angle-double-down"}
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)} onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandBottomRange })} text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandBottomRange})}
/> />
</HunkExpandDivider> </HunkExpandDivider>
); );
@@ -204,19 +200,19 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-down"} icon={"fa-angle-down"}
onClick={this.expandBottom(expandableHunk, 10)} onClick={this.expandBottom(expandableHunk, 10)}
text={this.props.t("diff.expandByLines", { count: 10 })} text={this.props.t("diff.expandByLines", {count: 10})}
/>{" "} />{" "}
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-double-down"} icon={"fa-angle-double-down"}
onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)} onClick={this.expandBottom(expandableHunk, expandableHunk.maxExpandBottomRange)}
text={this.props.t("diff.expandComplete", { count: expandableHunk.maxExpandBottomRange })} text={this.props.t("diff.expandComplete", {count: expandableHunk.maxExpandBottomRange})}
/> />
</HunkExpandDivider> </HunkExpandDivider>
); );
} }
} }
// hunk footer must be defined // hunk footer must be defined
return <span />; return <span/>;
}; };
createLastHunkFooter = (expandableHunk: ExpandableHunk) => { createLastHunkFooter = (expandableHunk: ExpandableHunk) => {
@@ -226,7 +222,7 @@ class DiffFile extends React.Component<Props, State> {
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-down"} icon={"fa-angle-down"}
onClick={this.expandBottom(expandableHunk, 10)} onClick={this.expandBottom(expandableHunk, 10)}
text={this.props.t("diff.expandLastBottomByLines", { count: 10 })} text={this.props.t("diff.expandLastBottomByLines", {count: 10})}
/>{" "} />{" "}
<HunkExpandLink <HunkExpandLink
icon={"fa-angle-double-down"} icon={"fa-angle-double-down"}
@@ -237,7 +233,7 @@ class DiffFile extends React.Component<Props, State> {
); );
} }
// hunk header must be defined // hunk header must be defined
return <span />; return <span/>;
}; };
expandHead = (expandableHunk: ExpandableHunk, count: number) => { expandHead = (expandableHunk: ExpandableHunk, count: number) => {
@@ -259,16 +255,16 @@ class DiffFile extends React.Component<Props, State> {
}; };
diffExpanded = (newFile: File) => { diffExpanded = (newFile: File) => {
this.setState({ file: newFile, diffExpander: new DiffExpander(newFile) }); this.setState({file: newFile, diffExpander: new DiffExpander(newFile)});
}; };
diffExpansionFailed = (err: any) => { diffExpansionFailed = (err: any) => {
this.setState({ expansionError: err }); this.setState({expansionError: err});
}; };
collectHunkAnnotations = (hunk: HunkType) => { collectHunkAnnotations = (hunk: HunkType) => {
const { annotationFactory } = this.props; const {annotationFactory} = this.props;
const { file } = this.state; const {file} = this.state;
if (annotationFactory) { if (annotationFactory) {
return annotationFactory({ return annotationFactory({
hunk, hunk,
@@ -280,8 +276,8 @@ class DiffFile extends React.Component<Props, State> {
}; };
handleClickEvent = (change: Change, hunk: HunkType) => { handleClickEvent = (change: Change, hunk: HunkType) => {
const { onClick } = this.props; const {onClick} = this.props;
const { file } = this.state; const {file} = this.state;
const context = { const context = {
changeId: getChangeKey(change), changeId: getChangeKey(change),
change, change,
@@ -294,7 +290,7 @@ class DiffFile extends React.Component<Props, State> {
}; };
createGutterEvents = (hunk: HunkType) => { createGutterEvents = (hunk: HunkType) => {
const { onClick } = this.props; const {onClick} = this.props;
if (onClick) { if (onClick) {
return { return {
onClick: (event: ChangeEvent) => { onClick: (event: ChangeEvent) => {
@@ -315,7 +311,7 @@ class DiffFile extends React.Component<Props, State> {
} else if (i > 0) { } else if (i > 0) {
items.push( items.push(
<Decoration> <Decoration>
<HunkDivider /> <HunkDivider/>
</Decoration> </Decoration>
); );
} }
@@ -358,7 +354,7 @@ class DiffFile extends React.Component<Props, State> {
if (file.oldPath !== file.newPath && (file.type === "copy" || file.type === "rename")) { if (file.oldPath !== file.newPath && (file.type === "copy" || file.type === "rename")) {
return ( return (
<> <>
{file.oldPath} <Icon name="arrow-right" color="inherit" /> {file.newPath} {file.oldPath} <Icon name="arrow-right" color="inherit"/> {file.newPath}
</> </>
); );
} else if (file.type === "delete") { } else if (file.type === "delete") {
@@ -377,7 +373,7 @@ class DiffFile extends React.Component<Props, State> {
}; };
renderChangeTag = (file: File) => { renderChangeTag = (file: File) => {
const { t } = this.props; const {t} = this.props;
if (!file.type) { if (!file.type) {
return; return;
} }
@@ -389,14 +385,14 @@ class DiffFile extends React.Component<Props, State> {
const color = const color =
value === "added" ? "success is-outlined" : value === "deleted" ? "danger is-outlined" : "info is-outlined"; value === "added" ? "success is-outlined" : value === "deleted" ? "danger is-outlined" : "info is-outlined";
return <ChangeTypeTag className={classNames("is-rounded", "has-text-weight-normal")} color={color} label={value} />; return <ChangeTypeTag className={classNames("is-rounded", "has-text-weight-normal")} color={color} label={value}/>;
}; };
hasContent = (file: File) => file && !file.isBinary && file.hunks && file.hunks.length > 0; hasContent = (file: File) => file && !file.isBinary && file.hunks && file.hunks.length > 0;
render() { render() {
const { fileControlFactory, fileAnnotationFactory, changeset: { id: changesetId, _embedded: { parents } }, baseUrl, t } = this.props; const {fileControlFactory, fileAnnotationFactory, t} = this.props;
const { file, collapsed, sideBySide, diffExpander, expansionError } = this.state; const {file, collapsed, sideBySide, diffExpander, expansionError} = this.state;
const viewType = sideBySide ? "split" : "unified"; const viewType = sideBySide ? "split" : "unified";
let body = null; let body = null;
@@ -417,37 +413,14 @@ class DiffFile extends React.Component<Props, State> {
</div> </div>
); );
} }
const collapseIcon = this.hasContent(file) ? <Icon name={icon} color="inherit" /> : null; const collapseIcon = this.hasContent(file) ? <Icon name={icon} color="inherit"/> : null;
const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null; const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null;
let jumpToSource = null;
let jumpToTarget = null;
if (changesetId && baseUrl) {
const jumpToSourceButton = <JumpToFileButton
tooltip={this.props.t("diff.jumpToSource")}
link={`${baseUrl.substr(0, baseUrl.lastIndexOf("/"))}/sources/${changesetId}/${file.newPath}/`}
/>;
const jumpToTargetButton = parents?.length === 1 && <JumpToFileButton
tooltip={this.props.t("diff.jumpToTarget")}
link={`${baseUrl.substr(0, baseUrl.lastIndexOf("/"))}/sources/${parents[0].id}/${file.oldPath}/`}
/>;
switch (file.type) {
case "add":
jumpToSource = jumpToSourceButton;
break;
case "delete":
jumpToTarget = jumpToTargetButton;
break;
default:
jumpToSource = jumpToSourceButton;
jumpToTarget = jumpToTargetButton;
}
}
const sideBySideToggle = const sideBySideToggle =
file.hunks && file.hunks.length > 0 ? ( file.hunks && file.hunks.length > 0 && (
<ButtonWrapper className={classNames("level-right", "is-flex")}> <ButtonWrapper className={classNames("level-right", "is-flex")}>
<ButtonGroup> <ButtonGroup>
<MenuContext.Consumer> <MenuContext.Consumer>
{({ setCollapsed }) => ( {({setCollapsed}) => (
<DiffButton <DiffButton
icon={sideBySide ? "align-left" : "columns"} icon={sideBySide ? "align-left" : "columns"}
tooltip={t(sideBySide ? "diff.combined" : "diff.sideBySide")} tooltip={t(sideBySide ? "diff.combined" : "diff.sideBySide")}
@@ -462,15 +435,6 @@ class DiffFile extends React.Component<Props, State> {
)} )}
</MenuContext.Consumer> </MenuContext.Consumer>
{fileControls} {fileControls}
{jumpToSource}
{jumpToTarget}
</ButtonGroup>
</ButtonWrapper>
) : (
<ButtonWrapper className={classNames("level-right", "is-flex")}>
<ButtonGroup>
{jumpToSource}
{jumpToTarget}
</ButtonGroup> </ButtonGroup>
</ButtonWrapper> </ButtonWrapper>
); );
@@ -480,8 +444,8 @@ class DiffFile extends React.Component<Props, State> {
errorModal = ( errorModal = (
<Modal <Modal
title={t("diff.expansionFailed")} title={t("diff.expansionFailed")}
closeFunction={() => this.setState({ expansionError: undefined })} closeFunction={() => this.setState({expansionError: undefined})}
body={<ErrorNotification error={expansionError} />} body={<ErrorNotification error={expansionError}/>}
active={true} active={true}
/> />
); );

View File

@@ -22,25 +22,22 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React from "react";
import { apiClient } from "../apiclient"; import {apiClient} from "../apiclient";
import ErrorNotification from "../ErrorNotification"; import ErrorNotification from "../ErrorNotification";
// @ts-ignore // @ts-ignore
import parser from "gitdiff-parser"; import parser from "gitdiff-parser";
import Loading from "../Loading"; import Loading from "../Loading";
import Diff from "./Diff"; import Diff from "./Diff";
import { DiffObjectProps, File } from "./DiffTypes"; import {DiffObjectProps, File} from "./DiffTypes";
import { NotFoundError } from "../errors"; import {NotFoundError} from "../errors";
import { Notification } from "../index"; import {Notification} from "../index";
import { withTranslation, WithTranslation } from "react-i18next"; import {withTranslation, WithTranslation} from "react-i18next";
import {Changeset} from "@scm-manager/ui-types";
type Props = WithTranslation & type Props = WithTranslation &
DiffObjectProps & { DiffObjectProps & {
url: string; url: string;
changeset: Changeset; };
baseUrl: string;
};
type State = { type State = {
diff?: File[]; diff?: File[];
@@ -71,8 +68,8 @@ class LoadingDiff extends React.Component<Props, State> {
} }
fetchDiff = () => { fetchDiff = () => {
const { url } = this.props; const {url} = this.props;
this.setState({ loading: true }); this.setState({loading: true});
apiClient apiClient
.get(url) .get(url)
.then(response => { .then(response => {
@@ -98,14 +95,14 @@ class LoadingDiff extends React.Component<Props, State> {
}; };
render() { render() {
const { diff, loading, error } = this.state; const {diff, loading, error} = this.state;
if (error) { if (error) {
if (error instanceof NotFoundError) { if (error instanceof NotFoundError) {
return <Notification type="info">{this.props.t("changesets.noChangesets")}</Notification>; return <Notification type="info">{this.props.t("changesets.noChangesets")}</Notification>;
} }
return <ErrorNotification error={error} />; return <ErrorNotification error={error}/>;
} else if (loading) { } else if (loading) {
return <Loading />; return <Loading/>;
} else if (!diff) { } else if (!diff) {
return null; return null;
} else { } else {

View File

@@ -22,15 +22,16 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React from "react";
import { Changeset, Link, Collection } from "@scm-manager/ui-types"; import {Changeset, Collection, Link} from "@scm-manager/ui-types";
import LoadingDiff from "../LoadingDiff"; import LoadingDiff from "../LoadingDiff";
import Notification from "../../Notification"; import Notification from "../../Notification";
import { WithTranslation, withTranslation } from "react-i18next"; import {WithTranslation, withTranslation} from "react-i18next";
import {FileControlFactory} from "../DiffTypes";
type Props = WithTranslation & { type Props = WithTranslation & {
changeset: Changeset; changeset: Changeset;
baseUrl: string;
defaultCollapse?: boolean; defaultCollapse?: boolean;
fileControlFactory?: FileControlFactory;
}; };
export const isDiffSupported = (changeset: Collection) => { export const isDiffSupported = (changeset: Collection) => {
@@ -48,12 +49,12 @@ export const createUrl = (changeset: Collection) => {
class ChangesetDiff extends React.Component<Props> { class ChangesetDiff extends React.Component<Props> {
render() { render() {
const { changeset, baseUrl, defaultCollapse, t } = this.props; const {changeset, fileControlFactory, defaultCollapse, t} = this.props;
if (!isDiffSupported(changeset)) { if (!isDiffSupported(changeset)) {
return <Notification type="danger">{t("changeset.diffNotSupported")}</Notification>; return <Notification type="danger">{t("changeset.diffNotSupported")}</Notification>;
} else { } else {
const url = createUrl(changeset); const url = createUrl(changeset);
return <LoadingDiff url={url} defaultCollapse={defaultCollapse} sideBySide={false} changeset={changeset} baseUrl={baseUrl} />; return <LoadingDiff url={url} defaultCollapse={defaultCollapse} sideBySide={false} fileControlFactory={fileControlFactory}/>;
} }
} }
} }

View File

@@ -35,6 +35,7 @@ import ChangesetAuthor from "./ChangesetAuthor";
import ChangesetTags from "./ChangesetTags"; import ChangesetTags from "./ChangesetTags";
import ChangesetButtonGroup from "./ChangesetButtonGroup"; import ChangesetButtonGroup from "./ChangesetButtonGroup";
import ChangesetDescription from "./ChangesetDescription"; import ChangesetDescription from "./ChangesetDescription";
import {FileControlFactory} from "../DiffTypes";
type Props = WithTranslation & { type Props = WithTranslation & {
repository: Repository; repository: Repository;

View File

@@ -45,11 +45,13 @@ export * from "./changesets";
export { default as Diff } from "./Diff"; export { default as Diff } from "./Diff";
export { default as DiffFile } from "./DiffFile"; export { default as DiffFile } from "./DiffFile";
export { default as DiffButton } from "./DiffButton"; export { default as DiffButton } from "./DiffButton";
export { FileControlFactory } from "./DiffTypes";
export { default as LoadingDiff } from "./LoadingDiff"; export { default as LoadingDiff } from "./LoadingDiff";
export { DefaultCollapsed, DefaultCollapsedFunction } from "./defaultCollapsed"; export { DefaultCollapsed, DefaultCollapsedFunction } from "./defaultCollapsed";
export { default as RepositoryAvatar } from "./RepositoryAvatar"; export { default as RepositoryAvatar } from "./RepositoryAvatar";
export { default as RepositoryEntry } from "./RepositoryEntry"; export { default as RepositoryEntry } from "./RepositoryEntry";
export { default as RepositoryEntryLink } from "./RepositoryEntryLink"; export { default as RepositoryEntryLink } from "./RepositoryEntryLink";
export { default as JumpToFileButton } from "./JumpToFileButton";
export { export {
File, File,

View File

@@ -224,7 +224,7 @@
}, },
"diff": { "diff": {
"jumpToSource": "Zur Quelldatei springen", "jumpToSource": "Zur Quelldatei springen",
"jumpToTarget": "Zur Zieldatei springen", "jumpToTarget": "Zur vorherigen Version der 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

@@ -231,7 +231,7 @@
"copy": "copied" "copy": "copied"
}, },
"jumpToSource": "Jump to source file", "jumpToSource": "Jump to source file",
"jumpToTarget": "Jump to target file", "jumpToTarget": "Jump to the previous version of the 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.",

View File

@@ -43,11 +43,12 @@ import {
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import ContributorTable from "./ContributorTable"; import ContributorTable from "./ContributorTable";
import { Link as ReactLink } from "react-router-dom"; import { Link as ReactLink } from "react-router-dom";
import {FileControlFactory} from "@scm-manager/ui-components";
type Props = WithTranslation & { type Props = WithTranslation & {
changeset: Changeset; changeset: Changeset;
repository: Repository; repository: Repository;
baseUrl: string; fileControlFactory?: FileControlFactory;
}; };
type State = { type State = {
@@ -131,6 +132,7 @@ const Contributors: FC<{ changeset: Changeset }> = ({ changeset }) => {
</ContributorDetails> </ContributorDetails>
); );
} }
return ( return (
<> <>
<ContributorLine onClick={e => setOpen(!open)}> <ContributorLine onClick={e => setOpen(!open)}>
@@ -158,7 +160,7 @@ class ChangesetDetails extends React.Component<Props, State> {
} }
render() { render() {
const { changeset, repository, baseUrl, t } = this.props; const { changeset, repository, fileControlFactory, t } = this.props;
const { collapsed } = this.state; const { collapsed } = this.state;
const description = changesets.parseDescription(changeset.description); const description = changesets.parseDescription(changeset.description);
@@ -239,7 +241,7 @@ class ChangesetDetails extends React.Component<Props, State> {
/> />
} }
/> />
<ChangesetDiff changeset={changeset} baseUrl={baseUrl} defaultCollapse={collapsed} /> <ChangesetDiff changeset={changeset} fileControlFactory={fileControlFactory} defaultCollapse={collapsed} />
</div> </div>
</> </>
); );

View File

@@ -22,12 +22,12 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React from "react";
import { connect } from "react-redux"; import {connect} from "react-redux";
import { compose } from "redux"; import {compose} from "redux";
import { withRouter } from "react-router-dom"; import {withRouter} from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next"; import {WithTranslation, withTranslation} from "react-i18next";
import { Changeset, Repository } from "@scm-manager/ui-types"; import {Changeset, Repository} from "@scm-manager/ui-types";
import { ErrorPage, Loading } from "@scm-manager/ui-components"; import {ErrorPage, Loading} from "@scm-manager/ui-components";
import { import {
fetchChangesetIfNeeded, fetchChangesetIfNeeded,
getChangeset, getChangeset,
@@ -35,12 +35,13 @@ import {
isFetchChangesetPending isFetchChangesetPending
} from "../modules/changesets"; } from "../modules/changesets";
import ChangesetDetails from "../components/changesets/ChangesetDetails"; import ChangesetDetails from "../components/changesets/ChangesetDetails";
import {FileControlFactory} from "@scm-manager/ui-components";
type Props = WithTranslation & { type Props = WithTranslation & {
id: string; id: string;
changeset: Changeset; changeset: Changeset;
repository: Repository; repository: Repository;
baseUrl: string; fileControlFactoryFactory?: (changeset: Changeset) => FileControlFactory;
loading: boolean; loading: boolean;
error: Error; error: Error;
fetchChangesetIfNeeded: (repository: Repository, id: string) => void; fetchChangesetIfNeeded: (repository: Repository, id: string) => void;
@@ -49,27 +50,28 @@ type Props = WithTranslation & {
class ChangesetView extends React.Component<Props> { class ChangesetView extends React.Component<Props> {
componentDidMount() { componentDidMount() {
const { fetchChangesetIfNeeded, repository, id } = this.props; const {fetchChangesetIfNeeded, repository, id} = this.props;
fetchChangesetIfNeeded(repository, id); fetchChangesetIfNeeded(repository, id);
} }
componentDidUpdate(prevProps: Props) { componentDidUpdate(prevProps: Props) {
const { fetchChangesetIfNeeded, repository, id } = this.props; const {fetchChangesetIfNeeded, repository, id} = this.props;
if (prevProps.id !== id) { if (prevProps.id !== id) {
fetchChangesetIfNeeded(repository, id); fetchChangesetIfNeeded(repository, id);
} }
} }
render() { render() {
const { changeset, loading, error, t, repository, baseUrl } = this.props; const {changeset, loading, error, t, repository, fileControlFactoryFactory} = this.props;
if (error) { if (error) {
return <ErrorPage title={t("changesets.errorTitle")} subtitle={t("changesets.errorSubtitle")} error={error} />; return <ErrorPage title={t("changesets.errorTitle")} subtitle={t("changesets.errorSubtitle")} error={error}/>;
} }
if (!changeset || loading) return <Loading />; if (!changeset || loading) return <Loading/>;
return <ChangesetDetails changeset={changeset} repository={repository} baseUrl={baseUrl} />; return <ChangesetDetails changeset={changeset} repository={repository}
fileControlFactory={fileControlFactoryFactory && fileControlFactoryFactory(changeset)}/>;
} }
} }

View File

@@ -22,24 +22,24 @@
* SOFTWARE. * SOFTWARE.
*/ */
import React from "react"; import React from "react";
import { connect } from "react-redux"; import {connect} from "react-redux";
import { Redirect, Route, Switch, RouteComponentProps } from "react-router-dom"; import {Redirect, Route, RouteComponentProps, Switch} from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next"; import {WithTranslation, withTranslation} from "react-i18next";
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions"; import {binder, ExtensionPoint} from "@scm-manager/ui-extensions";
import { Repository } from "@scm-manager/ui-types"; import {Changeset, Repository} from "@scm-manager/ui-types";
import { import {
CustomQueryFlexWrappedColumns,
ErrorPage, ErrorPage,
Loading, Loading,
NavLink, NavLink,
Page, Page,
CustomQueryFlexWrappedColumns,
PrimaryContentColumn, PrimaryContentColumn,
SecondaryNavigationColumn,
SecondaryNavigation, SecondaryNavigation,
SubNavigation, SecondaryNavigationColumn,
StateMenuContextProvider StateMenuContextProvider,
SubNavigation
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import { fetchRepoByName, getFetchRepoFailure, getRepository, isFetchRepoPending } from "../modules/repos"; import {fetchRepoByName, getFetchRepoFailure, getRepository, isFetchRepoPending} from "../modules/repos";
import RepositoryDetails from "../components/RepositoryDetails"; import RepositoryDetails from "../components/RepositoryDetails";
import EditRepo from "./EditRepo"; import EditRepo from "./EditRepo";
import BranchesOverview from "../branches/containers/BranchesOverview"; import BranchesOverview from "../branches/containers/BranchesOverview";
@@ -49,10 +49,11 @@ import EditRepoNavLink from "../components/EditRepoNavLink";
import BranchRoot from "../branches/containers/BranchRoot"; import BranchRoot from "../branches/containers/BranchRoot";
import PermissionsNavLink from "../components/PermissionsNavLink"; import PermissionsNavLink from "../components/PermissionsNavLink";
import RepositoryNavLink from "../components/RepositoryNavLink"; import RepositoryNavLink from "../components/RepositoryNavLink";
import { getLinks, getRepositoriesLink } from "../../modules/indexResource"; import {getLinks, getRepositoriesLink} from "../../modules/indexResource";
import CodeOverview from "../codeSection/containers/CodeOverview"; import CodeOverview from "../codeSection/containers/CodeOverview";
import ChangesetView from "./ChangesetView"; import ChangesetView from "./ChangesetView";
import SourceExtensions from "../sources/containers/SourceExtensions"; import SourceExtensions from "../sources/containers/SourceExtensions";
import {FileControlFactory, JumpToFileButton} from "@scm-manager/ui-components";
type Props = RouteComponentProps & type Props = RouteComponentProps &
WithTranslation & { WithTranslation & {
@@ -66,16 +67,16 @@ type Props = RouteComponentProps &
// dispatch functions // dispatch functions
fetchRepoByName: (link: string, namespace: string, name: string) => void; fetchRepoByName: (link: string, namespace: string, name: string) => void;
}; };
class RepositoryRoot extends React.Component<Props> { class RepositoryRoot extends React.Component<Props> {
componentDidMount() { componentDidMount() {
const { fetchRepoByName, namespace, name, repoLink } = this.props; const {fetchRepoByName, namespace, name, repoLink} = this.props;
fetchRepoByName(repoLink, namespace, name); fetchRepoByName(repoLink, namespace, name);
} }
componentDidUpdate(prevProps: Props) { componentDidUpdate(prevProps: Props) {
const { fetchRepoByName, namespace, name, repoLink } = this.props; const {fetchRepoByName, namespace, name, repoLink} = this.props;
if (namespace !== prevProps.namespace || name !== prevProps.name) { if (namespace !== prevProps.namespace || name !== prevProps.name) {
fetchRepoByName(repoLink, namespace, name); fetchRepoByName(repoLink, namespace, name);
} }
@@ -105,7 +106,7 @@ class RepositoryRoot extends React.Component<Props> {
}; };
getCodeLinkname = () => { getCodeLinkname = () => {
const { repository } = this.props; const {repository} = this.props;
if (repository?._links?.sources) { if (repository?._links?.sources) {
return "sources"; return "sources";
} }
@@ -116,8 +117,8 @@ class RepositoryRoot extends React.Component<Props> {
}; };
evaluateDestinationForCodeLink = () => { evaluateDestinationForCodeLink = () => {
const { repository } = this.props; const {repository} = this.props;
let url = `${this.matchedUrl()}/code`; const url = `${this.matchedUrl()}/code`;
if (repository?._links?.sources) { if (repository?._links?.sources) {
return `${url}/sources/`; return `${url}/sources/`;
} }
@@ -125,16 +126,16 @@ class RepositoryRoot extends React.Component<Props> {
}; };
render() { render() {
const { loading, error, indexLinks, repository, t } = this.props; const {loading, error, indexLinks, repository, t} = this.props;
if (error) { if (error) {
return ( return (
<ErrorPage title={t("repositoryRoot.errorTitle")} subtitle={t("repositoryRoot.errorSubtitle")} error={error} /> <ErrorPage title={t("repositoryRoot.errorTitle")} subtitle={t("repositoryRoot.errorSubtitle")} error={error}/>
); );
} }
if (!repository || loading) { if (!repository || loading) {
return <Loading />; return <Loading/>;
} }
const url = this.matchedUrl(); const url = this.matchedUrl();
@@ -153,66 +154,102 @@ class RepositoryRoot extends React.Component<Props> {
redirectedUrl = url + "/info"; redirectedUrl = url + "/info";
} }
const fileControlFactoryFactory: (changeset: Changeset) => FileControlFactory = (changeset) => (file) => {
const baseUrl = `${url}/code/sources`;
const sourceLink = {
url: `${baseUrl}/${changeset.id}/${file.newPath}/`,
label: t("diff.jumpToSource")
};
const targetLink = changeset._embedded?.parents?.length === 1 && {
url: `${baseUrl}/${changeset._embedded.parents[0].id}/${file.oldPath}`,
label: t("diff.jumpToTarget")
};
const links = [];
switch (file.type) {
case "add":
links.push(sourceLink);
break;
case "delete":
if (targetLink) {
links.push(targetLink);
}
break;
default:
if (targetLink) {
links.push(sourceLink, targetLink);
} else {
links.push(sourceLink);
}
}
return links.map(({url, label}) => <JumpToFileButton
tooltip={label}
link={url}
/>);
};
return ( return (
<StateMenuContextProvider> <StateMenuContextProvider>
<Page <Page
title={repository.namespace + "/" + repository.name} title={repository.namespace + "/" + repository.name}
afterTitle={<ExtensionPoint name={"repository.afterTitle"} props={{ repository }} />} afterTitle={<ExtensionPoint name={"repository.afterTitle"} props={{repository}}/>}
> >
<CustomQueryFlexWrappedColumns> <CustomQueryFlexWrappedColumns>
<PrimaryContentColumn> <PrimaryContentColumn>
<Switch> <Switch>
<Redirect exact from={this.props.match.url} to={redirectedUrl} /> <Redirect exact from={this.props.match.url} to={redirectedUrl}/>
{/* redirect pre 2.0.0-rc2 links */} {/* redirect pre 2.0.0-rc2 links */}
<Redirect from={`${url}/changeset/:id`} to={`${url}/code/changeset/:id`} /> <Redirect from={`${url}/changeset/:id`} to={`${url}/code/changeset/:id`}/>
<Redirect exact from={`${url}/sources`} to={`${url}/code/sources`} /> <Redirect exact from={`${url}/sources`} to={`${url}/code/sources`}/>
<Redirect from={`${url}/sources/:revision/:path*`} to={`${url}/code/sources/:revision/:path*`} /> <Redirect from={`${url}/sources/:revision/:path*`} to={`${url}/code/sources/:revision/:path*`}/>
<Redirect exact from={`${url}/changesets`} to={`${url}/code/changesets`} /> <Redirect exact from={`${url}/changesets`} to={`${url}/code/changesets`}/>
<Redirect from={`${url}/branch/:branch/changesets`} to={`${url}/code/branch/:branch/changesets/`} /> <Redirect from={`${url}/branch/:branch/changesets`} to={`${url}/code/branch/:branch/changesets/`}/>
<Route path={`${url}/info`} exact component={() => <RepositoryDetails repository={repository} />} /> <Route path={`${url}/info`} exact component={() => <RepositoryDetails repository={repository}/>}/>
<Route path={`${url}/settings/general`} component={() => <EditRepo repository={repository} />} /> <Route path={`${url}/settings/general`} component={() => <EditRepo repository={repository}/>}/>
<Route <Route
path={`${url}/settings/permissions`} path={`${url}/settings/permissions`}
render={() => ( render={() => (
<Permissions namespace={this.props.repository.namespace} repoName={this.props.repository.name} /> <Permissions namespace={this.props.repository.namespace} repoName={this.props.repository.name}/>
)} )}
/> />
<Route <Route
exact exact
path={`${url}/code/changeset/:id`} path={`${url}/code/changeset/:id`}
render={() => <ChangesetView repository={repository} baseUrl={`${url}/code/changeset`} />} render={() => <ChangesetView repository={repository}
fileControlFactoryFactory={fileControlFactoryFactory}/>}
/> />
<Route <Route
path={`${url}/code/sourceext/:extension`} path={`${url}/code/sourceext/:extension`}
exact={true} exact={true}
render={() => <SourceExtensions repository={repository} />} render={() => <SourceExtensions repository={repository}/>}
/> />
<Route <Route
path={`${url}/code/sourceext/:extension/:revision/:path*`} path={`${url}/code/sourceext/:extension/:revision/:path*`}
render={() => <SourceExtensions repository={repository} baseUrl={`${url}/code/sources`} />} render={() => <SourceExtensions repository={repository} baseUrl={`${url}/code/sources`}/>}
/> />
<Route <Route
path={`${url}/code`} path={`${url}/code`}
render={() => <CodeOverview baseUrl={`${url}/code`} repository={repository} />} render={() => <CodeOverview baseUrl={`${url}/code`} repository={repository}/>}
/> />
<Route <Route
path={`${url}/branch/:branch`} path={`${url}/branch/:branch`}
render={() => <BranchRoot repository={repository} baseUrl={`${url}/branch`} />} render={() => <BranchRoot repository={repository} baseUrl={`${url}/branch`}/>}
/> />
<Route <Route
path={`${url}/branches`} path={`${url}/branches`}
exact={true} exact={true}
render={() => <BranchesOverview repository={repository} baseUrl={`${url}/branch`} />} render={() => <BranchesOverview repository={repository} baseUrl={`${url}/branch`}/>}
/> />
<Route path={`${url}/branches/create`} render={() => <CreateBranch repository={repository} />} /> <Route path={`${url}/branches/create`} render={() => <CreateBranch repository={repository}/>}/>
<ExtensionPoint name="repository.route" props={extensionProps} renderAll={true} /> <ExtensionPoint name="repository.route" props={extensionProps} renderAll={true}/>
</Switch> </Switch>
</PrimaryContentColumn> </PrimaryContentColumn>
<SecondaryNavigationColumn> <SecondaryNavigationColumn>
<SecondaryNavigation label={t("repositoryRoot.menu.navigationLabel")}> <SecondaryNavigation label={t("repositoryRoot.menu.navigationLabel")}>
<ExtensionPoint name="repository.navigation.topLevel" props={extensionProps} renderAll={true} /> <ExtensionPoint name="repository.navigation.topLevel" props={extensionProps} renderAll={true}/>
<NavLink <NavLink
to={`${url}/info`} to={`${url}/info`}
icon="fas fa-info-circle" icon="fas fa-info-circle"
@@ -239,15 +276,15 @@ class RepositoryRoot extends React.Component<Props> {
activeOnlyWhenExact={false} activeOnlyWhenExact={false}
title={t("repositoryRoot.menu.sourcesNavLink")} title={t("repositoryRoot.menu.sourcesNavLink")}
/> />
<ExtensionPoint name="repository.navigation" props={extensionProps} renderAll={true} /> <ExtensionPoint name="repository.navigation" props={extensionProps} renderAll={true}/>
<SubNavigation <SubNavigation
to={`${url}/settings/general`} to={`${url}/settings/general`}
label={t("repositoryRoot.menu.settingsNavLink")} label={t("repositoryRoot.menu.settingsNavLink")}
title={t("repositoryRoot.menu.settingsNavLink")} title={t("repositoryRoot.menu.settingsNavLink")}
> >
<EditRepoNavLink repository={repository} editUrl={`${url}/settings/general`} /> <EditRepoNavLink repository={repository} editUrl={`${url}/settings/general`}/>
<PermissionsNavLink permissionUrl={`${url}/settings/permissions`} repository={repository} /> <PermissionsNavLink permissionUrl={`${url}/settings/permissions`} repository={repository}/>
<ExtensionPoint name="repository.setting" props={extensionProps} renderAll={true} /> <ExtensionPoint name="repository.setting" props={extensionProps} renderAll={true}/>
</SubNavigation> </SubNavigation>
</SecondaryNavigation> </SecondaryNavigation>
</SecondaryNavigationColumn> </SecondaryNavigationColumn>
@@ -259,7 +296,7 @@ class RepositoryRoot extends React.Component<Props> {
} }
const mapStateToProps = (state: any, ownProps: Props) => { const mapStateToProps = (state: any, ownProps: Props) => {
const { namespace, name } = ownProps.match.params; const {namespace, name} = ownProps.match.params;
const repository = getRepository(state, namespace, name); const repository = getRepository(state, namespace, name);
const loading = isFetchRepoPending(state, namespace, name); const loading = isFetchRepoPending(state, namespace, name);
const error = getFetchRepoFailure(state, namespace, name); const error = getFetchRepoFailure(state, namespace, name);