mirror of
https://github.com/strapi/strapi.git
synced 2025-09-17 20:40:17 +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 { get } from 'lodash';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Flex, Padded } from '@buffetjs/core';
|
import { Flex, Padded } from '@buffetjs/core';
|
||||||
@ -9,7 +9,7 @@ import ConditionsButton from '../../ConditionsButton';
|
|||||||
import HiddenAction from '../../HiddenAction';
|
import HiddenAction from '../../HiddenAction';
|
||||||
import Wrapper from './Wrapper';
|
import Wrapper from './Wrapper';
|
||||||
import RowLabel from '../../RowLabel';
|
import RowLabel from '../../RowLabel';
|
||||||
import { getCheckboxState } from '../../utils';
|
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
||||||
|
|
||||||
const Collapse = ({ availableActions, isActive, isGrey, name, onClickToggle, pathToData }) => {
|
const Collapse = ({ availableActions, isActive, isGrey, name, onClickToggle, pathToData }) => {
|
||||||
const { modifiedData } = usePermissionsDataManager();
|
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
|
// This corresponds to the data related to the CT left checkboxe
|
||||||
// modifiedData: { collectionTypes: { [ctuid]: {create: {fields: {f1: true} } } } }
|
// modifiedData: { collectionTypes: { [ctuid]: {create: {fields: {f1: true} } } } }
|
||||||
const mainData = get(modifiedData, pathToData.split('..'), {});
|
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 (
|
return (
|
||||||
<Wrapper isActive={isActive} isGrey={isGrey}>
|
<Wrapper isActive={isActive} isGrey={isGrey}>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { getCheckboxState } from '../../utils';
|
import { getCheckboxState, removeConditionKeyFromData } from '../../utils';
|
||||||
|
|
||||||
const getCheckboxesState = (properties, modifiedData) => {
|
const getCheckboxesState = (properties, modifiedData) => {
|
||||||
const actionsIds = properties.map(({ actionId }) => actionId);
|
const actionsIds = properties.map(({ actionId }) => actionId);
|
||||||
@ -8,7 +8,7 @@ const getCheckboxesState = (properties, modifiedData) => {
|
|||||||
Object.keys(modifiedData).forEach(ctUid => {
|
Object.keys(modifiedData).forEach(ctUid => {
|
||||||
const actionIdData = get(modifiedData, [ctUid, actionId], {});
|
const actionIdData = get(modifiedData, [ctUid, actionId], {});
|
||||||
|
|
||||||
const actionIdState = { [ctUid]: actionIdData };
|
const actionIdState = { [ctUid]: removeConditionKeyFromData(actionIdData) };
|
||||||
|
|
||||||
if (!acc[actionId]) {
|
if (!acc[actionId]) {
|
||||||
acc[actionId] = actionIdState;
|
acc[actionId] = actionIdState;
|
||||||
|
@ -14,6 +14,10 @@ const initialState = {
|
|||||||
images: true,
|
images: true,
|
||||||
city: true,
|
city: true,
|
||||||
},
|
},
|
||||||
|
conditions: {
|
||||||
|
'admin::is-creator': false,
|
||||||
|
'admin::has-same-role-as-creator': false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'content-manager.explorer.read': {
|
'content-manager.explorer.read': {
|
||||||
fields: {
|
fields: {
|
||||||
@ -23,6 +27,10 @@ const initialState = {
|
|||||||
images: true,
|
images: true,
|
||||||
city: true,
|
city: true,
|
||||||
},
|
},
|
||||||
|
conditions: {
|
||||||
|
'admin::is-creator': false,
|
||||||
|
'admin::has-same-role-as-creator': false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
'content-manager.explorer.update': {
|
'content-manager.explorer.update': {
|
||||||
fields: {
|
fields: {
|
||||||
@ -32,6 +40,10 @@ const initialState = {
|
|||||||
images: true,
|
images: true,
|
||||||
city: true,
|
city: true,
|
||||||
},
|
},
|
||||||
|
conditions: {
|
||||||
|
'admin::is-creator': false,
|
||||||
|
'admin::has-same-role-as-creator': false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
restaurant: {
|
restaurant: {
|
||||||
@ -86,6 +98,9 @@ const initialState = {
|
|||||||
const reducer = (state, action) =>
|
const reducer = (state, action) =>
|
||||||
produce(state, draftState => {
|
produce(state, draftState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case 'ON_CHANGE_TOGGLE_PARENT_CHECKBOX': {
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'ON_CHANGE_SIMPLE_CHECKBOX': {
|
case 'ON_CHANGE_SIMPLE_CHECKBOX': {
|
||||||
set(draftState, ['modifiedData', ...action.keys.split('..')], action.value);
|
set(draftState, ['modifiedData', ...action.keys.split('..')], action.value);
|
||||||
break;
|
break;
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import createArrayOfValues from './createArrayOfValues';
|
import createArrayOfValues from './createArrayOfValues';
|
||||||
|
import removeConditionKeyFromData from './removeConditionKeyFromData';
|
||||||
|
|
||||||
const getCheckboxState = data => {
|
const getCheckboxState = dataObj => {
|
||||||
const arrayOfValues = createArrayOfValues(data);
|
const dataWithoutCondition = removeConditionKeyFromData(dataObj);
|
||||||
|
|
||||||
|
const arrayOfValues = createArrayOfValues(dataWithoutCondition);
|
||||||
|
|
||||||
if (!arrayOfValues.length) {
|
if (!arrayOfValues.length) {
|
||||||
return { hasAllActionsSelected: false, hasSomeActionsSelected: false };
|
return { hasAllActionsSelected: false, hasSomeActionsSelected: false };
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
export { default as getCheckboxState } from './getCheckboxState';
|
export { default as getCheckboxState } from './getCheckboxState';
|
||||||
export { default as createArrayOfValues } from './createArrayOfValues';
|
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