61 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-09-22 16:56:31 +02:00
import React from 'react';
2021-09-13 12:24:11 +02:00
import { useIntl } from 'react-intl';
import { Typography } from '@strapi/design-system/Typography';
import { Stack } from '@strapi/design-system/Stack';
import { GridItem } from '@strapi/design-system/Grid';
2021-11-24 11:48:58 +01:00
import { get, isEmpty, without } from 'lodash';
2021-09-21 18:47:18 +02:00
import { useUsersPermissions } from '../../contexts/UsersPermissionsContext';
import BoundRoute from '../BoundRoute';
const Policies = () => {
2021-09-13 12:24:11 +02:00
const { formatMessage } = useIntl();
2021-09-22 16:56:31 +02:00
const { selectedAction, routes } = useUsersPermissions();
2021-11-24 11:48:58 +01:00
2021-09-21 18:47:18 +02:00
const path = without(selectedAction.split('.'), 'controllers');
const controllerRoutes = get(routes, path[0]);
2021-11-24 15:49:01 +01:00
const pathResolved = path.slice(1).join('.');
2021-11-24 11:48:58 +01:00
2021-09-21 18:47:18 +02:00
const displayedRoutes = isEmpty(controllerRoutes)
? []
2022-08-08 23:33:39 +02:00
: controllerRoutes.filter((o) => o.handler.endsWith(pathResolved));
2021-09-21 18:47:18 +02:00
return (
2021-09-13 12:24:11 +02:00
<GridItem
col={5}
background="neutral150"
paddingTop={6}
paddingBottom={6}
paddingLeft={7}
paddingRight={7}
style={{ minHeight: '100%' }}
>
2021-09-21 18:47:18 +02:00
{selectedAction ? (
<Stack spacing={2}>
2021-09-22 14:48:06 +02:00
{displayedRoutes.map((route, key) => (
// eslint-disable-next-line react/no-array-index-key
<BoundRoute key={key} route={route} />
))}
2021-09-21 18:47:18 +02:00
</Stack>
) : (
<Stack spacing={2}>
<Typography variant="delta" as="h3">
2021-09-22 16:56:31 +02:00
{formatMessage({
id: 'users-permissions.Policies.header.title',
defaultMessage: 'Advanced settings',
})}
</Typography>
<Typography as="p" textColor="neutral600">
2021-09-21 18:47:18 +02:00
{formatMessage({
id: 'users-permissions.Policies.header.hint',
defaultMessage:
"Select the application's actions or the plugin's actions and click on the cog icon to display the bound route",
})}
</Typography>
2021-09-22 16:56:31 +02:00
</Stack>
2021-09-21 18:47:18 +02:00
)}
2021-09-13 12:24:11 +02:00
</GridItem>
);
};
export default Policies;