// @flow import React from "react"; import { withRouter } from "react-router-dom"; import { binder } from "@scm-manager/ui-extensions"; import { ProtectedRoute, apiClient, ErrorNotification, ErrorBoundary } from "@scm-manager/ui-components"; import DummyComponent from "./DummyComponent"; type Props = { authenticated?: boolean, //context objects history: History }; type State = { error?: Error }; class LegacyRepositoryRedirect extends React.Component { constructor(props: Props, state: State) { super(props, state); this.state = { error: null }; } handleError = (error: Error) => { this.setState({ error }); }; redirectLegacyRepository() { const { history } = this.props; if (location.href && location.href.includes("#diffPanel;")) { let splittedUrl = location.href.split(";"); let repoId = splittedUrl[1]; let changeSetId = splittedUrl[2]; apiClient .get("/legacy/repository/" + repoId) .then(response => response.json()) .then(payload => history.push( "/repo/" + payload.namespace + "/" + payload.name + "/changesets/" + changeSetId ) ) .catch(this.handleError); } } render() { const { authenticated } = this.props; const { error } = this.state; if (error) { return (
); } return ( <> {authenticated ? ( this.redirectLegacyRepository() ) : ( )} ); } } binder.bind("legacy.redirectRepository", withRouter(LegacyRepositoryRedirect));