@carbon/ibm-products 2.43.2-canary.233 → 2.43.2-canary.234

Sign up to get free protection for your applications and to get access to all the features.
@@ -47,7 +47,8 @@ var componentName = 'ConditionBuilder';
47
47
  var ConditionBuilder = /*#__PURE__*/React__default.forwardRef(function (_ref, ref) {
48
48
  var className = _ref.className,
49
49
  inputConfig = _ref.inputConfig,
50
- startConditionLabel = _ref.startConditionLabel,
50
+ _ref$startConditionLa = _ref.startConditionLabel,
51
+ startConditionLabel = _ref$startConditionLa === void 0 ? 'Add Condition' : _ref$startConditionLa,
51
52
  popOverSearchThreshold = _ref.popOverSearchThreshold,
52
53
  getOptions = _ref.getOptions,
53
54
  initialState = _ref.initialState,
@@ -146,27 +147,32 @@ ConditionBuilder.propTypes = {
146
147
  */
147
148
  getOptions: PropTypes.func,
148
149
  /**
149
- * Optional prop if you want to pass a saved condition state.
150
- * This object should respect the structure of condition state that is available in getConditionState callback
150
+ * Optional prop if you want to pass a saved condition state, pass as "initialState.state".
151
+ * "initialState.enabledDefault" will populate the builder with the provided initial state before clicking Add Condition button.
152
+ *
153
+ * This state should respect the structure of condition state that is available in getConditionState callback
151
154
  */
152
155
  /**@ts-ignore */
153
156
  initialState: PropTypes.shape({
154
- groups: PropTypes.arrayOf(PropTypes.shape({
155
- groupOperator: PropTypes.string,
156
- statement: PropTypes.string,
157
- conditions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({
158
- property: PropTypes.string,
159
- operator: PropTypes.string,
160
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.shape({
161
- id: PropTypes.string,
162
- label: PropTypes.string
163
- })), PropTypes.shape({
164
- id: PropTypes.string,
165
- label: PropTypes.string
166
- })])
167
- }), PropTypes.object]))
168
- })),
169
- operator: PropTypes.string
157
+ state: PropTypes.shape({
158
+ groups: PropTypes.arrayOf(PropTypes.shape({
159
+ groupOperator: PropTypes.string,
160
+ statement: PropTypes.string,
161
+ conditions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({
162
+ property: PropTypes.string,
163
+ operator: PropTypes.string,
164
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.shape({
165
+ id: PropTypes.string,
166
+ label: PropTypes.string
167
+ })), PropTypes.shape({
168
+ id: PropTypes.string,
169
+ label: PropTypes.string
170
+ })])
171
+ }), PropTypes.object]))
172
+ })),
173
+ operator: PropTypes.string
174
+ }),
175
+ enabledDefault: PropTypes.bool
170
176
  }),
171
177
  /**
172
178
  * This is a mandatory prop that defines the input to the condition builder.
@@ -199,7 +205,7 @@ ConditionBuilder.propTypes = {
199
205
  /**
200
206
  * Provide a label to the button that starts condition builder
201
207
  */
202
- startConditionLabel: PropTypes.string.isRequired,
208
+ startConditionLabel: PropTypes.string,
203
209
  /**
204
210
  * Optional prop, if you need to pass translations to the texts on the component instead of the defined defaults.
205
211
  * This callback function will receive the message id and you need to return the corresponding text for that id.
@@ -122,17 +122,21 @@ export type Action = {
122
122
  export type variantsType = 'Non-Hierarchical' | 'Hierarchical';
123
123
  export type ConditionBuilderProps = {
124
124
  inputConfig: inputConfig;
125
- initialState?: ConditionBuilderState;
125
+ initialState?: InitialState;
126
126
  getActionsState?: (state: Action[] | undefined) => void;
127
127
  getConditionState: (state: ConditionBuilderState | undefined) => void;
128
128
  getOptions?: (state: ConditionBuilderState, condition: Condition) => Promise<Option[]>;
129
129
  actions?: Action[];
130
130
  className?: string;
131
131
  popOverSearchThreshold: number;
132
- startConditionLabel: string;
132
+ startConditionLabel?: string;
133
133
  variant?: 'Non-Hierarchical' | 'Hierarchical';
134
134
  translateWithId: (id: string) => string;
135
135
  };
136
+ export type InitialState = {
137
+ state: ConditionBuilderState;
138
+ enabledDefault?: boolean;
139
+ };
136
140
  export interface ConditionBuilderContextInputProps extends PropsWithChildren {
137
141
  children?: ReactNode;
138
142
  inputConfig?: inputConfig;
@@ -5,12 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import PropTypes from 'prop-types';
8
- import { Action, ConditionBuilderState } from '../ConditionBuilder.types';
8
+ import { Action, ConditionBuilderState, InitialState } from '../ConditionBuilder.types';
9
9
  interface ConditionBuilderContentProps {
10
10
  startConditionLabel: string;
11
11
  getConditionState: (state: ConditionBuilderState) => void;
12
12
  getActionsState?: (state: Action[]) => void;
13
- initialState?: ConditionBuilderState;
13
+ initialState?: InitialState;
14
14
  actions?: Action[];
15
15
  }
16
16
  declare const ConditionBuilderContent: {
@@ -35,12 +35,15 @@ declare const ConditionBuilderContent: {
35
35
  * Optional prop if the condition building need to start from a predefined initial state
36
36
  */
