mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
//@flow
|
|
import React from "react";
|
|
import connect from "react-redux/es/connect/connect";
|
|
import { translate } from "react-i18next";
|
|
import {
|
|
fetchPermissions,
|
|
getFetchPermissionsFailure,
|
|
isFetchPermissionsPending,
|
|
getPermissionsOfRepo
|
|
} from "../modules/permissions";
|
|
import Loading from "../../components/Loading";
|
|
import ErrorPage from "../../components/ErrorPage";
|
|
import type {PermissionCollection} from "../types/Permissions";
|
|
|
|
type Props = {
|
|
namespace: string,
|
|
name: string,
|
|
loading: boolean,
|
|
error: Error,
|
|
permissions: PermissionCollection,
|
|
|
|
//dispatch functions
|
|
fetchPermissions: (namespace: string, name: string) => void,
|
|
|
|
// context props
|
|
t: string => string,
|
|
match: any
|
|
};
|
|
|
|
class Permissions extends React.Component<Props> {
|
|
componentDidMount() {
|
|
const { fetchPermissions, namespace, name } = this.props;
|
|
|
|
fetchPermissions(namespace, name);
|
|
}
|
|
|
|
render() {
|
|
const { namespace, name, loading, error, permissions, t } = this.props;
|
|
|
|
if (error) {
|
|
return (
|
|
<ErrorPage
|
|
title={t("permissions.error-title")}
|
|
subtitle={t("permissions.error-subtitle")}
|
|
error={error}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (loading || !permissions) {
|
|
return <Loading />;
|
|
}
|
|
|
|
return <div>Permissions will be shown here!</div>;
|
|
}
|
|
}
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
const namespace = ownProps.namespace;
|
|
const name = ownProps.name;
|
|
const error = getFetchPermissionsFailure(state);
|
|
const loading = isFetchPermissionsPending(state);
|
|
const permissions = getPermissionsOfRepo(state, namespace, name);
|
|
return {
|
|
namespace,
|
|
name,
|
|
error,
|
|
loading,
|
|
permissions
|
|
};
|
|
};
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
return {
|
|
fetchPermissions: (namespace: string, name: string) => {
|
|
dispatch(fetchPermissions(namespace, name));
|
|
}
|
|
};
|
|
};
|
|
|
|
export default connect(
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
)(translate("permissions")(Permissions));
|