mirror of
https://github.com/strapi/strapi.git
synced 2025-10-29 17:04:13 +00:00
move to ds accordion
This commit is contained in:
parent
fddb6fffe0
commit
7a68a06082
@ -7,8 +7,6 @@ import styled from 'styled-components';
|
|||||||
|
|
||||||
const Wrapper = styled.div`
|
const Wrapper = styled.div`
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-left: auto;
|
|
||||||
padding-right: ${({ theme }) => theme.spaces[6]};
|
|
||||||
|
|
||||||
${({ hasConditions, disabled, theme }) =>
|
${({ hasConditions, disabled, theme }) =>
|
||||||
hasConditions &&
|
hasConditions &&
|
||||||
@ -26,12 +24,12 @@ const Wrapper = styled.div`
|
|||||||
`}
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const ConditionsButton = ({ onClick, className, hasConditions }) => {
|
const ConditionsButton = ({ onClick, className, hasConditions, variant }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper hasConditions={hasConditions} className={className}>
|
<Wrapper hasConditions={hasConditions} className={className}>
|
||||||
<Button variant="secondary" startIcon={<Settings />} onClick={onClick}>
|
<Button variant={variant} startIcon={<Settings />} onClick={onClick}>
|
||||||
{formatMessage({ id: 'app.components.LeftMenuLinkContainer.settings' })}
|
{formatMessage({ id: 'app.components.LeftMenuLinkContainer.settings' })}
|
||||||
</Button>
|
</Button>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
@ -41,11 +39,13 @@ const ConditionsButton = ({ onClick, className, hasConditions }) => {
|
|||||||
ConditionsButton.defaultProps = {
|
ConditionsButton.defaultProps = {
|
||||||
className: null,
|
className: null,
|
||||||
hasConditions: false,
|
hasConditions: false,
|
||||||
|
variant: 'secondary',
|
||||||
};
|
};
|
||||||
ConditionsButton.propTypes = {
|
ConditionsButton.propTypes = {
|
||||||
onClick: PropTypes.func.isRequired,
|
onClick: PropTypes.func.isRequired,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
hasConditions: PropTypes.bool,
|
hasConditions: PropTypes.bool,
|
||||||
|
variant: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is a styled component advanced usage :
|
// This is a styled component advanced usage :
|
||||||
|
|||||||
@ -137,7 +137,7 @@ const Collapse = ({
|
|||||||
<Chevron paddingLeft={2}>{isActive ? <Up /> : <Down />}</Chevron>
|
<Chevron paddingLeft={2}>{isActive ? <Up /> : <Down />}</Chevron>
|
||||||
</RowLabelWithCheckbox>
|
</RowLabelWithCheckbox>
|
||||||
|
|
||||||
<Row>
|
<Row style={{ flex: 1 }}>
|
||||||
{checkboxesActions.map(
|
{checkboxesActions.map(
|
||||||
({
|
({
|
||||||
actionId,
|
actionId,
|
||||||
@ -196,10 +196,12 @@ const Collapse = ({
|
|||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
</Row>
|
</Row>
|
||||||
|
<Box paddingRight={6}>
|
||||||
<ConditionsButton
|
<ConditionsButton
|
||||||
onClick={handleToggleModalIsOpen}
|
onClick={handleToggleModalIsOpen}
|
||||||
hasConditions={doesConditionButtonHasConditions}
|
hasConditions={doesConditionButtonHasConditions}
|
||||||
/>
|
/>
|
||||||
|
</Box>
|
||||||
{modalState.isMounted && (
|
{modalState.isMounted && (
|
||||||
<ConditionsModal
|
<ConditionsModal
|
||||||
headerBreadCrumbs={[label, 'app.components.LeftMenuLinkContainer.settings']}
|
headerBreadCrumbs={[label, 'app.components.LeftMenuLinkContainer.settings']}
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const ListWrapper = styled.div`
|
|
||||||
background-color: ${({ theme }) => theme.main.colors.white};
|
|
||||||
border-bottom-left-radius: ${({ theme }) => theme.main.sizes.borderRadius};
|
|
||||||
border-bottom-right-radius: ${({ theme }) => theme.main.sizes.borderRadius};
|
|
||||||
padding: 1.8rem 0;
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default ListWrapper;
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
import { Text } from '@buffetjs/core';
|
|
||||||
|
|
||||||
const activeStyle = theme => `
|
|
||||||
background-color: ${theme.main.colors.lightestBlue};
|
|
||||||
border: 1px solid ${theme.main.colors.darkBlue};
|
|
||||||
${Text} {
|
|
||||||
color: ${theme.main.colors.mediumBlue};
|
|
||||||
}
|
|
||||||
svg {
|
|
||||||
color: ${theme.main.colors.mediumBlue};
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
const RowStyle = styled.div`
|
|
||||||
height: 5.4rem;
|
|
||||||
padding: 1rem 3rem;
|
|
||||||
border: 1px solid transparent;
|
|
||||||
background-color: ${({ theme, isWhite }) => theme.main.colors[isWhite ? 'white' : 'lightGrey']};
|
|
||||||
cursor: pointer;
|
|
||||||
&:hover {
|
|
||||||
background-color: ${({ theme }) => theme.main.colors.lightestBlue};
|
|
||||||
${({ theme }) => activeStyle(theme)};
|
|
||||||
}
|
|
||||||
${({ isActive, theme }) => isActive && activeStyle(theme)};
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default RowStyle;
|
|
||||||
@ -1,11 +1,9 @@
|
|||||||
import React, { useMemo } from 'react';
|
import { Accordion, AccordionContent, AccordionToggle, Box } from '@strapi/parts';
|
||||||
import { Flex, Text } from '@buffetjs/core';
|
import upperFirst from 'lodash/upperFirst';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
||||||
import { PermissionsWrapper, RowContainer } from '@strapi/helper-plugin';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { useMemo } from 'react';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import SubCategory from '../SubCategory';
|
import SubCategory from '../SubCategory';
|
||||||
import RowStyle from './Wrapper';
|
|
||||||
|
|
||||||
const PermissionRow = ({
|
const PermissionRow = ({
|
||||||
childrenForm,
|
childrenForm,
|
||||||
@ -30,26 +28,18 @@ const PermissionRow = ({
|
|||||||
}, [name]);
|
}, [name]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowContainer isWhite={isWhite}>
|
<Accordion expanded={isOpen} toggle={handleClick} id="acc-1">
|
||||||
<RowStyle isWhite={isWhite} isActive={isOpen} onClick={handleClick}>
|
<AccordionToggle
|
||||||
<Flex alignItems="center" justifyContent="space-between">
|
title={upperFirst(categoryName)}
|
||||||
<div>
|
description={`${formatMessage(
|
||||||
<Text color="grey" fontWeight="bold" fontSize="xs" textTransform="uppercase">
|
{ id: 'Settings.permissions.category' },
|
||||||
{categoryName}
|
{ category: categoryName }
|
||||||
</Text>
|
)} ${kind === 'plugins' ? 'plugin' : kind}`}
|
||||||
<Text lineHeight="22px" color="grey">
|
variant={isWhite ? 'primary' : 'secondary'}
|
||||||
{formatMessage({ id: 'Settings.permissions.category' }, { category: categoryName })}
|
/>
|
||||||
{kind === 'plugins' ? 'plugin' : kind}
|
|
||||||
</Text>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<FontAwesomeIcon style={{ width: '11px' }} color="#9EA7B8" icon="chevron-down" />
|
|
||||||
</div>
|
|
||||||
</Flex>
|
|
||||||
</RowStyle>
|
|
||||||
|
|
||||||
{isOpen && (
|
<AccordionContent>
|
||||||
<PermissionsWrapper isWhite={isWhite}>
|
<Box padding={6}>
|
||||||
{childrenForm.map(({ actions, subCategoryName, subCategoryId }) => (
|
{childrenForm.map(({ actions, subCategoryName, subCategoryId }) => (
|
||||||
<SubCategory
|
<SubCategory
|
||||||
key={subCategoryName}
|
key={subCategoryName}
|
||||||
@ -60,9 +50,9 @@ const PermissionRow = ({
|
|||||||
pathToData={[...pathToData, subCategoryId]}
|
pathToData={[...pathToData, subCategoryId]}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</PermissionsWrapper>
|
</Box>
|
||||||
)}
|
</AccordionContent>
|
||||||
</RowContainer>
|
</Accordion>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
/* eslint-disable indent */
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const CheckboxWrapper = styled.div`
|
|
||||||
min-width: 33%;
|
|
||||||
padding: 0.9rem;
|
|
||||||
height: 3.6rem;
|
|
||||||
position: relative;
|
|
||||||
${({ hasConditions, disabled, theme }) =>
|
|
||||||
hasConditions &&
|
|
||||||
`
|
|
||||||
&:before {
|
|
||||||
content: '•';
|
|
||||||
position: absolute;
|
|
||||||
top: 2px;
|
|
||||||
left: 0px;
|
|
||||||
color: ${disabled ? theme.main.colors.grey : theme.main.colors.mediumBlue};
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default CheckboxWrapper;
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
/* eslint-disable indent */
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const ConditionsButtonWrapper = styled.div`
|
|
||||||
padding: 0.9rem;
|
|
||||||
${({ hasConditions }) =>
|
|
||||||
hasConditions &&
|
|
||||||
`
|
|
||||||
padding-left: 22px;
|
|
||||||
`}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default ConditionsButtonWrapper;
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
/* eslint-disable indent */
|
|
||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
|
||||||
padding-bottom: 2.6rem;
|
|
||||||
input[type='checkbox'] {
|
|
||||||
&:after {
|
|
||||||
color: ${({ theme }) => theme.main.colors.mediumBlue};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
${({ disabled, theme }) =>
|
|
||||||
disabled &&
|
|
||||||
`
|
|
||||||
label {
|
|
||||||
cursor: default !important;
|
|
||||||
color: ${theme.main.colors.grey};
|
|
||||||
}
|
|
||||||
input[type='checkbox'] {
|
|
||||||
&:after {
|
|
||||||
color: ${theme.main.colors.grey};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`}
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default Wrapper;
|
|
||||||
@ -1,25 +1,39 @@
|
|||||||
import React, { useMemo, useState } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Flex, Padded, Text, Checkbox } from '@buffetjs/core';
|
import { Row, Box, TableLabel, Checkbox, Grid, GridItem } from '@strapi/parts';
|
||||||
|
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { BaselineAlignment } from '@strapi/helper-plugin';
|
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import IS_DISABLED from 'ee_else_ce/components/Roles/PluginsAndSettings/SubCategory/utils/constants';
|
import IS_DISABLED from 'ee_else_ce/components/Roles/PluginsAndSettings/SubCategory/utils/constants';
|
||||||
import { usePermissionsDataManager } from '../../../../hooks';
|
import { usePermissionsDataManager } from '../../../../hooks';
|
||||||
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
||||||
import ConditionsButton from '../../ConditionsButton';
|
import ConditionsButton from '../../ConditionsButton';
|
||||||
import ConditionsModal from '../../ConditionsModal';
|
import ConditionsModal from '../../ConditionsModal';
|
||||||
import CheckboxWrapper from './CheckboxWrapper';
|
|
||||||
import ConditionsButtonWrapper from './ConditionsButtonWrapper';
|
|
||||||
import Wrapper from './Wrapper';
|
|
||||||
import { formatActions, getConditionsButtonState } from './utils';
|
import { formatActions, getConditionsButtonState } from './utils';
|
||||||
|
|
||||||
const Border = styled.div`
|
const Border = styled.div`
|
||||||
flex: 1;
|
flex: 1;
|
||||||
align-self: center;
|
align-self: center;
|
||||||
border-top: 1px solid #f6f6f6;
|
border-top: 1px solid ${({ theme }) => theme.colors.neutral150};
|
||||||
padding: 0px 10px;
|
`;
|
||||||
|
|
||||||
|
const CheckboxWrapper = styled.div`
|
||||||
|
position: relative;
|
||||||
|
${({ hasConditions, disabled, theme }) =>
|
||||||
|
hasConditions &&
|
||||||
|
`
|
||||||
|
&:before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: -4px;
|
||||||
|
left: -8px;
|
||||||
|
width: 6px;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 20px;
|
||||||
|
background: ${disabled ? theme.colors.neutral100 : theme.colors.primary600};
|
||||||
|
}
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const SubCategory = ({ categoryName, isFormDisabled, subCategoryName, actions, pathToData }) => {
|
const SubCategory = ({ categoryName, isFormDisabled, subCategoryName, actions, pathToData }) => {
|
||||||
@ -56,61 +70,67 @@ const SubCategory = ({ categoryName, isFormDisabled, subCategoryName, actions, p
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Wrapper>
|
<Box>
|
||||||
<Flex justifyContent="space-between" alignItems="center">
|
<Row justifyContent="space-between" alignItems="center">
|
||||||
<Padded right size="sm">
|
<Box paddingRight={4}>
|
||||||
<Text
|
<TableLabel textColor="neutral600">{subCategoryName}</TableLabel>
|
||||||
lineHeight="18px"
|
</Box>
|
||||||
color="#919bae"
|
|
||||||
fontWeight="bold"
|
|
||||||
fontSize="xs"
|
|
||||||
textTransform="uppercase"
|
|
||||||
>
|
|
||||||
{subCategoryName}
|
|
||||||
</Text>
|
|
||||||
</Padded>
|
|
||||||
<Border />
|
<Border />
|
||||||
<Padded left size="sm">
|
<Box paddingLeft={4}>
|
||||||
<BaselineAlignment top size="1px" />
|
|
||||||
<Checkbox
|
<Checkbox
|
||||||
name={pathToData.join('..')}
|
name={pathToData.join('..')}
|
||||||
message={formatMessage({ id: 'app.utils.select-all' })}
|
|
||||||
disabled={isFormDisabled || IS_DISABLED}
|
disabled={isFormDisabled || IS_DISABLED}
|
||||||
onChange={onChangeParentCheckbox}
|
// Keep same signature as packages/core/admin/admin/src/components/Roles/Permissions/index.js l.91
|
||||||
someChecked={hasSomeActionsSelected}
|
onValueChange={value =>
|
||||||
|
onChangeParentCheckbox({
|
||||||
|
target: {
|
||||||
|
name: pathToData.join('..'),
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
})}
|
||||||
|
indeterminate={hasSomeActionsSelected}
|
||||||
value={hasAllActionsSelected}
|
value={hasAllActionsSelected}
|
||||||
/>
|
>
|
||||||
</Padded>
|
{formatMessage({ id: 'app.utils.select-all' })}
|
||||||
</Flex>
|
</Checkbox>
|
||||||
<BaselineAlignment top size="1px" />
|
</Box>
|
||||||
<Padded top size="xs">
|
</Row>
|
||||||
<Flex flexWrap="wrap">
|
<Row paddingTop={6} paddingBottom={6}>
|
||||||
|
<Grid gap={2} style={{ flex: 1 }}>
|
||||||
{formattedActions.map(({ checkboxName, value, action, displayName, hasConditions }) => {
|
{formattedActions.map(({ checkboxName, value, action, displayName, hasConditions }) => {
|
||||||
return (
|
return (
|
||||||
|
<GridItem col={3} key={action}>
|
||||||
<CheckboxWrapper
|
<CheckboxWrapper
|
||||||
disabled={isFormDisabled || IS_DISABLED}
|
disabled={isFormDisabled || IS_DISABLED}
|
||||||
hasConditions={hasConditions}
|
hasConditions={hasConditions}
|
||||||
key={action}
|
|
||||||
>
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
name={checkboxName}
|
name={checkboxName}
|
||||||
disabled={isFormDisabled || IS_DISABLED}
|
disabled={isFormDisabled || IS_DISABLED}
|
||||||
message={displayName}
|
// Keep same signature as packages/core/admin/admin/src/components/Roles/Permissions/index.js l.91
|
||||||
onChange={onChangeSimpleCheckbox}
|
onValueChange={value =>
|
||||||
|
onChangeSimpleCheckbox({
|
||||||
|
target: {
|
||||||
|
name: checkboxName,
|
||||||
|
value,
|
||||||
|
},
|
||||||
|
})}
|
||||||
value={value}
|
value={value}
|
||||||
/>
|
>
|
||||||
|
{displayName}
|
||||||
|
</Checkbox>
|
||||||
</CheckboxWrapper>
|
</CheckboxWrapper>
|
||||||
|
</GridItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Flex>
|
</Grid>
|
||||||
<ConditionsButtonWrapper disabled={isFormDisabled} hasConditions={doesButtonHasCondition}>
|
|
||||||
<ConditionsButton
|
<ConditionsButton
|
||||||
hasConditions={doesButtonHasCondition}
|
hasConditions={doesButtonHasCondition}
|
||||||
onClick={handleToggleModalIsOpen}
|
onClick={handleToggleModalIsOpen}
|
||||||
|
variant="tertiary"
|
||||||
/>
|
/>
|
||||||
</ConditionsButtonWrapper>
|
</Row>
|
||||||
</Padded>
|
</Box>
|
||||||
</Wrapper>
|
|
||||||
{modalState.isMounted && (
|
{modalState.isMounted && (
|
||||||
<ConditionsModal
|
<ConditionsModal
|
||||||
headerBreadCrumbs={[categoryName, subCategoryName]}
|
headerBreadCrumbs={[categoryName, subCategoryName]}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Padded } from '@buffetjs/core';
|
import { Box } from '@strapi/parts';
|
||||||
import ListWrapper from './ListWrapper';
|
|
||||||
import PermissionRow from './Row';
|
import PermissionRow from './Row';
|
||||||
|
|
||||||
const PluginsAndSettingsPermissions = ({ isFormDisabled, kind, layout }) => {
|
const PluginsAndSettingsPermissions = ({ isFormDisabled, kind, layout }) => {
|
||||||
@ -12,8 +11,7 @@ const PluginsAndSettingsPermissions = ({ isFormDisabled, kind, layout }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListWrapper>
|
<Box padding={6} background="neutral0">
|
||||||
<Padded left right size="md">
|
|
||||||
{layout.map(({ category, categoryId, childrenForm }, index) => {
|
{layout.map(({ category, categoryId, childrenForm }, index) => {
|
||||||
return (
|
return (
|
||||||
<PermissionRow
|
<PermissionRow
|
||||||
@ -29,8 +27,7 @@ const PluginsAndSettingsPermissions = ({ isFormDisabled, kind, layout }) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Padded>
|
</Box>
|
||||||
</ListWrapper>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
import React, { memo } from 'react';
|
import { Box, Checkbox, Text } from '@strapi/parts';
|
||||||
|
import upperFirst from 'lodash/upperFirst';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import React, { memo } from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { Checkbox, Text, Box } from '@strapi/parts';
|
|
||||||
import CollapseLabel from '../CollapseLabel';
|
import CollapseLabel from '../CollapseLabel';
|
||||||
import { firstRowWidth } from '../Permissions/utils/constants';
|
import { firstRowWidth } from '../Permissions/utils/constants';
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ const RowLabelWithCheckbox = ({
|
|||||||
role: 'button',
|
role: 'button',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<StyledText>{label.charAt(0).toUpperCase() + label.slice(1)}</StyledText>
|
<StyledText>{upperFirst(label)}</StyledText>
|
||||||
{children}
|
{children}
|
||||||
</CollapseLabel>
|
</CollapseLabel>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user