37
37
  initialState: PropTypes.Requireable<PropTypes.InferProps<{
38
- groups: PropTypes.Requireable<(PropTypes.InferProps<{
39
- groupOperator: PropTypes.Requireable<string>;
40
- statement: PropTypes.Requireable<string>;
41
- conditions: PropTypes.Requireable<(object | null | undefined)[]>;
42
- }> | null | undefined)[]>;
43
- operator: PropTypes.Requireable<string>;
38
+ state: PropTypes.Requireable<PropTypes.InferProps<{
39
+ groups: PropTypes.Requireable<(PropTypes.InferProps<{
40
+ groupOperator: PropTypes.Requireable<string>;
41
+ statement: PropTypes.Requireable<string>;
42
+ conditions: PropTypes.Requireable<(object | null | undefined)[]>;
43
+ }> | null | undefined)[]>;
44
+ operator: PropTypes.Requireable<string>;
45
+ }>>;
46
+ enabledDefault: PropTypes.Requireable<boolean>;
44
47
  }>>;
45
48
  startConditionLabel: PropTypes.Validator<string>;
46
49
  };
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import { slicedToArray as _slicedToArray, objectSpread2 as _objectSpread2, toConsumableArray as _toConsumableArray } from '../../../_virtual/_rollupPluginBabelHelpers.js';
9
- import React__default, { useContext, useState, useEffect, useCallback } from 'react';
9
+ import React__default, { useContext, useRef, useState, useEffect, useCallback } from 'react';
10
10
  import PropTypes from '../../../node_modules/prop-types/index.js';
11
11
  import { Button, Section, Heading } from '@carbon/react';
12
12
  import { Add, TextNewLine } from '@carbon/react/icons';
@@ -33,6 +33,7 @@ var ConditionBuilderContent = function ConditionBuilderContent(_ref) {
33
33
  setRootState = _useContext.setRootState,
34
34
  variant = _useContext.variant,
35
35
  actionState = _useContext.actionState;
36
+ var initialConditionState = useRef(initialState !== null && initialState !== void 0 && initialState.state ? JSON.parse(JSON.stringify(initialState === null || initialState === void 0 ? void 0 : initialState.state)) : null);
36
37
  var _useState = useState(false),
37
38
  _useState2 = _slicedToArray(_useState, 2),
38
39
  isConditionBuilderActive = _useState2[0],
@@ -69,10 +70,24 @@ var ConditionBuilderContent = function ConditionBuilderContent(_ref) {
69
70
  getActionsState === null || getActionsState === void 0 || getActionsState(actionState !== null && actionState !== void 0 ? actionState : []);
70
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
72
  }, [actionState]);
73
+ useEffect(function () {
74
+ if (initialState !== null && initialState !== void 0 && initialState.enabledDefault) {
75
+ setRootState === null || setRootState === void 0 || setRootState(initialConditionState.current);
76
+ initialConditionState.current = null;
77
+ }
78
+ // eslint-disable-next-line react-hooks/exhaustive-deps
79
+ }, [initialState]);
72
80
  var onStartConditionBuilder = function onStartConditionBuilder() {
81
+ var _initialConditionStat;
73
82
  //when add condition button is clicked.
74
83
  setIsConditionBuilderActive(true);
75
- setRootState === null || setRootState === void 0 || setRootState(initialState !== null && initialState !== void 0 ? initialState : emptyState); //here we can set an empty skeleton object for an empty condition builder,
84
+ if (initialConditionState !== null && initialConditionState !== void 0 && (_initialConditionStat = initialConditionState.current) !== null && _initialConditionStat !== void 0 && (_initialConditionStat = _initialConditionStat.groups) !== null && _initialConditionStat !== void 0 && _initialConditionStat.length) {
85
+ setRootState === null || setRootState === void 0 || setRootState(initialConditionState.current);
86
+ initialConditionState.current = null;
87
+ } else {
88
+ setRootState === null || setRootState === void 0 || setRootState(emptyState); //here we can set an empty skeleton object for an empty condition builder,
89
+ }
90
+
76
91
  //or we can even pre-populate some existing builder and continue editing
77
92
  };
