get selectedBranch in state for ExtensionPoint / if no branch is selected use defaultBranch for ExtensionPoint

This commit is contained in:
Eduard Heimbuch
2019-09-02 11:48:53 +02:00
parent f769248164
commit 6d7be86e59
2 changed files with 32 additions and 5 deletions

View File

@@ -1,16 +1,18 @@
//@flow //@flow
import React from "react"; import React from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import type { Branch } from "@scm-manager/ui-types";
import injectSheet from "react-jss"; import injectSheet from "react-jss";
import { ExtensionPoint, binder } from "@scm-manager/ui-extensions"; import { ExtensionPoint, binder } from "@scm-manager/ui-extensions";
import {ButtonGroup} from "./buttons"; import {ButtonGroup} from "./buttons";
import classNames from "classnames"; import classNames from "classnames";
type Props = { type Props = {
branch: Branch,
defaultBranch: Branch,
revision: string, revision: string,
path: string, path: string,
baseUrl: string, baseUrl: string,
branch: string,
classes: any classes: any
}; };
@@ -60,7 +62,7 @@ class Breadcrumb extends React.Component<Props> {
} }
render() { render() {
const { classes, baseUrl, revision, path } = this.props; const { classes, baseUrl, branch, defaultBranch, path } = this.props;
return ( return (
<> <>
@@ -74,7 +76,7 @@ class Breadcrumb extends React.Component<Props> {
<ButtonGroup> <ButtonGroup>
<ExtensionPoint <ExtensionPoint
name="sourceView.actionbar.right" name="sourceView.actionbar.right"
props={{ baseUrl, revision, path }} props={{ baseUrl, branch: branch ? branch : defaultBranch, path }}
renderAll={true} renderAll={true}
/> />
</ButtonGroup> </ButtonGroup>

View File

@@ -36,7 +36,19 @@ type Props = {
t: string => string t: string => string
}; };
class Sources extends React.Component<Props> { type State = {
selectedBranch: any
};
class Sources extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
selectedBranch: null
};
}
componentDidMount() { componentDidMount() {
const { const {
fetchBranches, fetchBranches,
@@ -60,12 +72,14 @@ class Sources extends React.Component<Props> {
const { baseUrl, history, path } = this.props; const { baseUrl, history, path } = this.props;
let url; let url;
if (branch) { if (branch) {
this.setState({selectedBranch: branch});
if (path) { if (path) {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/${path}`; url = `${baseUrl}/${encodeURIComponent(branch.name)}/${path}`;
} else { } else {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/`; url = `${baseUrl}/${encodeURIComponent(branch.name)}/`;
} }
} else { } else {
this.setState({selectedBranch: null});
url = `${baseUrl}/`; url = `${baseUrl}/`;
} }
history.push(url); history.push(url);
@@ -75,6 +89,7 @@ class Sources extends React.Component<Props> {
const { const {
repository, repository,
baseUrl, baseUrl,
branches,
loading, loading,
error, error,
revision, revision,
@@ -82,6 +97,8 @@ class Sources extends React.Component<Props> {
currentFileIsDirectory currentFileIsDirectory
} = this.props; } = this.props;
const {selectedBranch} = this.state;
if (error) { if (error) {
return <ErrorNotification error={error} />; return <ErrorNotification error={error} />;
} }
@@ -94,7 +111,15 @@ class Sources extends React.Component<Props> {
return ( return (
<div className="panel"> <div className="panel">
{this.renderBranchSelector()} {this.renderBranchSelector()}
<Breadcrumb revision={encodeURIComponent(revision)} path={path} baseUrl={baseUrl} /> <Breadcrumb
revision={encodeURIComponent(revision)}
path={path}
baseUrl={baseUrl}
branch={selectedBranch}
defaultBranch={
branches && branches.filter(b => b.defaultBranch === true)[0]
}
/>
<FileTree <FileTree
repository={repository} repository={repository}
revision={revision} revision={revision}