-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Categories selector for dynamic zone #7987
Added Categories selector for dynamic zone #7987
Conversation
Codecov Report
@@ Coverage Diff @@
## master #7987 +/- ##
==========================================
- Coverage 33.73% 33.65% -0.09%
==========================================
Files 1244 1248 +4
Lines 13732 13765 +33
Branches 1365 1365
==========================================
Hits 4632 4632
- Misses 8210 8243 +33
Partials 890 890
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Hi your PR contains unwanted commits. Can you clean it up ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your contribution!
Users are going to love this addition, there just a few changes that needs to be applied and we will merge your PR.
Don't hesitate if you have any question.
` | ||
max-height: 260px; | ||
`} | ||
|
||
.componentPickerTitle { | ||
margin-bottom: 15px; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change the margin-bottom to 10px in order to keep the baseline?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p className="componentPickerTitle"> | ||
<FormattedMessage id={`${pluginId}.components.DynamicZone.pick-compo`} /> | ||
</p> | ||
<div className="categoriesList"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the following css so the baseline is kept
.categoriesList {
padding-bottom: 4px;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -41,19 +42,27 @@ const DynamicZone = ({ | |||
dynamicDisplayedComponents, | |||
}) => { | |||
const [isOpen, setIsOpen] = useState(false); | |||
|
|||
const [indexCategory, setIndexCategory] = useState(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to change the logic a bit of the collapses.
So here's my idea, we will use an object instead for the dynamicComponentCategories
.
First let's change the useState hook:
const [categoryToOpen, setCategoryToOpen] = useState('');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -78,6 +87,42 @@ const DynamicZone = ({ | |||
[layout, name] | |||
); | |||
|
|||
const dynamicComponentCategories = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we will use lodash groupBy
instead to simplify the code a bit:
const dynamicComponentCategories = useMemo(() => {
const componentsWithInfos = dynamicZoneAvailableComponents.map(componentUid => {
const {
category,
schema: { info },
} = getDynamicComponent(componentUid);
return { componentUid, category, info };
});
return groupBy(componentsWithInfos, 'category');
}, [dynamicZoneAvailableComponents, getDynamicComponent]);
This will return an object like the following:
{
category1: [ { componentUid, category: category1: info }, ....],
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, []); | ||
}, [dynamicZoneAvailableComponents, getDynamicComponent]); | ||
|
||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the modification added the effect is not needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<FormattedMessage id={`${pluginId}.components.DynamicZone.pick-compo`} /> | ||
</p> | ||
<div className="categoriesList"> | ||
{dynamicComponentCategories.map(({ category, components }, index) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Therefore, this needs to be updated as follow:
{Object.keys(dynamicComponentCategories).map((categoryName, index) => {
const components = dynamicComponentCategories[categoryName];
return (
<CategoryItem
key={categoryName}
category={categoryName}
components={components}
isOpen={categoryToOpen === categoryName}
isFirst={index === 0}
onClickToggle={() => {
// Detailed below
handleClickToggle(categoryName);
}}
onClickComponent={componentUid => {
setCategoryToOpen('');
const shouldCheckErrors = hasError;
addComponentToDynamicZone(name, componentUid, shouldCheckErrors);
}}
/>
);
})}
const handleClickToggle = useCallback(
categoryName => {
const nextCategoryToOpen = categoryToOpen === categoryName ? '' : categoryName;
setCategoryToOpen(nextCategoryToOpen);
},
[categoryToOpen]
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
align-self: center; | ||
margin-top: -2px; | ||
} | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello 😃 , I made some modifications to the file in order to use the theme and avoid the multiple conditions on the isOpen variable.
import styled from 'styled-components';
/* eslint-disable */
const BannerWrapper = styled.button`
display: flex;
height: 36px;
width: 100%;
padding: 0 15px;
border-bottom: 0;
border: 1px solid rgba(227, 233, 243, 0.75);
background-color: ${({ theme }) => theme.main.colors.white};
font-size: ${({ theme }) => theme.main.sizes.fonts.md};
font-weight: ${({ theme }) => theme.main.fontWeights.semiBold};
cursor: pointer;
&:focus {
outline: 0;
}
.img-wrapper {
width: 19px;
height: 19px;
margin-right: 19px;
border-radius: 50%;
background-color: ${({ theme }) => theme.main.colors.mediumGrey};
text-align: center;
}
.label {
text-transform: capitalize;
}
svg {
path {
fill: ${({ theme }) => theme.main.colors.leftMenu['link-color']} !important;
}
}
-webkit-font-smoothing: antialiased;
> div {
align-self: center;
margin-top: -2px;
}
${({ isFirst, theme }) => {
if (isFirst) {
return `
border-top-right-radius: ${theme.main.sizes.borderRadius};
border-top-left-radius: ${theme.main.sizes.borderRadius};
`;
}
}}
${({ isOpen, theme }) => {
if (isOpen) {
return `
border: 1px solid ${theme.main.colors.darkBlue};
background-color: ${theme.main.colors.lightBlue};
color: ${theme.main.colors.mediumBlue};
font-weight: ${theme.main.fontWeights.bold};
.img-wrapper {
background-color: ${theme.main.colors.darkBlue};
transform: rotate(180deg);
}
svg {
path {
fill: ${theme.main.colors.mediumBlue} !important;
}
}
`;
}
}}
`;
export default BannerWrapper;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HichamELBSI done in bc81f9a
<Collapse | ||
isOpen={isOpen} | ||
style={{ backgroundColor: '#F3F3F3' }} | ||
onExited={() => setShowComponents(false)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create a handle function please.
const handleExited = () => setShowComponents(false);
return (
<>
<Banner onClickToggle={onClickToggle} isFirst={isFirst} isOpen={isOpen} category={category} />
<Collapse
isOpen={isOpen}
style={{ backgroundColor: '#F3F3F3' }}
onExited={handleExited}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HichamELBSI done in 146bd85
<Banner onClickToggle={onClickToggle} isFirst={isFirst} isOpen={isOpen} category={category} /> | ||
<Collapse | ||
isOpen={isOpen} | ||
style={{ backgroundColor: '#F3F3F3' }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This custom background seems to be useless. Can you remove it please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HichamELBSI done in 773c0a8
<div | ||
className="componentsList" | ||
style={{ paddingTop: '10px', paddingLeft: '15px', paddingRight: '15px' }} | ||
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you create a file for this component please.
`...src/components/DynamicZone/ComponentsList.js``
import styled from 'styled-components';
const ComponentsList = styled.div`
padding-top: 10px;
padding-left: 15px;
padding-right: 15px;
`;
export default ComponentsList
and then in .../src/components/DynamicZone/CategoryItem.js
...
return (
<>
<Banner onClickToggle={onClickToggle} isFirst={isFirst} isOpen={isOpen} category={category} />
<Collapse isOpen={isOpen} onExited={handleExited}>
{showComponents && (
<ComponentsList className="componentsList">
{components.map(component => {
const {
info: { icon, name: friendlyName },
componentUid,
} = component;
return (
<DynamicComponentCard
key={componentUid}
componentUid={componentUid}
friendlyName={friendlyName}
icon={icon}
onClick={() => onClickComponent(componentUid)}
/>
);
})}
</ComponentsList>
)}
</Collapse>
</>
);
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HichamELBSI done in 5963e6c
return groupBy(componentsWithInfos, 'category'); | ||
}, [dynamicZoneAvailableComponents, getDynamicComponent]); | ||
|
||
// useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@misterdju can you make sure the DCO checks so we can merge your PR? |
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Nicolas Chesné <hello@norbz.net> Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
@soupette, I have done the commands suggested by the DCO checks. Is it ok for you ? |
@misterdju sure but it looks like you have unwanted commits in your PR which affects more than 100 files. Can you check? |
I think a rebase here instead of merging in the master should remove quite a bit of the conflicts as well as the various commits |
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
Signed-off-by: Julien Boudringhin <julien.boudringhin@gmail.com>
@soupette i think it is good now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@misterdju can you update your branch so we can merge the PR? |
This pull request has been mentioned on Strapi Community. There might be relevant details there: |
This RP corresponds to the development of the RFC (0019-dz-categories)
Hope this PR is ready to be merged :)