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,20 @@
{
"name": "@scm-manager/legacy-plugin",
"license": "BSD-3-Clause",
"main": "src/main/js/index.js",
"scripts": {
"build": "ui-bundler plugin",
"watch": "ui-bundler plugin -w",
"lint": "ui-bundler lint",
"flow": "flow check"
},
"dependencies": {
"@scm-manager/ui-components": "latest",
"@scm-manager/ui-extensions": "^0.1.1",
"react-redux": "^5.0.7",
"@scm-manager/ui-types": "latest"
},
"devDependencies": {
"@scm-manager/ui-bundler": "^0.0.25"
}
}

View File

@@ -0,0 +1,15 @@
//@flow
import React from "react";
import { withRouter } from "react-router-dom";
class DummyComponent extends React.Component<Props, State> {
render() {
return (
<>
</>
);
}
}
export default withRouter(DummyComponent);

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));

View File

@@ -38,15 +38,6 @@ class Main extends React.Component<Props> {
const { authenticated, links } = this.props; const { authenticated, links } = this.props;
const redirectUrlFactory = binder.getExtension("main.redirect", this.props); const redirectUrlFactory = binder.getExtension("main.redirect", this.props);
let url = "/repos"; let url = "/repos";
if (location.href && location.href.includes("#diffPanel;")) {
let repoId = location.href.substring(location.href.search("#diffPanel;") + 11, location.href.search("#diffPanel;") + 21);
console.log("RepoId:");
console.log(repoId);
apiClient.get("/legacy/repository/" + repoId).then(response =>
console.log(JSON.parse(response))
// this.props.history.push("/repo/" + response.responseBody.namespace + "/" + response.responseBody.name)
);
}
if (redirectUrlFactory) { if (redirectUrlFactory) {
url = redirectUrlFactory(this.props); url = redirectUrlFactory(this.props);
} }
@@ -134,7 +125,11 @@ class Main extends React.Component<Props> {
component={Profile} component={Profile}
authenticated={authenticated} authenticated={authenticated}
/> />
<ExtensionPoint
name="legacyRepository.redirect"
renderAll={true}
props={{ authenticated }}
/>
<ExtensionPoint <ExtensionPoint
name="main.route" name="main.route"
renderAll={true} renderAll={true}