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';
|
2021-11-15 18:27:32 +01:00
|
|
|
import { Typography } from '@strapi/design-system/Typography';
|
2021-10-27 10:36:00 +02:00
|
|
|
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';
|
2020-08-06 16:27:51 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
? []
|
2021-11-24 15:49:01 +01:00
|
|
|
: controllerRoutes.filter(o => o.handler.endsWith(pathResolved));
|
2021-09-21 18:47:18 +02:00
|
|
|
|
2020-08-06 16:27:51 +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 ? (
|
2021-09-22 16:56:31 +02:00
|
|
|
<Stack size={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>
|
|
|
|
) : (
|
2021-09-22 16:56:31 +02:00
|
|
|
<Stack size={2}>
|
2021-11-15 18:27:32 +01:00
|
|
|
<Typography variant="delta" as="h3">
|
2021-09-22 16:56:31 +02:00
|
|
|
{formatMessage({
|
|
|
|
id: 'users-permissions.Policies.header.title',
|
|
|
|
defaultMessage: 'Advanced settings',
|
|
|
|
})}
|
2021-11-15 18:27:32 +01:00
|
|
|
</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",
|
|
|
|
})}
|
2021-11-15 18:27:32 +01:00
|
|
|
</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>
|
2020-08-06 16:27:51 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Policies;
|