2019-07-04 12:13:45 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { withRouter } from "react-router-dom";
|
|
|
|
|
import { binder } from "@scm-manager/ui-extensions";
|
2019-07-05 10:08:27 +02:00
|
|
|
import {
|
|
|
|
|
ProtectedRoute,
|
|
|
|
|
apiClient,
|
|
|
|
|
ErrorNotification,
|
|
|
|
|
ErrorBoundary
|
|
|
|
|
} from "@scm-manager/ui-components";
|
2019-07-04 12:13:45 +02:00
|
|
|
import DummyComponent from "./DummyComponent";
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
authenticated?: boolean,
|
|
|
|
|
|
|
|
|
|
//context objects
|
|
|
|
|
history: History
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-05 10:08:27 +02:00
|
|
|
type State = {
|
|
|
|
|
error?: Error
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class LegacyRepositoryRedirect extends React.Component<Props, State> {
|
|
|
|
|
constructor(props: Props, state: State) {
|
|
|
|
|
super(props, state);
|
|
|
|
|
this.state = { error: null };
|
2019-07-04 12:13:45 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 10:08:27 +02:00
|
|
|
handleError = (error: Error) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
error
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-04 12:13:45 +02:00
|
|
|
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];
|
|
|
|
|
|
2019-07-05 10:08:27 +02:00
|
|
|
apiClient
|
|
|
|
|
.get("/legacy/repository/" + repoId)
|
2019-07-04 12:13:45 +02:00
|
|
|
.then(response => response.json())
|
2019-07-05 10:08:27 +02:00
|
|
|
.then(payload =>
|
|
|
|
|
history.push(
|
|
|
|
|
"/repo/" +
|
|
|
|
|
payload.namespace +
|
|
|
|
|
"/" +
|
|
|
|
|
payload.name +
|
|
|
|
|
"/changesets/" +
|
|
|
|
|
changeSetId
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.catch(this.handleError);
|
2019-07-04 12:13:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { authenticated } = this.props;
|
2019-07-05 10:08:27 +02:00
|
|
|
const { error } = this.state;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<section className="section">
|
|
|
|
|
<div className="container">
|
|
|
|
|
<ErrorBoundary>
|
|
|
|
|
<ErrorNotification error={error} />
|
|
|
|
|
</ErrorBoundary>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-07-04 12:13:45 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2019-07-05 10:08:27 +02:00
|
|
|
{authenticated ? (
|
|
|
|
|
this.redirectLegacyRepository()
|
|
|
|
|
) : (
|
|
|
|
|
<ProtectedRoute
|
|
|
|
|
path="/index.html"
|
|
|
|
|
component={DummyComponent}
|
|
|
|
|
authenticated={authenticated}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2019-07-04 12:13:45 +02:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-05 10:08:27 +02:00
|
|
|
binder.bind("legacy.redirectRepository", withRouter(LegacyRepositoryRedirect));
|