mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
safe state in props and show loading and error state
This commit is contained in:
@@ -2,14 +2,30 @@
|
||||
import React from "react";
|
||||
import connect from "react-redux/es/connect/connect";
|
||||
import { translate } from "react-i18next";
|
||||
import { fetchPermissions } from "../modules/permissions";
|
||||
import {
|
||||
fetchPermissions,
|
||||
getFetchPermissionsFailure,
|
||||
isFetchPermissionsPending,
|
||||
getPermissionsOfRepo
|
||||
} from "../modules/permissions";
|
||||
import type { History } from "history";
|
||||
import Loading from "../../components/Loading";
|
||||
import ErrorPage from "../../components/ErrorPage";
|
||||
|
||||
type Props = {
|
||||
namespace: string,
|
||||
name: string,
|
||||
loading: boolean,
|
||||
error: Error,
|
||||
permissions: Permissions,
|
||||
|
||||
//dispatch functions
|
||||
fetchPermissions: (namespace: string, name: string) => void
|
||||
fetchPermissions: (namespace: string, name: string) => void,
|
||||
|
||||
// context props
|
||||
t: string => string,
|
||||
history: History,
|
||||
match: any
|
||||
};
|
||||
|
||||
class Permissions extends React.Component<Props> {
|
||||
@@ -20,15 +36,38 @@ class Permissions extends React.Component<Props> {
|
||||
}
|
||||
|
||||
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, name } = ownProps.match.params;
|
||||
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
|
||||
namespace,
|
||||
name,
|
||||
error,
|
||||
loading,
|
||||
permissions
|
||||
};
|
||||
};
|
||||
|
||||
@@ -43,4 +82,4 @@ const mapDispatchToProps = dispatch => {
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(translate("repos")(Permissions));
|
||||
)(translate("permissions")(Permissions));
|
||||
|
||||
Reference in New Issue
Block a user