mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
move redirect logic to legacy plugin / bind Extensionpoint in Main.js
This commit is contained in:
55
scm-plugins/scm-legacy-plugin/src/main/js/index.js
Normal file
55
scm-plugins/scm-legacy-plugin/src/main/js/index.js
Normal 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));
|
||||
|
||||
Reference in New Issue
Block a user