mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 12:27:33 +00:00
Add conditions to reducer
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
d51746e7b5
commit
a147590cad
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import { get } from 'lodash';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Flex, Padded } from '@buffetjs/core';
|
||||
@ -9,7 +9,7 @@ import ConditionsButton from '../../ConditionsButton';
|
||||
import HiddenAction from '../../HiddenAction';
|
||||
import Wrapper from './Wrapper';
|
||||
import RowLabel from '../../RowLabel';
|
||||
import { getCheckboxState } from '../../utils';
|
||||
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
||||
|
||||
const Collapse = ({ availableActions, isActive, isGrey, name, onClickToggle, pathToData }) => {
|
||||
const { modifiedData } = usePermissionsDataManager();
|
||||
@ -17,7 +17,14 @@ const Collapse = ({ availableActions, isActive, isGrey, name, onClickToggle, pat
|
||||
// This corresponds to the data related to the CT left checkboxe
|
||||
// modifiedData: { collectionTypes: { [ctuid]: {create: {fields: {f1: true} } } } }
|
||||
const mainData = get(modifiedData, pathToData.split('..'), {});
|
||||
const { hasAllActionsSelected, hasSomeActionsSelected } = getCheckboxState(mainData);
|
||||
const dataWithoutCondition = useMemo(() => {
|
||||
return Object.keys(mainData).reduce((acc, current) => {
|
||||
acc[current] = removeConditionKeyFromData(mainData[current]);
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}, [mainData]);
|
||||
const { hasAllActionsSelected, hasSomeActionsSelected } = getCheckboxState(dataWithoutCondition);
|
||||
|
||||
return (
|
||||
<Wrapper isActive={isActive} isGrey={isGrey}>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { get } from 'lodash';
|
||||
import { getCheckboxState } from '../../utils';
|
||||
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
||||
|
||||
const getCheckboxesState = (properties, modifiedData) => {
|
||||
const actionsIds = properties.map(({ actionId }) => actionId);
|
||||
@ -8,7 +8,7 @@ const getCheckboxesState = (properties, modifiedData) => {
|
||||
Object.keys(modifiedData).forEach(ctUid => {
|
||||
const actionIdData = get(modifiedData, [ctUid, actionId], {});
|
||||
|
||||
const actionIdState = { [ctUid]: actionIdData };
|
||||
const actionIdState = { [ctUid]: removeConditionKeyFromData(actionIdData) };
|
||||
|
||||
if (!acc[actionId]) {
|
||||
acc[actionId] = actionIdState;
|
||||
|
@ -14,6 +14,10 @@ const initialState = {
|
||||
images: true,
|
||||
city: true,
|
||||
},
|
||||
conditions: {
|
||||
'admin::is-creator': false,
|
||||
'admin::has-same-role-as-creator': false,
|
||||
},
|
||||
},
|
||||
'content-manager.explorer.read': {
|
||||
fields: {
|
||||
@ -23,6 +27,10 @@ const initialState = {
|
||||
images: true,
|
||||
city: true,
|
||||
},
|
||||
conditions: {
|
||||
'admin::is-creator': false,
|
||||
'admin::has-same-role-as-creator': false,
|
||||
},
|
||||
},
|
||||
'content-manager.explorer.update': {
|
||||
fields: {
|
||||
@ -32,6 +40,10 @@ const initialState = {
|
||||
images: true,
|
||||
city: true,
|
||||
},
|
||||
conditions: {
|
||||
'admin::is-creator': false,
|
||||
'admin::has-same-role-as-creator': false,
|
||||
},
|
||||
},
|
||||
},
|
||||
restaurant: {
|
||||
@ -86,6 +98,9 @@ const initialState = {
|
||||
const reducer = (state, action) =>
|
||||
produce(state, draftState => {
|
||||
switch (action.type) {
|
||||
case 'ON_CHANGE_TOGGLE_PARENT_CHECKBOX': {
|
||||
break;
|
||||
}
|
||||
case 'ON_CHANGE_SIMPLE_CHECKBOX': {
|
||||
set(draftState, ['modifiedData', ...action.keys.split('..')], action.value);
|
||||
break;
|
||||
|
@ -1,7 +1,10 @@
|
||||
import createArrayOfValues from './createArrayOfValues';
|
||||
import removeConditionKeyFromData from './removeConditionKeyFromData';
|
||||
|
||||
const getCheckboxState = data => {
|
||||
const arrayOfValues = createArrayOfValues(data);
|
||||
const getCheckboxState = dataObj => {
|
||||
const dataWithoutCondition = removeConditionKeyFromData(dataObj);
|
||||
|
||||
const arrayOfValues = createArrayOfValues(dataWithoutCondition);
|
||||
|
||||
if (!arrayOfValues.length) {
|
||||
return { hasAllActionsSelected: false, hasSomeActionsSelected: false };
|
||||
|
@ -1,2 +1,3 @@
|
||||
export { default as getCheckboxState } from './getCheckboxState';
|
||||
export { default as createArrayOfValues } from './createArrayOfValues';
|
||||
export { default as removeConditionKeyFromData } from './removeConditionKeyFromData';
|
||||
|
@ -0,0 +1,15 @@
|
||||
const removeConditionKeyFromData = obj => {
|
||||
if (!obj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Object.keys(obj).reduce((acc, current) => {
|
||||
if (current !== 'conditions') {
|
||||
acc[current] = obj[current];
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
export default removeConditionKeyFromData;
|
Loading…
x
Reference in New Issue
Block a user