2018-08-21 15:37:45 +02:00
|
|
|
//@flow
|
|
|
|
|
import React from "react";
|
2018-08-23 10:16:54 +02:00
|
|
|
import connect from "react-redux/es/connect/connect";
|
|
|
|
|
import { translate } from "react-i18next";
|
2018-08-23 11:00:14 +02:00
|
|
|
import {
|
|
|
|
|
fetchPermissions,
|
|
|
|
|
getFetchPermissionsFailure,
|
|
|
|
|
isFetchPermissionsPending,
|
|
|
|
|
getPermissionsOfRepo
|
|
|
|
|
} from "../modules/permissions";
|
|
|
|
|
import Loading from "../../components/Loading";
|
|
|
|
|
import ErrorPage from "../../components/ErrorPage";
|
2018-08-23 11:49:10 +02:00
|
|
|
import type { PermissionCollection } from "../types/Permissions";
|
2018-08-23 15:39:09 +02:00
|
|
|
import PermissionsTable from "./PermissionsTable";
|
2018-08-21 15:37:45 +02:00
|
|
|
|
2018-08-23 10:16:54 +02:00
|
|
|
type Props = {
|
|
|
|
|
namespace: string,
|
|
|
|
|
name: string,
|
2018-08-23 11:00:14 +02:00
|
|
|
loading: boolean,
|
|
|
|
|
error: Error,
|
2018-08-23 11:11:40 +02:00
|
|
|
permissions: PermissionCollection,
|
2018-08-23 10:16:54 +02:00
|
|
|
|
|
|
|
|
//dispatch functions
|
2018-08-23 11:00:14 +02:00
|
|
|
fetchPermissions: (namespace: string, name: string) => void,
|
|
|
|
|
|
|
|
|
|
// context props
|
|
|
|
|
t: string => string,
|
|
|
|
|
match: any
|
2018-08-23 10:16:54 +02:00
|
|
|
};
|
2018-08-21 15:37:45 +02:00
|
|
|
|
|
|
|
|
class Permissions extends React.Component<Props> {
|
2018-08-23 10:16:54 +02:00
|
|
|
componentDidMount() {
|
|
|
|
|
const { fetchPermissions, namespace, name } = this.props;
|
|
|
|
|
|
|
|
|
|
fetchPermissions(namespace, name);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-21 15:37:45 +02:00
|
|
|
render() {
|
2018-08-23 15:39:09 +02:00
|
|
|
const { loading, error, permissions, t, namespace, name } = this.props;
|
2018-08-23 11:00:14 +02:00
|
|
|
if (error) {
|
|
|
|
|
return (
|
|
|
|
|
<ErrorPage
|
|
|
|
|
title={t("permissions.error-title")}
|
|
|
|
|
subtitle={t("permissions.error-subtitle")}
|
|
|
|
|
error={error}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (loading || !permissions) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 11:49:10 +02:00
|
|
|
if (permissions.length > 0)
|
2018-08-23 15:39:09 +02:00
|
|
|
return <PermissionsTable permissions={permissions} namespace={namespace} name={name} />;
|
2018-08-23 11:49:10 +02:00
|
|
|
|
|
|
|
|
return <div />;
|
2018-08-21 15:37:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 10:16:54 +02:00
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2018-08-23 11:00:14 +02:00
|
|
|
const namespace = ownProps.namespace;
|
|
|
|
|
const name = ownProps.name;
|
2018-08-23 12:25:00 +02:00
|
|
|
const error = getFetchPermissionsFailure(state, namespace, name);
|
|
|
|
|
const loading = isFetchPermissionsPending(state, namespace, name);
|
2018-08-23 11:00:14 +02:00
|
|
|
const permissions = getPermissionsOfRepo(state, namespace, name);
|
2018-08-23 10:16:54 +02:00
|
|
|
return {
|
2018-08-23 11:00:14 +02:00
|
|
|
namespace,
|
|
|
|
|
name,
|
|
|
|
|
error,
|
|
|
|
|
loading,
|
|
|
|
|
permissions
|
2018-08-23 10:16:54 +02:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
|
return {
|
|
|
|
|
fetchPermissions: (namespace: string, name: string) => {
|
|
|
|
|
dispatch(fetchPermissions(namespace, name));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps
|
2018-08-23 11:00:14 +02:00
|
|
|
)(translate("permissions")(Permissions));
|