mirror of
https://github.com/strapi/strapi.git
synced 2025-09-07 15:49:24 +00:00
Add modal condition button
This commit is contained in:
parent
7a68a06082
commit
deb6859a56
@ -1,12 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const Wrapper = styled.div`
|
|
||||||
display: flex;
|
|
||||||
height: 36px;
|
|
||||||
border-radius: ${({ theme }) => theme.main.sizes.borderRadius};
|
|
||||||
margin-bottom: 18px;
|
|
||||||
background-color: ${({ theme, isGrey }) =>
|
|
||||||
isGrey ? theme.main.colors.content.background : theme.main.colors.white};
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default Wrapper;
|
|
@ -1,10 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Text, Padded, Flex } from '@buffetjs/core';
|
import { Row, TableLabel } from '@strapi/parts';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import ConditionsSelect from '../ConditionsSelect';
|
import ConditionsSelect from '../ConditionsSelect';
|
||||||
import Wrapper from './Wrapper';
|
|
||||||
|
const RowWrapper = styled(Row)`
|
||||||
|
height: 52px;
|
||||||
|
`;
|
||||||
|
|
||||||
const ActionRow = ({
|
const ActionRow = ({
|
||||||
arrayOfOptionsGroupedByCategory,
|
arrayOfOptionsGroupedByCategory,
|
||||||
@ -19,50 +23,27 @@ const ActionRow = ({
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper isGrey={isGrey}>
|
<RowWrapper background={isGrey ? 'neutral100' : 'neutral0'}>
|
||||||
<Padded style={{ width: 200 }} top left right bottom size="sm">
|
<Row paddingLeft={6} style={{ width: 180 }}>
|
||||||
<Flex>
|
<TableLabel textColor="neutral500">
|
||||||
<Text
|
{formatMessage({
|
||||||
lineHeight="19px"
|
id: 'Settings.permissions.conditions.can',
|
||||||
color="grey"
|
})}
|
||||||
fontSize="xs"
|
|
||||||
fontWeight="bold"
|
</TableLabel>
|
||||||
textTransform="uppercase"
|
<TableLabel title={label} textColor="primary600">
|
||||||
>
|
{formatMessage({
|
||||||
{formatMessage({
|
id: `Settings.roles.form.permissions.${label.toLowerCase()}`,
|
||||||
id: 'Settings.permissions.conditions.can',
|
defaultMessage: label,
|
||||||
})}
|
})}
|
||||||
|
</TableLabel>
|
||||||
</Text>
|
<TableLabel textColor="neutral500">
|
||||||
<Text
|
|
||||||
title={label}
|
{formatMessage({
|
||||||
lineHeight="19px"
|
id: 'Settings.permissions.conditions.when',
|
||||||
fontWeight="bold"
|
})}
|
||||||
fontSize="xs"
|
</TableLabel>
|
||||||
textTransform="uppercase"
|
</Row>
|
||||||
color="mediumBlue"
|
|
||||||
style={{ maxWidth: '60%' }}
|
|
||||||
ellipsis
|
|
||||||
>
|
|
||||||
{formatMessage({
|
|
||||||
id: `Settings.roles.form.permissions.${label.toLowerCase()}`,
|
|
||||||
defaultMessage: label,
|
|
||||||
})}
|
|
||||||
</Text>
|
|
||||||
<Text
|
|
||||||
lineHeight="19px"
|
|
||||||
color="grey"
|
|
||||||
fontSize="xs"
|
|
||||||
fontWeight="bold"
|
|
||||||
textTransform="uppercase"
|
|
||||||
>
|
|
||||||
|
|
||||||
{formatMessage({
|
|
||||||
id: 'Settings.permissions.conditions.when',
|
|
||||||
})}
|
|
||||||
</Text>
|
|
||||||
</Flex>
|
|
||||||
</Padded>
|
|
||||||
<ConditionsSelect
|
<ConditionsSelect
|
||||||
arrayOfOptionsGroupedByCategory={arrayOfOptionsGroupedByCategory}
|
arrayOfOptionsGroupedByCategory={arrayOfOptionsGroupedByCategory}
|
||||||
name={name}
|
name={name}
|
||||||
@ -71,7 +52,7 @@ const ActionRow = ({
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={value}
|
value={value}
|
||||||
/>
|
/>
|
||||||
</Wrapper>
|
</RowWrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
import styled from 'styled-components';
|
|
||||||
|
|
||||||
const Separator = styled.div`
|
|
||||||
padding-top: 1.4rem;
|
|
||||||
margin-bottom: 2.8rem;
|
|
||||||
border-bottom: 1px solid ${({ theme }) => theme.main.colors.brightGrey};
|
|
||||||
`;
|
|
||||||
|
|
||||||
export default Separator;
|
|
@ -1,14 +1,38 @@
|
|||||||
import React, { useMemo, useState } from 'react';
|
import { After } from '@strapi/icons';
|
||||||
|
import {
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
H2,
|
||||||
|
ModalFooter,
|
||||||
|
ModalHeader,
|
||||||
|
ModalLayout,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
TextButton,
|
||||||
|
} from '@strapi/parts';
|
||||||
|
import { cloneDeep, get, groupBy, set, upperFirst } from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { cloneDeep, get, groupBy, set } from 'lodash';
|
import React, { useMemo, useState } from 'react';
|
||||||
import { Modal, ModalHeader, ModalFooter } from '@strapi/helper-plugin';
|
import { FormattedMessage, useIntl } from 'react-intl';
|
||||||
import { Button, Text, Padded } from '@buffetjs/core';
|
import styled from 'styled-components';
|
||||||
import { useIntl } from 'react-intl';
|
|
||||||
import { usePermissionsDataManager } from '../../../hooks';
|
import { usePermissionsDataManager } from '../../../hooks';
|
||||||
import createDefaultConditionsForm from './utils/createDefaultConditionsForm';
|
|
||||||
import ActionRow from './ActionRow';
|
|
||||||
import Separator from './Separator';
|
|
||||||
import updateValues from '../Permissions/utils/updateValues';
|
import updateValues from '../Permissions/utils/updateValues';
|
||||||
|
import ActionRow from './ActionRow';
|
||||||
|
import createDefaultConditionsForm from './utils/createDefaultConditionsForm';
|
||||||
|
|
||||||
|
// ! Something needs to be done in the DS parts to avoid doing this
|
||||||
|
const Icon = styled(Box)`
|
||||||
|
svg {
|
||||||
|
width: 6px;
|
||||||
|
}
|
||||||
|
* {
|
||||||
|
fill: ${({ theme }) => theme.colors.neutral300};
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
const Separator = styled.div`
|
||||||
|
border-bottom: 1px solid ${({ theme }) => theme.main.colors.brightGrey};
|
||||||
|
`;
|
||||||
|
|
||||||
const ConditionsModal = ({
|
const ConditionsModal = ({
|
||||||
actions,
|
actions,
|
||||||
@ -21,6 +45,11 @@ const ConditionsModal = ({
|
|||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const { availableConditions, modifiedData, onChangeConditions } = usePermissionsDataManager();
|
const { availableConditions, modifiedData, onChangeConditions } = usePermissionsDataManager();
|
||||||
|
|
||||||
|
const translatedHeaders = headerBreadCrumbs.map(headerTrad => ({
|
||||||
|
key: headerTrad,
|
||||||
|
element: <FormattedMessage id={headerTrad} defaultMessage={upperFirst(headerTrad)} />,
|
||||||
|
}));
|
||||||
|
|
||||||
const arrayOfOptionsGroupedByCategory = useMemo(() => {
|
const arrayOfOptionsGroupedByCategory = useMemo(() => {
|
||||||
return Object.entries(groupBy(availableConditions, 'category'));
|
return Object.entries(groupBy(availableConditions, 'category'));
|
||||||
}, [availableConditions]);
|
}, [availableConditions]);
|
||||||
@ -79,53 +108,77 @@ const ConditionsModal = ({
|
|||||||
onToggle();
|
onToggle();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
if (!isOpen) return null;
|
||||||
<Modal withoverflow="true" onClosed={onClosed} isOpen={isOpen} onToggle={onToggle}>
|
|
||||||
<ModalHeader headerBreadcrumbs={headerBreadCrumbs} />
|
|
||||||
<Padded top left right bottom size="md">
|
|
||||||
<Text fontSize="lg" fontWeight="bold">
|
|
||||||
{formatMessage({
|
|
||||||
id: 'Settings.permissions.conditions.define-conditions',
|
|
||||||
})}
|
|
||||||
</Text>
|
|
||||||
<Separator />
|
|
||||||
{actionsToDisplay.length === 0 && (
|
|
||||||
<Text fontSize="md" color="grey">
|
|
||||||
{formatMessage({ id: 'Settings.permissions.conditions.no-actions' })}
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
{actionsToDisplay.map(({ actionId, label, pathToConditionsObject }, index) => {
|
|
||||||
const name = pathToConditionsObject.join('..');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ActionRow
|
<ModalLayout onClose={onClosed}>
|
||||||
key={actionId}
|
<ModalHeader>
|
||||||
arrayOfOptionsGroupedByCategory={arrayOfOptionsGroupedByCategory}
|
<Stack horizontal size={3}>
|
||||||
label={label}
|
{translatedHeaders.map(({ key, element }, index) => {
|
||||||
isFormDisabled={isFormDisabled}
|
const shouldDisplayChevron = index < translatedHeaders.length - 1;
|
||||||
isGrey={index % 2 === 0}
|
|
||||||
name={name}
|
return (
|
||||||
onCategoryChange={handleCategoryChange}
|
<>
|
||||||
onChange={handleChange}
|
<TextButton textColor="neutral800" key={key}>
|
||||||
value={get(state, name, {})}
|
{element}
|
||||||
/>
|
</TextButton>
|
||||||
);
|
{shouldDisplayChevron && (
|
||||||
})}
|
<Icon>
|
||||||
</Padded>
|
<After />
|
||||||
<ModalFooter>
|
</Icon>
|
||||||
<section>
|
)}
|
||||||
<Button type="button" color="cancel" onClick={onToggle}>
|
</>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Stack>
|
||||||
|
</ModalHeader>
|
||||||
|
<Box padding={8}>
|
||||||
|
<Stack size={6}>
|
||||||
|
<H2>
|
||||||
|
{formatMessage({
|
||||||
|
id: 'Settings.permissions.conditions.define-conditions',
|
||||||
|
})}
|
||||||
|
</H2>
|
||||||
|
<Separator />
|
||||||
|
<Box>
|
||||||
|
{actionsToDisplay.length === 0 && (
|
||||||
|
<Text>{formatMessage({ id: 'Settings.permissions.conditions.no-actions' })}</Text>
|
||||||
|
)}
|
||||||
|
{actionsToDisplay.map(({ actionId, label, pathToConditionsObject }, index) => {
|
||||||
|
const name = pathToConditionsObject.join('..');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ActionRow
|
||||||
|
key={actionId}
|
||||||
|
arrayOfOptionsGroupedByCategory={arrayOfOptionsGroupedByCategory}
|
||||||
|
label={label}
|
||||||
|
isFormDisabled={isFormDisabled}
|
||||||
|
isGrey={index % 2 === 0}
|
||||||
|
name={name}
|
||||||
|
onCategoryChange={handleCategoryChange}
|
||||||
|
onChange={handleChange}
|
||||||
|
value={get(state, name, {})}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
<ModalFooter
|
||||||
|
startActions={
|
||||||
|
<Button variant="tertiary" onClick={onToggle}>
|
||||||
{formatMessage({ id: 'app.components.Button.cancel' })}
|
{formatMessage({ id: 'app.components.Button.cancel' })}
|
||||||
</Button>
|
</Button>
|
||||||
|
}
|
||||||
<Button type="button" color="success" onClick={handleSubmit}>
|
endActions={
|
||||||
|
<Button onClick={handleSubmit}>
|
||||||
{formatMessage({
|
{formatMessage({
|
||||||
id: 'Settings.permissions.conditions.apply',
|
id: 'Settings.permissions.conditions.apply',
|
||||||
})}
|
})}
|
||||||
</Button>
|
</Button>
|
||||||
</section>
|
}
|
||||||
</ModalFooter>
|
/>
|
||||||
</Modal>
|
</ModalLayout>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,8 +64,8 @@ const Chevron = styled(Box)`
|
|||||||
|
|
||||||
const TinyDot = styled(Box)`
|
const TinyDot = styled(Box)`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: -6px;
|
||||||
left: 35px;
|
left: 37px;
|
||||||
width: 6px;
|
width: 6px;
|
||||||
height: 6px;
|
height: 6px;
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
|
@ -23,6 +23,7 @@ const Cell = styled(Box)`
|
|||||||
position: relative;
|
position: relative;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// ! Something needs to be done in the DS parts to avoid doing this
|
||||||
const Chevron = styled(Box)`
|
const Chevron = styled(Box)`
|
||||||
display: none;
|
display: none;
|
||||||
svg {
|
svg {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user