78
93
  var _onRemove = useCallback(function (groupId) {
@@ -208,22 +223,25 @@ ConditionBuilderContent.propTypes = {
208
223
  * Optional prop if the condition building need to start from a predefined initial state
209
224
  */
210
225
  initialState: PropTypes.shape({
211
- groups: PropTypes.arrayOf(PropTypes.shape({
212
- groupOperator: PropTypes.string,
213
- statement: PropTypes.string,
214
- conditions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({
215
- property: PropTypes.string,
216
- operator: PropTypes.string,
217
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.shape({
218
- id: PropTypes.string,
219
- label: PropTypes.string
220
- })), PropTypes.shape({
221
- id: PropTypes.string,
222
- label: PropTypes.string
223
- })])
224
- }), PropTypes.object]))
225
- })),
226
- operator: PropTypes.string
226
+ state: PropTypes.shape({
227
+ groups: PropTypes.arrayOf(PropTypes.shape({
228
+ groupOperator: PropTypes.string,
229
+ statement: PropTypes.string,
230
+ conditions: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.shape({
231
+ property: PropTypes.string,
232
+ operator: PropTypes.string,
233
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.shape({
234
+ id: PropTypes.string,
235
+ label: PropTypes.string
236
+ })), PropTypes.shape({
237
+ id: PropTypes.string,
238
+ label: PropTypes.string
239
+ })])
240
+ }), PropTypes.object]))
241
+ })),
242
+ operator: PropTypes.string
243
+ }),
244
+ enabledDefault: PropTypes.bool
227
245
  }),
228
246
  /* Provide a label to the button that starts condition builder
229
247
  */
