mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 14:35:45 +01:00
fix redirect
This commit is contained in:
@@ -77,7 +77,12 @@ class Breadcrumb extends React.Component<Props> {
|
|||||||
<ButtonGroup>
|
<ButtonGroup>
|
||||||
<ExtensionPoint
|
<ExtensionPoint
|
||||||
name="repos.sources.actionbar"
|
name="repos.sources.actionbar"
|
||||||
props={{ baseUrl, branch: branch ? branch : defaultBranch, path, isBranchUrl: branches && branches.filter(b => b.name === revision).length > 0 }}
|
props={{
|
||||||
|
baseUrl,
|
||||||
|
branch: branch ? branch : defaultBranch,
|
||||||
|
path,
|
||||||
|
isBranchUrl: branches &&
|
||||||
|
branches.filter(b => b.name.replace("/", "%2F") === revision).length > 0 }}
|
||||||
renderAll={true}
|
renderAll={true}
|
||||||
/>
|
/>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
|||||||
@@ -61,44 +61,36 @@ class Sources extends React.Component<Props, State> {
|
|||||||
repository,
|
repository,
|
||||||
revision,
|
revision,
|
||||||
path,
|
path,
|
||||||
branches,
|
|
||||||
baseUrl,
|
|
||||||
fetchSources
|
fetchSources
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
fetchBranches(repository);
|
fetchBranches(repository);
|
||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, revision, path);
|
||||||
|
|
||||||
if (this.shouldRedirect()) {
|
this.redirectToDefaultBranch();
|
||||||
const defaultBranches = branches.filter(b => b.defaultBranch);
|
|
||||||
|
|
||||||
if (defaultBranches.length > 0)
|
|
||||||
this.setState({ selectedBranch: defaultBranches[0] });
|
|
||||||
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidUpdate(prevProps) {
|
componentDidUpdate(prevProps) {
|
||||||
const {
|
const { fetchSources, repository, revision, path } = this.props;
|
||||||
fetchSources,
|
|
||||||
repository,
|
|
||||||
revision,
|
|
||||||
path,
|
|
||||||
branches,
|
|
||||||
baseUrl
|
|
||||||
} = this.props;
|
|
||||||
if (prevProps.revision !== revision || prevProps.path !== path) {
|
if (prevProps.revision !== revision || prevProps.path !== path) {
|
||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, revision, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.redirectToDefaultBranch();
|
||||||
|
}
|
||||||
|
|
||||||
|
redirectToDefaultBranch = () => {
|
||||||
|
const { branches, baseUrl } = this.props;
|
||||||
if (this.shouldRedirect()) {
|
if (this.shouldRedirect()) {
|
||||||
const defaultBranches = branches.filter(b => b.defaultBranch);
|
const defaultBranches = branches.filter(b => b.defaultBranch);
|
||||||
|
|
||||||
if (defaultBranches.length > 0)
|
if (defaultBranches.length > 0)
|
||||||
this.setState({ selectedBranch: defaultBranches[0] });
|
this.setState({ selectedBranch: defaultBranches[0] });
|
||||||
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
|
this.props.history.push(
|
||||||
|
`${baseUrl}/${defaultBranches[0].name.replace("/", "%2F")}/`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
shouldRedirect = () => {
|
shouldRedirect = () => {
|
||||||
const { branches, location } = this.props;
|
const { branches, location } = this.props;
|
||||||
|
|||||||
Reference in New Issue
Block a user