@carbon/ibm-products 2.43.2-canary.116 → 2.43.2-canary.118

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { slicedToArray as _slicedToArray, extends as _extends, defineProperty as _defineProperty, objectSpread2 as _objectSpread2 } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useContext, useState, useEffect } from 'react';
9
+ import React__default, { useContext, useState } from 'react';
10
10
  import { Close } from '@carbon/react/icons';
11
11
  import { ConditionBuilderItem } from '../ConditionBuilderItem/ConditionBuilderItem.js';
12
12
  import PropTypes from '../../../node_modules/prop-types/index.js';
@@ -52,8 +52,7 @@ var ConditionBlock = function ConditionBlock(props) {
52
52
  showConditionSubGroupPreviewHandler = props.showConditionSubGroupPreviewHandler,
53
53
  hideConditionPreviewHandler = props.hideConditionPreviewHandler,
54
54
  showConditionPreviewHandler = props.showConditionPreviewHandler,
55
- isLastCondition = props.isLastCondition,
56
- setShowDeletionPreviewForSubgroups = props.setShowDeletionPreviewForSubgroups;
55
+ isLastCondition = props.isLastCondition;
57
56
  var _useContext = useContext(ConditionBuilderContext),
58
57
  inputConfig = _useContext.inputConfig,
59
58
  variant = _useContext.variant,
@@ -62,6 +61,10 @@ var ConditionBlock = function ConditionBlock(props) {
62
61
  _useState2 = _slicedToArray(_useState, 2),
63
62
  showDeletionPreview = _useState2[0],
64
63
  setShowDeletionPreview = _useState2[1];
64
+ var _useState3 = useState(false),
65
+ _useState4 = _slicedToArray(_useState3, 2),
66
+ showAllActions = _useState4[0],
67
+ setShowAllActions = _useState4[1];
65
68
  var _useTranslations = useTranslations(['conditionRowText', 'conditionText', 'propertyText', 'operatorText', 'removeConditionText']),
66
69
  _useTranslations2 = _slicedToArray(_useTranslations, 5),
67
70
  conditionRowText = _useTranslations2[0],
@@ -94,15 +97,12 @@ var ConditionBlock = function ConditionBlock(props) {
94
97
  textarea: ConditionBuilderItemText
95
98
  };
96
99
  var ItemComponent = property ? itemComponents[type] : null;
97
- useEffect(function () {
98
- var _group$conditions, _group$conditions2;
99
- if (showDeletionPreview && (group === null || group === void 0 || (_group$conditions = group.conditions) === null || _group$conditions === void 0 ? void 0 : _group$conditions.length) > 1 && group !== null && group !== void 0 && (_group$conditions2 = group.conditions) !== null && _group$conditions2 !== void 0 && _group$conditions2[1].conditions && group.conditions[1].id !== condition.id) {
100
- setShowDeletionPreviewForSubgroups === null || setShowDeletionPreviewForSubgroups === void 0 || setShowDeletionPreviewForSubgroups(true);
101
- } else {
102
- setShowDeletionPreviewForSubgroups === null || setShowDeletionPreviewForSubgroups === void 0 || setShowDeletionPreviewForSubgroups(false);
103
- }
104
- // eslint-disable-next-line react-hooks/exhaustive-deps
105
- }, [showDeletionPreview]);
100
+ var showAllActionsHandler = function showAllActionsHandler() {
101
+ setShowAllActions(true);
102
+ };
103
+ var hideAllActionsHandler = function hideAllActionsHandler() {
104
+ setShowAllActions(false);
105
+ };
106
106
  var onStatementChangeHandler = function onStatementChangeHandler(v, evt) {
107
107
  focusThisField(evt, conditionBuilderRef);
108
108
  onStatementChange(v);
@@ -135,6 +135,12 @@ var ConditionBlock = function ConditionBlock(props) {
135
135
  var handleHideDeletionPreview = function handleHideDeletionPreview() {
136
136
  setShowDeletionPreview(false);
137
137
  };
138
+ var manageActionButtons = function manageActionButtons(conditionIndex, conditions) {
139
+ if (variant === 'tree') {
140
+ return true;
141
+ }
142
+ return isLastCondition(conditionIndex, conditions);
143
+ };
138
144
  var getOperators = function getOperators() {
139
145
  if (config !== null && config !== void 0 && config.operators) {
140
146
  return config.operators;
@@ -165,10 +171,15 @@ var ConditionBlock = function ConditionBlock(props) {
165
171
  });
166
172
  };
167
173
  return /*#__PURE__*/React__default.createElement("div", _extends({
168
- className: cx("".concat(blockClass, "__condition-block"), _defineProperty({}, "".concat(blockClass, "__condition__deletion-preview"), showDeletionPreview), _defineProperty({}, "".concat(blockClass, "__gap-bottom"), variant == 'tree' && !(conditionIndex + 1 >= group.conditions.length)), _defineProperty({}, "".concat(blockClass, "__gap ").concat(blockClass, "__gap-bottom"), variant == 'sentence')),
174
+ className: cx("".concat(blockClass, "__condition-block"), _defineProperty({}, "".concat(blockClass, "__condition__deletion-preview"), showDeletionPreview), _defineProperty({}, "".concat(blockClass, "__gap-bottom"), variant == 'tree'), _defineProperty({}, "".concat(blockClass, "__gap ").concat(blockClass, "__gap-bottom"), variant == 'sentence'), _defineProperty({}, "".concat(blockClass, "__condition--interacting"), showAllActions)),
169
175
  role: "row",
170
176
  "aria-label": conditionRowText
171
- }, getAriaAttributes()), conjunction ? /*#__PURE__*/React__default.createElement(ConditionConnector, {
177
+ }, getAriaAttributes(), {
178
+ tabIndex: -1,
179
+ onMouseEnter: showAllActionsHandler,
180
+ onMouseLeave: hideAllActionsHandler,
181
+ onBlur: hideAllActionsHandler
182
+ }), conjunction ? /*#__PURE__*/React__default.createElement(ConditionConnector, {
172
183
  className: "".concat(blockClass, "__gap"),
173
184
  operator: conjunction,
174
185
  onChange: function onChange(op) {
@@ -181,7 +192,8 @@ var ConditionBlock = function ConditionBlock(props) {
181
192
  title: conditionText,
182
193
  "data-name": "connectorField",
183
194
  popOverClassName: "".concat(blockClass, "__gap"),
184
- className: "".concat(blockClass, "__statement-button")
195
+ className: "".concat(blockClass, "__statement-button"),
196
+ tabIndex: 0
185
197
  }, /*#__PURE__*/React__default.createElement(ItemOption, {
186
198
  conditionState: {
187
199
  value: group.statement,
@@ -249,7 +261,7 @@ var ConditionBlock = function ConditionBlock(props) {
249
261
  renderIcon: Close,
250
262
  className: "".concat(blockClass, "__close-condition"),
251
263
  "data-name": "closeCondition"
252
- })), isLastCondition(conditionIndex, group.conditions) && /*#__PURE__*/React__default.createElement(ConditionBuilderAdd, {
264
+ })), manageActionButtons(conditionIndex, group.conditions) && /*#__PURE__*/React__default.createElement(ConditionBuilderAdd, {
253
265
  onClick: function onClick() {
254
266
  addConditionHandler(conditionIndex);
255
267
  },
@@ -317,10 +329,6 @@ ConditionBlock.propTypes = {
317
329
  * callback to handle the statement(if/ excl.if) change
318
330
  */
319
331
  onStatementChange: PropTypes.func,
320
- /**
321
- * method to set ShowDeletionPreviewForSubgroups
322
- */
323
- setShowDeletionPreviewForSubgroups: PropTypes.func,
324
332
  /**
325
333
  * handler for showing add condition preview
326
334
  */
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { slicedToArray as _slicedToArray, extends as _extends, defineProperty as _defineProperty } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useState } from 'react';
8
+ import { slicedToArray as _slicedToArray, extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
+ import React__default from 'react';
10
10
  import cx from 'classnames';
11
11
  import { AddAlt, TextNewLine } from '@carbon/react/icons';
12
12
  import { ConditionBuilderButton } from '../ConditionBuilderButton/ConditionBuilderButton.js';
@@ -25,21 +25,11 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
25
25
  enableSubGroup = _ref.enableSubGroup,
26
26
  buttonLabel = _ref.buttonLabel,
27
27
  tabIndex = _ref.tabIndex;
28
- var _useState = useState(false),
29
- _useState2 = _slicedToArray(_useState, 2),
30
- isAddSubgroup = _useState2[0],
31
- setIsAddSubgroup = _useState2[1];
32
28
  var _useTranslations = useTranslations(['addConditionText', 'addConditionRowText', 'addSubgroupText']),
33
29
  _useTranslations2 = _slicedToArray(_useTranslations, 3),
34
30
  addConditionText = _useTranslations2[0],
35
31
  addConditionRowText = _useTranslations2[1],
36
32
  addSubgroupText = _useTranslations2[2];
37
- var showAddSubGroup = function showAddSubGroup() {
38
- setIsAddSubgroup(true);
39
- };
40
- var hideAddSubGroup = function hideAddSubGroup() {
41
- setIsAddSubgroup(false);
42
- };
43
33
  var onClickHandler = function onClickHandler() {
44
34
  hideConditionPreviewHandler === null || hideConditionPreviewHandler === void 0 || hideConditionPreviewHandler();
45
35
  onClick();
@@ -69,11 +59,7 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
69
59
  return /*#__PURE__*/React__default.createElement("div", {
70
60
  className: "".concat(className, " ").concat(blockClass, "__add-button-wrapper"),
71
61
  role: !enableSubGroup ? 'gridcell' : 'none',
72
- "aria-label": getAriaLabel(),
73
- onMouseEnter: showAddSubGroup,
74
- onMouseLeave: hideAddSubGroup,
75
- onFocus: showAddSubGroup,
76
- onBlur: hideAddSubGroup
62
+ "aria-label": getAriaLabel()
77
63
  }, /*#__PURE__*/React__default.createElement(ConditionBuilderButton, _extends({
78
64
  renderIcon: AddAlt,
79
65
  onClick: onClickHandler
@@ -83,7 +69,8 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
83
69
  hideLabel: true,
84
70
  "data-name": "addButton",
85
71
  label: buttonLabel !== null && buttonLabel !== void 0 ? buttonLabel : addConditionText,
86
- tabIndex: tabIndex
72
+ tabIndex: tabIndex,
73
+ wrapperClassName: "".concat(blockClass, "__add-condition-wrapper")
87
74
  })), enableSubGroup && /*#__PURE__*/React__default.createElement(ConditionBuilderButton, _extends({
88
75
  renderIcon: TextNewLine,
89
76
  onClick: addConditionSubGroupHandler,
@@ -91,7 +78,7 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
91
78
  hideLabel: true,
92
79
  label: addSubgroupText,
93
80
  wrapperProps: wrapperProps,
94
- wrapperClassName: cx("".concat(blockClass, "__add-condition-sub-group-wrapper ").concat(blockClass, "__gap-left"), _defineProperty({}, "".concat(blockClass, "__add-condition-sub-group-wrapper--show"), isAddSubgroup))
81
+ wrapperClassName: "".concat(blockClass, "__add-condition-sub-group-wrapper ").concat(blockClass, "__gap-left")
95
82
  }, previewHandlersForSubgroup())));
96
83
  };
97
84
  var ConditionBuilderAdd$1 = ConditionBuilderAdd;
@@ -50,56 +50,50 @@ var ConditionGroupBuilder = function ConditionGroupBuilder(_ref) {
50
50
  _useState4 = _slicedToArray(_useState3, 2),
51
51
  showConditionSubGroupPreview = _useState4[0],
52
52
  setShowConditionSubGroupPreview = _useState4[1];
53
- var _useState5 = useState(false),
54
- _useState6 = _slicedToArray(_useState5, 2),
55
- showDeletionPreviewForSubgroups = _useState6[0],
56
- setShowDeletionPreviewForSubgroups = _useState6[1];
53
+ useState(false);
57
54
  var conditionBuilderContentRef = useRef();
58
55
  var onRemoveHandler = function onRemoveHandler(conditionId, evt, conditionIndex) {
59
56
  if (group.conditions.length > 1) {
60
57
  variant == 'tree' ? handleFocusOnCloseTree(evt) : handleFocusOnClose(evt, conditionIndex);
61
- if (group.conditions[1].conditions && group.conditions[1].id !== conditionId) {
62
- //when we remove every plain conditions of a group without deleting the subgroup, we need to restructure the group
63
- //the inner group become outer group and same level subgroups become plain conditions
64
-
65
- //ensure we are deleting last condition , not the subgroup
58
+ if (!checkGroupHaveCondition(group.conditions, conditionId)) {
59
+ //when we delete the last condition of a group without deleting the subgroup, we need to restructure the group.
60
+ //we will shift the group one level up. The subgroups will open up as conditions.
66
61
 
67
62
  //spreading out the condition inside the subgroup
68
- var allConditions = group.conditions.reduce(function (acc, item) {
69
- if (item.conditions) {
70
- return acc.concat(item.conditions);
63
+ var allConditions = group.conditions.reduce(function (acc, condition) {
64
+ if (condition.conditions) {
65
+ //this is a subgroup
66
+ return acc.concat(condition.conditions);
71
67
  }
72
68
  return acc;
73
69
  }, []);
74
-
75
- //we always have conditions first and then subgroups, so ordering accordingly
76
- var groupedItems = {
77
- groups: [],
78
- conditions: []
79
- };
80
- allConditions.forEach(function (item) {
81
- if (item.conditions) {
82
- groupedItems.groups.push(item);
83
- } else {
84
- groupedItems.conditions.push(item);
85
- }
86
- });
87
- onRemove(evt);
88
- // onChange({
89
- // ...group,
90
- // conditions: [...groupedItems.conditions, ...groupedItems.groups],
91
- // });
70
+ onChange(_objectSpread2(_objectSpread2({}, group), {}, {
71
+ conditions: allConditions
72
+ }));
92
73
  } else {
74
+ var filteredConditions = group.conditions.filter(function (condition) {
75
+ return conditionId !== condition.id;
76
+ });
77
+ //This is to handle a edge case.
78
+ //When a group has structure as 1 condition,1 subgroup, 1 condition and if we delete first condition,
79
+ //the group will start with a subgroup. To avoid this,opening up that subgroup.
80
+ if (filteredConditions !== null && filteredConditions !== void 0 && filteredConditions[0].conditions) {
81
+ filteredConditions.splice.apply(filteredConditions, [0, 1].concat(_toConsumableArray(filteredConditions[0].conditions)));
82
+ }
93
83
  onChange(_objectSpread2(_objectSpread2({}, group), {}, {
94
- conditions: group.conditions.filter(function (condition) {
95
- return conditionId !== condition.id;
96
- })
84
+ conditions: filteredConditions
97
85
  }));
98
86
  }
99
87
  } else {
100
88
  onRemove(evt);
101
89
  }
102
90
  };
91
+ //check to identify a group without a plain condition
92
+ var checkGroupHaveCondition = function checkGroupHaveCondition(conditions, conditionId) {
93
+ return conditions.find(function (eachCondition) {
94
+ return !eachCondition.conditions && eachCondition.id !== conditionId;
95
+ });
96
+ };
103
97
  var onChangeHandler = function onChangeHandler(updatedCondition, conditionIndex) {
104
98
  var updatedConditions = [].concat(_toConsumableArray(group.conditions.slice(0, conditionIndex)), [updatedCondition], _toConsumableArray(group.conditions.slice(conditionIndex + 1)));
105
99
  onChange(_objectSpread2(_objectSpread2({}, group), {}, {
@@ -286,7 +280,7 @@ var ConditionGroupBuilder = function ConditionGroupBuilder(_ref) {
286
280
  return /*#__PURE__*/React__default.createElement(Fragment, {
287
281
  key: eachCondition.id
288
282
  }, eachCondition.conditions ? /*#__PURE__*/React__default.createElement("div", {
289
- className: cx("".concat(blockClass, "__condition-block subgroup ").concat(blockClass, "__gap"), _defineProperty(_defineProperty({}, "".concat(blockClass, "__gap-bottom"), group.conditions.length < conditionIndex + 1), "".concat(blockClass, "__subgroup_deletionPreview"), showDeletionPreviewForSubgroups), {})
283
+ className: cx("".concat(blockClass, "__condition-block subgroup ").concat(blockClass, "__gap"), _defineProperty({}, "".concat(blockClass, "__gap-bottom"), group.conditions.length < conditionIndex + 1), {})
290
284
  }, /*#__PURE__*/React__default.createElement(ConditionConnector, {
291
285
  className: "".concat(blockClass, "__gap ").concat(blockClass, "__gap-bottom ").concat(blockClass, "__groupConnector"),
292
286
  operator: group.groupOperator,
@@ -334,8 +328,7 @@ var ConditionGroupBuilder = function ConditionGroupBuilder(_ref) {
334
328
  _showConditionPreviewHandler(conditionIndex);
335
329
  },
336
330
  hideConditionPreviewHandler: hideConditionPreviewHandler,
337
- isLastCondition: isLastCondition,
338
- setShowDeletionPreviewForSubgroups: setShowDeletionPreviewForSubgroups
331
+ isLastCondition: isLastCondition
339
332
  })), conditionIndex == showConditionSubGroupPreview && (_ConditionPreview || (_ConditionPreview = /*#__PURE__*/React__default.createElement(ConditionPreview, {
340
333
  previewType: "subGroup",
341
334
  group: group
@@ -20,7 +20,6 @@ declare namespace ConditionBlock {
20
20
  let onConnectorOperatorChange: PropTypes.Requireable<(...args: any[]) => any>;
21
21
  let onRemove: PropTypes.Requireable<(...args: any[]) => any>;
22
22
  let onStatementChange: PropTypes.Requireable<(...args: any[]) => any>;
23
- let setShowDeletionPreviewForSubgroups: PropTypes.Requireable<(...args: any[]) => any>;
24
23
  let showConditionPreviewHandler: PropTypes.Requireable<(...args: any[]) => any>;
25
24
  let showConditionSubGroupPreviewHandler: PropTypes.Requireable<(...args: any[]) => any>;
26
25
  let state: PropTypes.Requireable<object>;
@@ -61,8 +61,7 @@ var ConditionBlock = function ConditionBlock(props) {
61
61
  showConditionSubGroupPreviewHandler = props.showConditionSubGroupPreviewHandler,
62
62
  hideConditionPreviewHandler = props.hideConditionPreviewHandler,
63
63
  showConditionPreviewHandler = props.showConditionPreviewHandler,
64
- isLastCondition = props.isLastCondition,
65
- setShowDeletionPreviewForSubgroups = props.setShowDeletionPreviewForSubgroups;
64
+ isLastCondition = props.isLastCondition;
66
65
  var _useContext = React.useContext(ConditionBuilderProvider.ConditionBuilderContext),
67
66
  inputConfig = _useContext.inputConfig,
68
67
  variant = _useContext.variant,
@@ -71,6 +70,10 @@ var ConditionBlock = function ConditionBlock(props) {
71
70
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
72
71
  showDeletionPreview = _useState2[0],
73
72
  setShowDeletionPreview = _useState2[1];
73
+ var _useState3 = React.useState(false),
74
+ _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
75
+ showAllActions = _useState4[0],
76
+ setShowAllActions = _useState4[1];
74
77
  var _useTranslations = useTranslations.useTranslations(['conditionRowText', 'conditionText', 'propertyText', 'operatorText', 'removeConditionText']),
75
78
  _useTranslations2 = _rollupPluginBabelHelpers.slicedToArray(_useTranslations, 5),
76
79
  conditionRowText = _useTranslations2[0],
@@ -103,15 +106,12 @@ var ConditionBlock = function ConditionBlock(props) {
103
106
  textarea: ConditionBuilderItemText.ConditionBuilderItemText
104
107
  };
105
108
  var ItemComponent = property ? itemComponents[type] : null;
106
- React.useEffect(function () {
107
- var _group$conditions, _group$conditions2;
108
- if (showDeletionPreview && (group === null || group === void 0 || (_group$conditions = group.conditions) === null || _group$conditions === void 0 ? void 0 : _group$conditions.length) > 1 && group !== null && group !== void 0 && (_group$conditions2 = group.conditions) !== null && _group$conditions2 !== void 0 && _group$conditions2[1].conditions && group.conditions[1].id !== condition.id) {
109
- setShowDeletionPreviewForSubgroups === null || setShowDeletionPreviewForSubgroups === void 0 || setShowDeletionPreviewForSubgroups(true);
110
- } else {
111
- setShowDeletionPreviewForSubgroups === null || setShowDeletionPreviewForSubgroups === void 0 || setShowDeletionPreviewForSubgroups(false);
112
- }
113
- // eslint-disable-next-line react-hooks/exhaustive-deps
114
- }, [showDeletionPreview]);
109
+ var showAllActionsHandler = function showAllActionsHandler() {
110
+ setShowAllActions(true);
111
+ };
112
+ var hideAllActionsHandler = function hideAllActionsHandler() {
113
+ setShowAllActions(false);
114
+ };
115
115
  var onStatementChangeHandler = function onStatementChangeHandler(v, evt) {
116
116
  util.focusThisField(evt, conditionBuilderRef);
117
117
  onStatementChange(v);
@@ -144,6 +144,12 @@ var ConditionBlock = function ConditionBlock(props) {
144
144
  var handleHideDeletionPreview = function handleHideDeletionPreview() {
145
145
  setShowDeletionPreview(false);
146
146
  };
147
+ var manageActionButtons = function manageActionButtons(conditionIndex, conditions) {
148
+ if (variant === 'tree') {
149
+ return true;
150
+ }
151
+ return isLastCondition(conditionIndex, conditions);
152
+ };
147
153
  var getOperators = function getOperators() {
148
154
  if (config !== null && config !== void 0 && config.operators) {
149
155
  return config.operators;
@@ -174,10 +180,15 @@ var ConditionBlock = function ConditionBlock(props) {
174
180
  });
175
181
  };
176
182
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
177
- className: cx__default["default"]("".concat(DataConfigs.blockClass, "__condition-block"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__condition__deletion-preview"), showDeletionPreview), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap-bottom"), variant == 'tree' && !(conditionIndex + 1 >= group.conditions.length)), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap ").concat(DataConfigs.blockClass, "__gap-bottom"), variant == 'sentence')),
183
+ className: cx__default["default"]("".concat(DataConfigs.blockClass, "__condition-block"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__condition__deletion-preview"), showDeletionPreview), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap-bottom"), variant == 'tree'), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap ").concat(DataConfigs.blockClass, "__gap-bottom"), variant == 'sentence'), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__condition--interacting"), showAllActions)),
178
184
  role: "row",
179
185
  "aria-label": conditionRowText
180
- }, getAriaAttributes()), conjunction ? /*#__PURE__*/React__default["default"].createElement(ConditionConnector["default"], {
186
+ }, getAriaAttributes(), {
187
+ tabIndex: -1,
188
+ onMouseEnter: showAllActionsHandler,
189
+ onMouseLeave: hideAllActionsHandler,
190
+ onBlur: hideAllActionsHandler
191
+ }), conjunction ? /*#__PURE__*/React__default["default"].createElement(ConditionConnector["default"], {
181
192
  className: "".concat(DataConfigs.blockClass, "__gap"),
182
193
  operator: conjunction,
183
194
  onChange: function onChange(op) {
@@ -190,7 +201,8 @@ var ConditionBlock = function ConditionBlock(props) {
190
201
  title: conditionText,
191
202
  "data-name": "connectorField",
192
203
  popOverClassName: "".concat(DataConfigs.blockClass, "__gap"),
193
- className: "".concat(DataConfigs.blockClass, "__statement-button")
204
+ className: "".concat(DataConfigs.blockClass, "__statement-button"),
205
+ tabIndex: 0
194
206
  }, /*#__PURE__*/React__default["default"].createElement(ItemOption.ItemOption, {
195
207
  conditionState: {
196
208
  value: group.statement,
@@ -258,7 +270,7 @@ var ConditionBlock = function ConditionBlock(props) {
258
270
  renderIcon: icons.Close,
259
271
  className: "".concat(DataConfigs.blockClass, "__close-condition"),
260
272
  "data-name": "closeCondition"
261
- })), isLastCondition(conditionIndex, group.conditions) && /*#__PURE__*/React__default["default"].createElement(ConditionBuilderAdd["default"], {
273
+ })), manageActionButtons(conditionIndex, group.conditions) && /*#__PURE__*/React__default["default"].createElement(ConditionBuilderAdd["default"], {
262
274
  onClick: function onClick() {
263
275
  addConditionHandler(conditionIndex);
264
276
  },
@@ -326,10 +338,6 @@ ConditionBlock.propTypes = {
326
338
  * callback to handle the statement(if/ excl.if) change
327
339
  */
328
340
  onStatementChange: index["default"].func,
329
- /**
330
- * method to set ShowDeletionPreviewForSubgroups
331
- */
332
- setShowDeletionPreviewForSubgroups: index["default"].func,
333
341
  /**
334
342
  * handler for showing add condition preview
335
343
  */
@@ -34,21 +34,11 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
34
34
  enableSubGroup = _ref.enableSubGroup,
35
35
  buttonLabel = _ref.buttonLabel,
36
36
  tabIndex = _ref.tabIndex;
37
- var _useState = React.useState(false),
38
- _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
39
- isAddSubgroup = _useState2[0],
40
- setIsAddSubgroup = _useState2[1];
41
37
  var _useTranslations = useTranslations.useTranslations(['addConditionText', 'addConditionRowText', 'addSubgroupText']),
42
38
  _useTranslations2 = _rollupPluginBabelHelpers.slicedToArray(_useTranslations, 3),
43
39
  addConditionText = _useTranslations2[0],
44
40
  addConditionRowText = _useTranslations2[1],
45
41
  addSubgroupText = _useTranslations2[2];
46
- var showAddSubGroup = function showAddSubGroup() {
47
- setIsAddSubgroup(true);
48
- };
49
- var hideAddSubGroup = function hideAddSubGroup() {
50
- setIsAddSubgroup(false);
51
- };
52
42
  var onClickHandler = function onClickHandler() {
53
43
  hideConditionPreviewHandler === null || hideConditionPreviewHandler === void 0 || hideConditionPreviewHandler();
54
44
  onClick();
@@ -78,11 +68,7 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
78
68
  return /*#__PURE__*/React__default["default"].createElement("div", {
79
69
  className: "".concat(className, " ").concat(DataConfigs.blockClass, "__add-button-wrapper"),
80
70
  role: !enableSubGroup ? 'gridcell' : 'none',
81
- "aria-label": getAriaLabel(),
82
- onMouseEnter: showAddSubGroup,
83
- onMouseLeave: hideAddSubGroup,
84
- onFocus: showAddSubGroup,
85
- onBlur: hideAddSubGroup
71
+ "aria-label": getAriaLabel()
86
72
  }, /*#__PURE__*/React__default["default"].createElement(ConditionBuilderButton.ConditionBuilderButton, _rollupPluginBabelHelpers["extends"]({
87
73
  renderIcon: icons.AddAlt,
88
74
  onClick: onClickHandler
@@ -92,7 +78,8 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
92
78
  hideLabel: true,
93
79
  "data-name": "addButton",
94
80
  label: buttonLabel !== null && buttonLabel !== void 0 ? buttonLabel : addConditionText,
95
- tabIndex: tabIndex
81
+ tabIndex: tabIndex,
82
+ wrapperClassName: "".concat(DataConfigs.blockClass, "__add-condition-wrapper")
96
83
  })), enableSubGroup && /*#__PURE__*/React__default["default"].createElement(ConditionBuilderButton.ConditionBuilderButton, _rollupPluginBabelHelpers["extends"]({
97
84
  renderIcon: icons.TextNewLine,
98
85
  onClick: addConditionSubGroupHandler,
@@ -100,7 +87,7 @@ var ConditionBuilderAdd = function ConditionBuilderAdd(_ref) {
100
87
  hideLabel: true,
101
88
  label: addSubgroupText,
102
89
  wrapperProps: wrapperProps,
103
- wrapperClassName: cx__default["default"]("".concat(DataConfigs.blockClass, "__add-condition-sub-group-wrapper ").concat(DataConfigs.blockClass, "__gap-left"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__add-condition-sub-group-wrapper--show"), isAddSubgroup))
90
+ wrapperClassName: "".concat(DataConfigs.blockClass, "__add-condition-sub-group-wrapper ").concat(DataConfigs.blockClass, "__gap-left")
104
91
  }, previewHandlersForSubgroup())));
105
92
  };
106
93
  var ConditionBuilderAdd$1 = ConditionBuilderAdd;
@@ -59,56 +59,50 @@ var ConditionGroupBuilder = function ConditionGroupBuilder(_ref) {
59
59
  _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
60
60
  showConditionSubGroupPreview = _useState4[0],
61
61
  setShowConditionSubGroupPreview = _useState4[1];
62
- var _useState5 = React.useState(false),
63
- _useState6 = _rollupPluginBabelHelpers.slicedToArray(_useState5, 2),
64
- showDeletionPreviewForSubgroups = _useState6[0],
65
- setShowDeletionPreviewForSubgroups = _useState6[1];
62
+ React.useState(false);
66
63
  var conditionBuilderContentRef = React.useRef();
67
64
  var onRemoveHandler = function onRemoveHandler(conditionId, evt, conditionIndex) {
68
65
  if (group.conditions.length > 1) {
69
66
  variant == 'tree' ? handleFocusOnCloseTree(evt) : handleFocusOnClose(evt, conditionIndex);
70
- if (group.conditions[1].conditions && group.conditions[1].id !== conditionId) {
71
- //when we remove every plain conditions of a group without deleting the subgroup, we need to restructure the group
72
- //the inner group become outer group and same level subgroups become plain conditions
73
-
74
- //ensure we are deleting last condition , not the subgroup
67
+ if (!checkGroupHaveCondition(group.conditions, conditionId)) {
68
+ //when we delete the last condition of a group without deleting the subgroup, we need to restructure the group.
69
+ //we will shift the group one level up. The subgroups will open up as conditions.
75
70
 
76
71
  //spreading out the condition inside the subgroup
77
- var allConditions = group.conditions.reduce(function (acc, item) {
78
- if (item.conditions) {
79
- return acc.concat(item.conditions);
72
+ var allConditions = group.conditions.reduce(function (acc, condition) {
73
+ if (condition.conditions) {
74
+ //this is a subgroup
75
+ return acc.concat(condition.conditions);
80
76
  }
81
77
  return acc;
82
78
  }, []);
83
-
84
- //we always have conditions first and then subgroups, so ordering accordingly
85
- var groupedItems = {
86
- groups: [],
87
- conditions: []
88
- };
89
- allConditions.forEach(function (item) {
90
- if (item.conditions) {
91
- groupedItems.groups.push(item);
92
- } else {
93
- groupedItems.conditions.push(item);
94
- }
95
- });
96
- onRemove(evt);
97
- // onChange({
98
- // ...group,
99
- // conditions: [...groupedItems.conditions, ...groupedItems.groups],
100
- // });
79
+ onChange(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, group), {}, {
80
+ conditions: allConditions
81
+ }));
101
82
  } else {
83
+ var filteredConditions = group.conditions.filter(function (condition) {
84
+ return conditionId !== condition.id;
85
+ });
86
+ //This is to handle a edge case.
87
+ //When a group has structure as 1 condition,1 subgroup, 1 condition and if we delete first condition,
88
+ //the group will start with a subgroup. To avoid this,opening up that subgroup.
89
+ if (filteredConditions !== null && filteredConditions !== void 0 && filteredConditions[0].conditions) {
90
+ filteredConditions.splice.apply(filteredConditions, [0, 1].concat(_rollupPluginBabelHelpers.toConsumableArray(filteredConditions[0].conditions)));
91
+ }
102
92
  onChange(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, group), {}, {
103
- conditions: group.conditions.filter(function (condition) {
104
- return conditionId !== condition.id;
105
- })
93
+ conditions: filteredConditions
106
94
  }));
107
95
  }
108
96
  } else {
109
97
  onRemove(evt);
110
98
  }
111
99
  };
100
+ //check to identify a group without a plain condition
101
+ var checkGroupHaveCondition = function checkGroupHaveCondition(conditions, conditionId) {
102
+ return conditions.find(function (eachCondition) {
103
+ return !eachCondition.conditions && eachCondition.id !== conditionId;
104
+ });
105
+ };
112
106
  var onChangeHandler = function onChangeHandler(updatedCondition, conditionIndex) {
113
107
  var updatedConditions = [].concat(_rollupPluginBabelHelpers.toConsumableArray(group.conditions.slice(0, conditionIndex)), [updatedCondition], _rollupPluginBabelHelpers.toConsumableArray(group.conditions.slice(conditionIndex + 1)));
114
108
  onChange(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, group), {}, {
@@ -295,7 +289,7 @@ var ConditionGroupBuilder = function ConditionGroupBuilder(_ref) {
295
289
  return /*#__PURE__*/React__default["default"].createElement(React.Fragment, {
296
290
  key: eachCondition.id
297
291
  }, eachCondition.conditions ? /*#__PURE__*/React__default["default"].createElement("div", {
298
- className: cx__default["default"]("".concat(DataConfigs.blockClass, "__condition-block subgroup ").concat(DataConfigs.blockClass, "__gap"), _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap-bottom"), group.conditions.length < conditionIndex + 1), "".concat(DataConfigs.blockClass, "__subgroup_deletionPreview"), showDeletionPreviewForSubgroups), {})
292
+ className: cx__default["default"]("".concat(DataConfigs.blockClass, "__condition-block subgroup ").concat(DataConfigs.blockClass, "__gap"), _rollupPluginBabelHelpers.defineProperty({}, "".concat(DataConfigs.blockClass, "__gap-bottom"), group.conditions.length < conditionIndex + 1), {})
299
293
  }, /*#__PURE__*/React__default["default"].createElement(ConditionConnector["default"], {
300
294
  className: "".concat(DataConfigs.blockClass, "__gap ").concat(DataConfigs.blockClass, "__gap-bottom ").concat(DataConfigs.blockClass, "__groupConnector"),
301
295
  operator: group.groupOperator,
@@ -343,8 +337,7 @@ var ConditionGroupBuilder = function ConditionGroupBuilder(_ref) {
343
337
  _showConditionPreviewHandler(conditionIndex);
344
338
  },
345
339
  hideConditionPreviewHandler: hideConditionPreviewHandler,
346
- isLastCondition: isLastCondition,
347
- setShowDeletionPreviewForSubgroups: setShowDeletionPreviewForSubgroups
340
+ isLastCondition: isLastCondition
348
341
  })), conditionIndex == showConditionSubGroupPreview && (_ConditionPreview || (_ConditionPreview = /*#__PURE__*/React__default["default"].createElement(ConditionPreview["default"], {
349
342
  previewType: "subGroup",
350
343
  group: group
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/ibm-products",
3
3
  "description": "Carbon for IBM Products",
4
- "version": "2.43.2-canary.116+832233109",
4
+ "version": "2.43.2-canary.118+357fb5d96",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -81,7 +81,7 @@
81
81
  "fs-extra": "^11.2.0",
82
82
  "glob": "^10.3.10",
83
83
  "jest": "^29.7.0",
84
- "jest-config-ibm-cloud-cognitive": "^1.5.0",
84
+ "jest-config-ibm-cloud-cognitive": "^1.6.0-rc.0",
85
85
  "jest-environment-jsdom": "^29.7.0",
86
86
  "namor": "^1.1.2",
87
87
  "npm-check-updates": "^16.14.12",
@@ -96,7 +96,7 @@
96
96
  "dependencies": {
97
97
  "@babel/runtime": "^7.23.9",
98
98
  "@carbon/feature-flags": "^0.20.0",
99
- "@carbon/ibm-products-styles": "^2.42.0",
99
+ "@carbon/ibm-products-styles": "^2.39.1-canary.128+357fb5d96",
100
100
  "@carbon/telemetry": "^0.1.0",
101
101
  "@dnd-kit/core": "^6.0.8",
102
102
  "@dnd-kit/modifiers": "^7.0.0",
@@ -120,5 +120,5 @@
120
120
  "react": "^16.8.6 || ^17.0.1 || ^18.2.0",
121
121
  "react-dom": "^16.8.6 || ^17.0.1 || ^18.2.0"
122
122
  },
123
- "gitHead": "832233109aca76f9e4a48ed7e7dbd0eac70c46b1"
123
+ "gitHead": "357fb5d964dd83cdff78b7be3615e9de19db922f"
124
124
  }
@@ -38,20 +38,12 @@ $block-class: #{c4p-settings.$pkg-prefix}--condition-builder;
38
38
  .#{$block-class}__button:not(
39
39
  .#{$block-class}__statement-button,
40
40
  .#{$block-class}__connector-button,
41
- .#{$block-class}__add-button
41
+ .#{$block-class}__add-button,
42
+ .#{$block-class}__add-condition-sub-group
42
43
  ) {
43
44
  background-color: $tag-background-red;
44
45
  color: $tag-color-red;
45
46
  }
46
- .#{$block-class}__subgroup_deletionPreview {
47
- .#{$block-class}__group {
48
- /* stylelint-disable max-nesting-depth */
49
- button {
50
- background-color: $tag-background-red;
51
- color: $tag-color-red;
52
- }
53
- }
54
- }
55
47
 
56
48
  .#{$block-class}__condition__deletion-preview
57
49
  .#{$block-class}__button:not(