mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
get selectedBranch in state for ExtensionPoint / if no branch is selected use defaultBranch for ExtensionPoint
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import type { Branch } from "@scm-manager/ui-types";
|
||||
import injectSheet from "react-jss";
|
||||
import { ExtensionPoint, binder } from "@scm-manager/ui-extensions";
|
||||
import {ButtonGroup} from "./buttons";
|
||||
import classNames from "classnames";
|
||||
|
||||
type Props = {
|
||||
branch: Branch,
|
||||
defaultBranch: Branch,
|
||||
revision: string,
|
||||
path: string,
|
||||
baseUrl: string,
|
||||
branch: string,
|
||||
classes: any
|
||||
};
|
||||
|
||||
@@ -60,7 +62,7 @@ class Breadcrumb extends React.Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { classes, baseUrl, revision, path } = this.props;
|
||||
const { classes, baseUrl, branch, defaultBranch, path } = this.props;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -74,7 +76,7 @@ class Breadcrumb extends React.Component<Props> {
|
||||
<ButtonGroup>
|
||||
<ExtensionPoint
|
||||
name="sourceView.actionbar.right"
|
||||
props={{ baseUrl, revision, path }}
|
||||
props={{ baseUrl, branch: branch ? branch : defaultBranch, path }}
|
||||
renderAll={true}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
|
||||
@@ -36,7 +36,19 @@ type Props = {
|
||||
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() {
|
||||
const {
|
||||
fetchBranches,
|
||||
@@ -60,12 +72,14 @@ class Sources extends React.Component<Props> {
|
||||
const { baseUrl, history, path } = this.props;
|
||||
let url;
|
||||
if (branch) {
|
||||
this.setState({selectedBranch: branch});
|
||||
if (path) {
|
||||
url = `${baseUrl}/${encodeURIComponent(branch.name)}/${path}`;
|
||||
} else {
|
||||
url = `${baseUrl}/${encodeURIComponent(branch.name)}/`;
|
||||
}
|
||||
} else {
|
||||
this.setState({selectedBranch: null});
|
||||
url = `${baseUrl}/`;
|
||||
}
|
||||
history.push(url);
|
||||
@@ -75,6 +89,7 @@ class Sources extends React.Component<Props> {
|
||||
const {
|
||||
repository,
|
||||
baseUrl,
|
||||
branches,
|
||||
loading,
|
||||
error,
|
||||
revision,
|
||||
@@ -82,6 +97,8 @@ class Sources extends React.Component<Props> {
|
||||
currentFileIsDirectory
|
||||
} = this.props;
|
||||
|
||||
const {selectedBranch} = this.state;
|
||||
|
||||
if (error) {
|
||||
return <ErrorNotification error={error} />;
|
||||
}
|
||||
@@ -94,7 +111,15 @@ class Sources extends React.Component<Props> {
|
||||
return (
|
||||
<div className="panel">
|
||||
{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
|
||||
repository={repository}
|
||||
revision={revision}
|
||||
|
||||
Reference in New Issue
Block a user