mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +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
|
//@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>
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
Reference in New Issue
Block a user