@@ -56,7 +56,8 @@ var componentName = 'ConditionBuilder';
56
56
  exports.ConditionBuilder = /*#__PURE__*/React__default["default"].forwardRef(function (_ref, ref) {
57
57
  var className = _ref.className,
58
58
  inputConfig = _ref.inputConfig,
59
- startConditionLabel = _ref.startConditionLabel,
59
+ _ref$startConditionLa = _ref.startConditionLabel,
60
+ startConditionLabel = _ref$startConditionLa === void 0 ? 'Add Condition' : _ref$startConditionLa,
60
61
  popOverSearchThreshold = _ref.popOverSearchThreshold,
61
62
  getOptions = _ref.getOptions,
62
63
  initialState = _ref.initialState,
@@ -155,27 +156,32 @@ exports.ConditionBuilder.propTypes = {
155
156
  */
156
157
  getOptions: index["default"].func,
157
158
  /**
158
- * Optional prop if you want to pass a saved condition state.
159
- * This object should respect the structure of condition state that is available in getConditionState callback
159
+ * Optional prop if you want to pass a saved condition state, pass as "initialState.state".
160
+ * "initialState.enabledDefault" will populate the builder with the provided initial state before clicking Add Condition button.
161
+ *
162
+ * This state should respect the structure of condition state that is available in getConditionState callback
160
163
  */
161
164
  /**@ts-ignore */
162
165
  initialState: index["default"].shape({
163
- groups: index["default"].arrayOf(index["default"].shape({
164
- groupOperator: index["default"].string,
165
- statement: index["default"].string,
166
- conditions: index["default"].arrayOf(index["default"].oneOfType([index["default"].shape({
167
- property: index["default"].string,
168
- operator: index["default"].string,
169
- value: index["default"].oneOfType([index["default"].string, index["default"].arrayOf(index["default"].shape({
170
- id: index["default"].string,
171
- label: index["default"].string
172
- })), index["default"].shape({
173
- id: index["default"].string,
174
- label: index["default"].string
175
- })])
176
- }), index["default"].object]))
177
- })),
178
- operator: index["default"].string
166
+ state: index["default"].shape({
167
+ groups: index["default"].arrayOf(index["default"].shape({
168
+ groupOperator: index["default"].string,
169
+ statement: index["default"].string,
170
+ conditions: index["default"].arrayOf(index["default"].oneOfType([index["default"].shape({
171
+ property: index["default"].string,
172
+ operator: index["default"].string,
173
+ value: index["default"].oneOfType([index["default"].string, index["default"].arrayOf(index["default"].shape({
174
+ id: index["default"].string,
175
+ label: index["default"].string
176
+ })), index["default"].shape({
177
+ id: index["default"].string,
178
+ label: index["default"].string
179
+ })])
180
+ }), index["default"].object]))
181
+ })),
182
+ operator: index["default"].string
183
+ }),
184
+ enabledDefault: index["default"].bool
179
185
  }),
180
186
  /**
181
187
  * This is a mandatory prop that defines the input to the condition builder.
@@ -208,7 +214,7 @@ exports.ConditionBuilder.propTypes = {
208
214
  /**
209
215
  * Provide a label to the button that starts condition builder
210
216
  */
211
- startConditionLabel: index["default"].string.isRequired,
217
+ startConditionLabel: index["default"].string,
212
218
  /**
213
219
  * Optional prop, if you need to pass translations to the texts on the component instead of the defined defaults.
214
220
  * This callback function will receive the message id and you need to return the corresponding text for that id.
@@ -122,17 +122,21 @@ export type Action = {
122
122
  export type variantsType = 'Non-Hierarchical' | 'Hierarchical';
123
123
  export type ConditionBuilderProps = {
124
124
  inputConfig: inputConfig;
125
- initialState?: ConditionBuilderState;
125
+ initialState?: InitialState;
126
126
  getActionsState?: (state: Action[] | undefined) => void;
127
127
  getConditionState: (state: ConditionBuilderState | undefined) => void;
128
128
  getOptions?: (state: ConditionBuilderState, condition: Condition) => Promise<Option[]>;
129
129
  actions?: Action[];
130
130
  className?: string;
131
131
  popOverSearchThreshold: number;
132
- startConditionLabel: string;
132
+ startConditionLabel?: string;
133
133
  variant?: 'Non-Hierarchical' | 'Hierarchical';
134
134
  translateWithId: (id: string) => string;
135
135
  };
136
+ export type InitialState = {
137
+ state: ConditionBuilderState;
138
+ enabledDefault?: boolean;
139
+ };
136
140
  export interface ConditionBuilderContextInputProps extends PropsWithChildren {
137
141
  children?: ReactNode;
138
142
  inputConfig?: inputConfig;
@@ -5,12 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import PropTypes from 'prop-types';
8
- import { Action, ConditionBuilderState } from '../ConditionBuilder.types';
8
+ import { Action, ConditionBuilderState, InitialState } from '../ConditionBuilder.types';
9
9
  interface ConditionBuilderContentProps {
10
10
  startConditionLabel: string;
11
11
  getConditionState: (state: ConditionBuilderState) => void;
12
12
  getActionsState?: (state: Action[]) => void;
13
- initialState?: ConditionBuilderState;
13
+ initialState?: InitialState;
14
14
  actions?: Action[];
15
15
  }
16
16
  declare const ConditionBuilderContent: {
@@ -35,12 +35,15 @@ declare const ConditionBuilderContent: {
35
35
  * Optional prop if the condition building need to start from a predefined initial state
36
36
  */
37
37
  initialState: PropTypes.Requireable<PropTypes.InferProps<{
38
- groups: PropTypes.Requireable<(PropTypes.InferProps<{
39
- groupOperator: PropTypes.Requireable<string>;
40
- statement: PropTypes.Requireable<string>;
41
- conditions: PropTypes.Requireable<(object | null | undefined)[]>;
42
- }> | null | undefined)[]>;
43
- operator: PropTypes.Requireable<string>;
38
+ state: PropTypes.Requireable<PropTypes.InferProps<{
39
+ groups: PropTypes.Requireable<(PropTypes.InferProps<{
40
+ groupOperator: PropTypes.Requireable<string>;
41
+ statement: PropTypes.Requireable<string>;
42
+ conditions: PropTypes.Requireable<(object | null | undefined)[]>;
43
+ }> | null | undefined)[]>;
44
+ operator: PropTypes.Requireable<string>;
45
+ }>>;
46
+ enabledDefault: PropTypes.Requireable<boolean>;
44
47
  }>>;
45
48
  startConditionLabel: PropTypes.Validator<string>;
46
49
  };
@@ -41,6 +41,7 @@ var ConditionBuilderContent = function ConditionBuilderContent(_ref) {
41
41
  setRootState = _useContext.setRootState,
42
42
  variant = _useContext.variant,
43
43
  actionState = _useContext.actionState;
44
+ var initialConditionState = React.useRef(initialState !== null && initialState !== void 0 && initialState.state ? JSON.parse(JSON.stringify(initialState === null || initialState === void 0 ? void 0 : initialState.state)) : null);
44
45
  var _useState = React.useState(false),
45
46
  _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
46
47
  isConditionBuilderActive = _useState2[0],
@@ -77,10 +78,24 @@ var ConditionBuilderContent = function ConditionBuilderContent(_ref) {
77
78
  getActionsState === null || getActionsState === void 0 || getActionsState(actionState !== null && actionState !== void 0 ? actionState : []);
78
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
79
80
  }, [actionState]);
81
+ React.useEffect(function () {
82
+ if (initialState !== null && initialState !== void 0 && initialState.enabledDefault) {
83
+ setRootState === null || setRootState === void 0 || setRootState(initialConditionState.current);
84
+ initialConditionState.current = null;
85
+ }
86
+ // eslint-disable-next-line react-hooks/exhaustive-deps
87
+ }, [initialState]);
80
88
  var onStartConditionBuilder = function onStartConditionBuilder() {
89
+ var _initialConditionStat;
81
90
  //when add condition button is clicked.
82
91
  setIsConditionBuilderActive(true);
83
- setRootState === null || setRootState === void 0 || setRootState(initialState !== null && initialState !== void 0 ? initialState : ConditionBuilderProvider.emptyState); //here we can set an empty skeleton object for an empty condition builder,
92
+ if (initialConditionState !== null && initialConditionState !== void 0 && (_initialConditionStat = initialConditionState.current) !== null && _initialConditionStat !== void 0 && (_initialConditionStat = _initialConditionStat.groups) !== null && _initialConditionStat !== void 0 && _initialConditionStat.length) {
93
+ setRootState === null || setRootState === void 0 || setRootState(initialConditionState.current);
94
+ initialConditionState.current = null;
95
+ } else {
96
+ setRootState === null || setRootState === void 0 || setRootState(ConditionBuilderProvider.emptyState); //here we can set an empty skeleton object for an empty condition builder,
97
+ }
98
+
84
99
  //or we can even pre-populate some existing builder and continue editing
85
100
  };
86
101
  var _onRemove = React.useCallback(function (groupId) {
@@ -216,22 +231,25 @@ ConditionBuilderContent.propTypes = {
216
231
  * Optional prop if the condition building need to start from a predefined initial state
217
232
  */
218
233
  initialState: index["default"].shape({
219
- groups: index["default"].arrayOf(index["default"].shape({
220
- groupOperator: index["default"].string,
221
- statement: index["default"].string,
222
- conditions: index["default"].arrayOf(index["default"].oneOfType([index["default"].shape({
223
- property: index["default"].string,
224
- operator: index["default"].string,
225
- value: index["default"].oneOfType([index["default"].string, index["default"].arrayOf(index["default"].shape({
226
- id: index["default"].string,
227
- label: index["default"].string
228
- })), index["default"].shape({
229
- id: index["default"].string,
230
- label: index["default"].string
231
- })])
232
- }), index["default"].object]))
233
- })),
234
- operator: index["default"].string
234
+ state: index["default"].shape({
235
+ groups: index["default"].arrayOf(index["default"].shape({
236
+ groupOperator: index["default"].string,
237
+ statement: index["default"].string,
238
+ conditions: index["default"].arrayOf(index["default"].oneOfType([index["default"].shape({
239
+ property: index["default"].string,
240
+ operator: index["default"].string,
241
+ value: index["default"].oneOfType([index["default"].string, index["default"].arrayOf(index["default"].shape({
242
+ id: index["default"].string,
243
+ label: index["default"].string
244
+ })), index["default"].shape({
245
+ id: index["default"].string,
246
+ label: index["default"].string
247
+ })])
248
+ }), index["default"].object]))
249
+ })),
250
+ operator: index["default"].string
251
+ }),
252
+ enabledDefault: index["default"].bool
235
253
  }),
236
254
  /* Provide a label to the button that starts condition builder
237
255
  */
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.233+11c1554ba",
4
+ "version": "2.43.2-canary.234+3b2b91c63",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -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": "11c1554ba92037f559862ad9c83cfdf048074659"
123
+ "gitHead": "3b2b91c63157d748425c1fa85ed70411e2c7e018"
124
124
  }