2021-02-11 18:56:14 +01:00
|
|
|
import createArrayOfValues from './createArrayOfValues';
|
2021-02-12 09:52:06 +01:00
|
|
|
import removeConditionKeyFromData from './removeConditionKeyFromData';
|
2021-02-11 18:56:14 +01:00
|
|
|
|
2021-02-12 09:52:06 +01:00
|
|
|
const getCheckboxState = dataObj => {
|
|
|
|
const dataWithoutCondition = removeConditionKeyFromData(dataObj);
|
|
|
|
|
|
|
|
const arrayOfValues = createArrayOfValues(dataWithoutCondition);
|
2021-02-11 18:56:14 +01:00
|
|
|
|
|
|
|
if (!arrayOfValues.length) {
|
|
|
|
return { hasAllActionsSelected: false, hasSomeActionsSelected: false };
|
|
|
|
}
|
|
|
|
|
|
|
|
const hasAllActionsSelected = arrayOfValues.every(val => val);
|
|
|
|
const hasSomeActionsSelected = arrayOfValues.some(val => val) && !hasAllActionsSelected;
|
|
|
|
|
|
|
|
return { hasAllActionsSelected, hasSomeActionsSelected };
|
|
|
|
};
|
|
|
|
|
|
|
|
export default getCheckboxState;
|