mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +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 Ul from './Ul';
 | 
			
		||||
import hasSubArray from './utils/hasSubArray';
 | 
			
		||||
import hasSomeSubArray from './utils/HasSomeSubArray';
 | 
			
		||||
 | 
			
		||||
const MultipleMenuList = ({
 | 
			
		||||
  selectProps: { name, addComponentsToDynamicZone, /*refState, */ value },
 | 
			
		||||
@ -52,6 +53,12 @@ const MultipleMenuList = ({
 | 
			
		||||
    return hasSubArray(value.value, componentsCategory);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const doesCategoryHasSomeElements = categoryName => {
 | 
			
		||||
    const componentsCategory = allComponentsCategory[categoryName];
 | 
			
		||||
 | 
			
		||||
    return hasSomeSubArray(value.value, componentsCategory);
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const handleChangeCategory = ({ target }) => {
 | 
			
		||||
    // refState.current.select.blur();
 | 
			
		||||
    const dataTarget = {
 | 
			
		||||
@ -81,6 +88,8 @@ const MultipleMenuList = ({
 | 
			
		||||
      >
 | 
			
		||||
        {Object.keys(componentsGroupedByCategory).map(categoryName => {
 | 
			
		||||
          const isChecked = getCategoryValue(categoryName);
 | 
			
		||||
          const someChecked =
 | 
			
		||||
            !isChecked && doesCategoryHasSomeElements(categoryName);
 | 
			
		||||
          const target = { name: categoryName, value: !isChecked };
 | 
			
		||||
 | 
			
		||||
          return (
 | 
			
		||||
@ -95,9 +104,10 @@ const MultipleMenuList = ({
 | 
			
		||||
                  >
 | 
			
		||||
                    <Checkbox
 | 
			
		||||
                      id="checkCategory"
 | 
			
		||||
                      checked={isChecked}
 | 
			
		||||
                      name={categoryName}
 | 
			
		||||
                      onChange={() => {}}
 | 
			
		||||
                      checked={getCategoryValue(categoryName)}
 | 
			
		||||
                      someChecked={someChecked}
 | 
			
		||||
                      style={{ marginRight: 10 }}
 | 
			
		||||
                    />
 | 
			
		||||
                    <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