mirror of
https://github.com/strapi/strapi.git
synced 2025-11-12 16:22:10 +00:00
Add some checked state to component picker
This commit is contained in:
parent
a1da290d42
commit
3a9b64df6a
@ -9,6 +9,7 @@ import UpperFirst from '../UpperFirst';
|
|||||||
import SubUl from './SubUl';
|
import SubUl from './SubUl';
|
||||||
import Ul from './Ul';
|
import Ul from './Ul';
|
||||||
import hasSubArray from './utils/hasSubArray';
|
import hasSubArray from './utils/hasSubArray';
|
||||||
|
import hasSomeSubArray from './utils/HasSomeSubArray';
|
||||||
|
|
||||||
const MultipleMenuList = ({
|
const MultipleMenuList = ({
|
||||||
selectProps: { name, addComponentsToDynamicZone, /*refState, */ value },
|
selectProps: { name, addComponentsToDynamicZone, /*refState, */ value },
|
||||||
@ -52,6 +53,12 @@ const MultipleMenuList = ({
|
|||||||
return hasSubArray(value.value, componentsCategory);
|
return hasSubArray(value.value, componentsCategory);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const doesCategoryHasSomeElements = categoryName => {
|
||||||
|
const componentsCategory = allComponentsCategory[categoryName];
|
||||||
|
|
||||||
|
return hasSomeSubArray(value.value, componentsCategory);
|
||||||
|
};
|
||||||
|
|
||||||
const handleChangeCategory = ({ target }) => {
|
const handleChangeCategory = ({ target }) => {
|
||||||
// refState.current.select.blur();
|
// refState.current.select.blur();
|
||||||
const dataTarget = {
|
const dataTarget = {
|
||||||
@ -81,6 +88,8 @@ const MultipleMenuList = ({
|
|||||||
>
|
>
|
||||||
{Object.keys(componentsGroupedByCategory).map(categoryName => {
|
{Object.keys(componentsGroupedByCategory).map(categoryName => {
|
||||||
const isChecked = getCategoryValue(categoryName);
|
const isChecked = getCategoryValue(categoryName);
|
||||||
|
const someChecked =
|
||||||
|
!isChecked && doesCategoryHasSomeElements(categoryName);
|
||||||
const target = { name: categoryName, value: !isChecked };
|
const target = { name: categoryName, value: !isChecked };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -95,9 +104,10 @@ const MultipleMenuList = ({
|
|||||||
>
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
id="checkCategory"
|
id="checkCategory"
|
||||||
|
checked={isChecked}
|
||||||
name={categoryName}
|
name={categoryName}
|
||||||
onChange={() => {}}
|
onChange={() => {}}
|
||||||
checked={getCategoryValue(categoryName)}
|
someChecked={someChecked}
|
||||||
style={{ marginRight: 10 }}
|
style={{ marginRight: 10 }}
|
||||||
/>
|
/>
|
||||||
<UpperFirst content={categoryName} />
|
<UpperFirst content={categoryName} />
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
const hasSomeSubArray = (master, sub) => {
|
||||||
|
return sub.some(v => master.indexOf(v) !== -1);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default hasSomeSubArray;
|
||||||
Loading…
x
Reference in New Issue
Block a user