2018-08-01 18:23:16 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2018-08-03 09:34:39 +02:00
|
|
|
import {
|
|
|
|
|
fetchRepo,
|
|
|
|
|
getFetchRepoFailure,
|
|
|
|
|
getRepository,
|
|
|
|
|
isFetchRepoPending
|
|
|
|
|
} from "../modules/repos";
|
2018-08-01 18:23:16 +02:00
|
|
|
import { connect } from "react-redux";
|
2018-08-03 09:34:39 +02:00
|
|
|
import { Route } from "react-router-dom";
|
|
|
|
|
import type { Repository } from "../types/Repositories";
|
|
|
|
|
import { Page } from "../../components/layout";
|
|
|
|
|
import Loading from "../../components/Loading";
|
|
|
|
|
import ErrorPage from "../../components/ErrorPage";
|
2018-08-01 18:23:16 +02:00
|
|
|
import { translate } from "react-i18next";
|
2018-08-03 09:34:39 +02:00
|
|
|
import { Navigation, NavLink, Section } from "../../components/navigation";
|
|
|
|
|
import RepositoryDetails from "../components/RepositoryDetails";
|
2018-08-01 18:23:16 +02:00
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
namespace: string,
|
|
|
|
|
name: string,
|
|
|
|
|
repository: Repository,
|
|
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
|
|
|
|
|
|
|
|
|
// dispatch functions
|
|
|
|
|
fetchRepo: (namespace: string, name: string) => void,
|
|
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
t: string => string,
|
|
|
|
|
match: any
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RepositoryRoot extends React.Component<Props> {
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
const { fetchRepo, namespace, name } = this.props;
|
|
|
|
|
|
|
|
|
|
fetchRepo(namespace, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stripEndingSlash = (url: string) => {
|
|
|
|
|
if (url.endsWith("/")) {
|
|
|
|
|
return url.substring(0, url.length - 2);
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
matchedUrl = () => {
|
|
|
|
|
return this.stripEndingSlash(this.props.match.url);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
const { loading, error, repository, t } = this.props;
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
|
|
|
|
title={t("repository-root.error-title")}
|
|
|
|
|
subtitle={t("repository-root.error-subtitle")}
|
|
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!repository || loading) {
|
2018-08-03 09:34:39 +02:00
|
|
|
return <Loading />;
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const url = this.matchedUrl();
|
|
|
|
|
|
2018-08-03 09:34:39 +02:00
|
|
|
return (
|
|
|
|
|
<Page title={repository.namespace + "/" + repository.name}>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column is-three-quarters">
|
|
|
|
|
<Route
|
|
|
|
|
path={url}
|
|
|
|
|
exact
|
|
|
|
|
component={() => <RepositoryDetails repository={repository} />}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Navigation>
|
|
|
|
|
<Section label={t("repository-root.actions-label")}>
|
|
|
|
|
<NavLink to="/repos" label={t("repository-root.back-label")} />
|
|
|
|
|
</Section>
|
|
|
|
|
</Navigation>
|
|
|
|
|
</div>
|
2018-08-01 18:23:16 +02:00
|
|
|
</div>
|
2018-08-03 09:34:39 +02:00
|
|
|
</Page>
|
|
|
|
|
);
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
const { namespace, name } = ownProps.match.params;
|
|
|
|
|
const repository = getRepository(state, namespace, name);
|
|
|
|
|
const loading = isFetchRepoPending(state, namespace, name);
|
|
|
|
|
const error = getFetchRepoFailure(state, namespace, name);
|
|
|
|
|
return {
|
|
|
|
|
namespace,
|
|
|
|
|
name,
|
|
|
|
|
repository,
|
|
|
|
|
loading,
|
|
|
|
|
error
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
2018-08-03 09:34:39 +02:00
|
|
|
fetchRepo: (namespace: string, name: string) => {
|
|
|
|
|
dispatch(fetchRepo(namespace, name));
|
2018-08-01 18:23:16 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
|
|
|
|
)(translate("repos")(RepositoryRoot));
|