fix redirect

This commit is contained in:
Eduard Heimbuch
2019-09-04 15:06:04 +02:00
parent eecba7c163
commit a95cd9c416
2 changed files with 17 additions and 20 deletions

View File

@@ -61,44 +61,36 @@ class Sources extends React.Component<Props, State> {
repository,
revision,
path,
branches,
baseUrl,
fetchSources
} = this.props;
fetchBranches(repository);
fetchSources(repository, revision, path);
if (this.shouldRedirect()) {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 0)
this.setState({ selectedBranch: defaultBranches[0] });
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
}
this.redirectToDefaultBranch();
}
componentDidUpdate(prevProps) {
const {
fetchSources,
repository,
revision,
path,
branches,
baseUrl
} = this.props;
const { fetchSources, repository, revision, path } = this.props;
if (prevProps.revision !== revision || prevProps.path !== path) {
fetchSources(repository, revision, path);
}
this.redirectToDefaultBranch();
}
redirectToDefaultBranch = () => {
const { branches, baseUrl } = this.props;
if (this.shouldRedirect()) {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 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 = () => {
const { branches, location } = this.props;