move redirect logic to legacy plugin / bind Extensionpoint in Main.js

This commit is contained in:
Eduard Heimbuch
2019-07-04 12:13:45 +02:00
parent 7211d657f2
commit 4f1ac2af09
4 changed files with 95 additions and 10 deletions

View File

@@ -0,0 +1,55 @@
// @flow
import React from "react";
import { withRouter } from "react-router-dom";
import { binder } from "@scm-manager/ui-extensions";
import { ProtectedRoute, apiClient } from "@scm-manager/ui-components";
import DummyComponent from "./DummyComponent";
type Props = {
authenticated?: boolean,
//context objects
history: History
};
class LegacyRepositoryRedirect extends React.Component<Props> {
constructor(props: Props) {
super(props);
}
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)
);
}
}
render() {
const { authenticated } = this.props;
return (
<>
{
authenticated?
this.redirectLegacyRepository():
<ProtectedRoute
path="/index.html"
component={DummyComponent}
authenticated={authenticated}
/>
}
</>
);
}
}
binder.bind("legacyRepository.redirect", withRouter(LegacyRepositoryRedirect));