mirror of
https://github.com/strapi/strapi.git
synced 2025-09-23 15:29:27 +00:00
Merge pull request #13256 from strapi/fix/component-icons-optional
Make component icons optional
This commit is contained in:
commit
d947be6859
@ -1,43 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
||||||
import Wrapper from './Wrapper';
|
|
||||||
|
|
||||||
const DynamicComponentCard = ({ children, componentUid, friendlyName, icon, onClick }) => {
|
|
||||||
return (
|
|
||||||
<Wrapper
|
|
||||||
onClick={e => {
|
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
|
|
||||||
onClick(componentUid);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<button className="component-icon" type="button">
|
|
||||||
<FontAwesomeIcon icon={icon} />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div className="component-uid">
|
|
||||||
<span>{friendlyName}</span>
|
|
||||||
</div>
|
|
||||||
{children}
|
|
||||||
</Wrapper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
DynamicComponentCard.defaultProps = {
|
|
||||||
children: null,
|
|
||||||
friendlyName: '',
|
|
||||||
onClick: () => {},
|
|
||||||
icon: 'smile',
|
|
||||||
};
|
|
||||||
|
|
||||||
DynamicComponentCard.propTypes = {
|
|
||||||
children: PropTypes.node,
|
|
||||||
componentUid: PropTypes.string.isRequired,
|
|
||||||
friendlyName: PropTypes.string,
|
|
||||||
icon: PropTypes.string,
|
|
||||||
onClick: PropTypes.func,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DynamicComponentCard;
|
|
@ -74,7 +74,7 @@ function ComponentCard({ componentUid, intlLabel, icon, onClick }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ComponentCard.defaultProps = {
|
ComponentCard.defaultProps = {
|
||||||
icon: 'smile',
|
icon: 'dice-d6',
|
||||||
onClick: () => {},
|
onClick: () => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ function ComponentCard({ component, dzName, index, isActive, isInDevelopmentMode
|
|||||||
paddingRight={4}
|
paddingRight={4}
|
||||||
>
|
>
|
||||||
<StackCentered spacing={1}>
|
<StackCentered spacing={1}>
|
||||||
<StyledFontAwesomeIcon icon={icon} />
|
<StyledFontAwesomeIcon icon={icon || 'dice-d6'} />
|
||||||
<Box maxWidth={`calc(${pxToRem(140)} - 32px)`}>
|
<Box maxWidth={`calc(${pxToRem(140)} - 32px)`}>
|
||||||
<Typography variant="pi" fontWeight="bold" ellipsis>
|
<Typography variant="pi" fontWeight="bold" ellipsis>
|
||||||
{displayName}
|
{displayName}
|
||||||
|
@ -16,23 +16,14 @@ import Cell from './Cell';
|
|||||||
|
|
||||||
const CELL_WIDTH = 44;
|
const CELL_WIDTH = 44;
|
||||||
|
|
||||||
const ComponentIconPicker = ({ error, isCreating, intlLabel, name, onChange, value }) => {
|
const ComponentIconPicker = ({ error, intlLabel, name, onChange, value }) => {
|
||||||
const { allIcons, allComponentsIconAlreadyTaken } = useDataManager();
|
const { allIcons } = useDataManager();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const [originalIcon] = useState(value);
|
|
||||||
const initialIcons = allIcons.filter(ico => {
|
|
||||||
if (isCreating) {
|
|
||||||
return !allComponentsIconAlreadyTaken.includes(ico);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edition
|
|
||||||
return !allComponentsIconAlreadyTaken.filter(icon => icon !== originalIcon).includes(ico);
|
|
||||||
});
|
|
||||||
|
|
||||||
const searchWrapperRef = useRef();
|
const searchWrapperRef = useRef();
|
||||||
const [showSearch, setShowSearch] = useState(false);
|
const [showSearch, setShowSearch] = useState(false);
|
||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [icons, setIcons] = useState(initialIcons);
|
const [icons, setIcons] = useState(allIcons);
|
||||||
const toggleSearch = () => setShowSearch(prev => !prev);
|
const toggleSearch = () => setShowSearch(prev => !prev);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -43,7 +34,7 @@ const ComponentIconPicker = ({ error, isCreating, intlLabel, name, onChange, val
|
|||||||
|
|
||||||
const handleChangeSearch = ({ target: { value } }) => {
|
const handleChangeSearch = ({ target: { value } }) => {
|
||||||
setSearch(value);
|
setSearch(value);
|
||||||
setIcons(() => initialIcons.filter(icon => icon.includes(value)));
|
setIcons(() => allIcons.filter(icon => icon.includes(value)));
|
||||||
};
|
};
|
||||||
|
|
||||||
const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : '';
|
const errorMessage = error ? formatMessage({ id: error, defaultMessage: error }) : '';
|
||||||
@ -91,7 +82,7 @@ const ComponentIconPicker = ({ error, isCreating, intlLabel, name, onChange, val
|
|||||||
}}
|
}}
|
||||||
onClear={() => {
|
onClear={() => {
|
||||||
setSearch('');
|
setSearch('');
|
||||||
setIcons(initialIcons);
|
setIcons(allIcons);
|
||||||
toggleSearch();
|
toggleSearch();
|
||||||
}}
|
}}
|
||||||
value={search}
|
value={search}
|
||||||
@ -175,7 +166,6 @@ ComponentIconPicker.defaultProps = {
|
|||||||
|
|
||||||
ComponentIconPicker.propTypes = {
|
ComponentIconPicker.propTypes = {
|
||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
isCreating: PropTypes.bool.isRequired,
|
|
||||||
intlLabel: PropTypes.shape({
|
intlLabel: PropTypes.shape({
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
defaultMessage: PropTypes.string.isRequired,
|
defaultMessage: PropTypes.string.isRequired,
|
||||||
|
@ -541,10 +541,6 @@ const DataManagerProvider = ({
|
|||||||
addAttribute,
|
addAttribute,
|
||||||
addCreatedComponentToDynamicZone,
|
addCreatedComponentToDynamicZone,
|
||||||
allComponentsCategories: retrieveSpecificInfoFromComponents(components, ['category']),
|
allComponentsCategories: retrieveSpecificInfoFromComponents(components, ['category']),
|
||||||
allComponentsIconAlreadyTaken: retrieveSpecificInfoFromComponents(components, [
|
|
||||||
'schema',
|
|
||||||
'icon',
|
|
||||||
]),
|
|
||||||
allIcons,
|
allIcons,
|
||||||
changeDynamicZoneComponents,
|
changeDynamicZoneComponents,
|
||||||
components,
|
components,
|
||||||
|
@ -39,7 +39,7 @@ const createComponentSchema = (usedComponentNames, reservedNames, category) => {
|
|||||||
.matches(CATEGORY_NAME_REGEX, errorsTrads.regex)
|
.matches(CATEGORY_NAME_REGEX, errorsTrads.regex)
|
||||||
.required(errorsTrads.required),
|
.required(errorsTrads.required),
|
||||||
|
|
||||||
icon: yup.string().required(errorsTrads.required),
|
icon: yup.string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return yup.object(shape);
|
return yup.object(shape);
|
||||||
|
@ -22,8 +22,7 @@ const componentSchema = createSchema(VALID_TYPES, VALID_RELATIONS, {
|
|||||||
icon: yup
|
icon: yup
|
||||||
.string()
|
.string()
|
||||||
.nullable()
|
.nullable()
|
||||||
.test(isValidIcon)
|
.test(isValidIcon),
|
||||||
.required('icon.required'),
|
|
||||||
category: yup
|
category: yup
|
||||||
.string()
|
.string()
|
||||||
.nullable()
|
.nullable()
|
||||||
|
@ -47,11 +47,6 @@ describe('Content Type Builder - Components', () => {
|
|||||||
name: 'ValidationError',
|
name: 'ValidationError',
|
||||||
path: ['component', 'displayName'],
|
path: ['component', 'displayName'],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
message: 'icon.required',
|
|
||||||
name: 'ValidationError',
|
|
||||||
path: ['component', 'icon'],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
message: 'category.required',
|
message: 'category.required',
|
||||||
name: 'ValidationError',
|
name: 'ValidationError',
|
||||||
@ -59,7 +54,7 @@ describe('Content Type Builder - Components', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
message: '4 errors occurred',
|
message: '3 errors occurred',
|
||||||
name: 'ValidationError',
|
name: 'ValidationError',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -242,11 +237,6 @@ describe('Content Type Builder - Components', () => {
|
|||||||
name: 'ValidationError',
|
name: 'ValidationError',
|
||||||
path: ['component', 'displayName'],
|
path: ['component', 'displayName'],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
message: 'icon.required',
|
|
||||||
name: 'ValidationError',
|
|
||||||
path: ['component', 'icon'],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
message: 'category.required',
|
message: 'category.required',
|
||||||
name: 'ValidationError',
|
name: 'ValidationError',
|
||||||
@ -254,7 +244,7 @@ describe('Content Type Builder - Components', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
message: '3 errors occurred',
|
message: '2 errors occurred',
|
||||||
name: 'ValidationError',
|
name: 'ValidationError',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user