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:
20
scm-plugins/scm-legacy-plugin/package.json
Normal file
20
scm-plugins/scm-legacy-plugin/package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
15
scm-plugins/scm-legacy-plugin/src/main/js/DummyComponent.js
Normal file
15
scm-plugins/scm-legacy-plugin/src/main/js/DummyComponent.js
Normal 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);
|
||||||
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));
|
||||||
|
|
||||||
@@ -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}
|
||||||
|
|||||||
Reference in New Issue
Block a user