@carbon/ibm-products 2.43.2-canary.230 → 2.43.2-canary.234
Sign up to get free protection for your applications and to get access to all the features.
- package/es/components/ConditionBuilder/ConditionBuilder.js +26 -20
- package/es/components/ConditionBuilder/ConditionBuilder.types.d.ts +6 -2
- package/es/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts +11 -8
- package/es/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.js +36 -18
- package/es/components/CreateFullPage/CreateFullPageStep.d.ts +3 -1
- package/es/components/CreateFullPage/CreateFullPageStep.js +5 -2
- package/es/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +17 -2
- package/es/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +13 -2
- package/es/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +1 -12
- package/lib/components/ConditionBuilder/ConditionBuilder.js +26 -20
- package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +6 -2
- package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts +11 -8
- package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.js +35 -17
- package/lib/components/CreateFullPage/CreateFullPageStep.d.ts +3 -1
- package/lib/components/CreateFullPage/CreateFullPageStep.js +5 -2
- package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterFlyout.js +15 -0
- package/lib/components/Datagrid/Datagrid/addons/Filtering/FilterPanel.js +12 -1
- package/lib/components/Datagrid/Datagrid/addons/Filtering/hooks/useFilters.js +0 -11
- package/package.json +2 -2
@@ -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
|
-
|
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
|
-
*
|
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
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
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?:
|
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
|
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?:
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
*/
|
@@ -60,10 +60,12 @@ interface CreateFullPageStepBaseProps extends PropsWithChildren {
|
|
60
60
|
title: ReactNode;
|
61
61
|
}
|
62
62
|
type CreateFullPageStepFieldsetProps = {
|
63
|
+
fieldsetLegendText?: string;
|
64
|
+
} | {
|
63
65
|
hasFieldset: false;
|
64
66
|
fieldsetLegendText?: string;
|
65
67
|
} | {
|
66
|
-
hasFieldset
|
68
|
+
hasFieldset: true;
|
67
69
|
fieldsetLegendText: string;
|
68
70
|
};
|
69
71
|
export type CreateFullPageStepProps = CreateFullPageStepBaseProps & CreateFullPageStepFieldsetProps;
|
@@ -24,6 +24,11 @@ var blockClass = "".concat(pkg.prefix, "--create-full-page__step");
|
|
24
24
|
var defaults = {
|
25
25
|
includeStep: true
|
26
26
|
};
|
27
|
+
|
28
|
+
// Try to specify the hasFieldset and fieldsetLegendText Typescript requirements.
|
29
|
+
// Basically, fieldsetLegendText should only be specified when hasFieldset is true.
|
30
|
+
// And usually, hasFieldset won't be specified at all unless it's being set to true.
|
31
|
+
|
27
32
|
var CreateFullPageStep = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
28
33
|
var children = _ref.children,
|
29
34
|
className = _ref.className,
|
@@ -134,7 +139,6 @@ CreateFullPageStep.propTypes = {
|
|
134
139
|
/**
|
135
140
|
* This will conditionally disable the submit button in the multi step CreateFullPage
|
136
141
|
*/
|
137
|
-
/**@ts-ignore */
|
138
142
|
disableSubmit: PropTypes.bool,
|
139
143
|
/**
|
140
144
|
* This is the legend text that appears above a fieldset html element for accessibility purposes. It is required when the optional `hasFieldset` prop is provided to a FullPageStep.
|
@@ -147,7 +151,6 @@ CreateFullPageStep.propTypes = {
|
|
147
151
|
/**
|
148
152
|
* This optional prop will render your form content inside of a fieldset html element
|
149
153
|
*/
|
150
|
-
/**@ts-ignore */
|
151
154
|
hasFieldset: PropTypes.bool,
|
152
155
|
/**
|
153
156
|
* This prop is used to help track dynamic steps. If this value is `false` then the step is not included in the visible steps or the ProgressIndicator
|
@@ -6,15 +6,16 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
import { slicedToArray as _slicedToArray, defineProperty as _defineProperty } from '../../../../../_virtual/_rollupPluginBabelHelpers.js';
|
9
|
-
import { BATCH, INSTANT, FLYOUT, CLEAR_FILTERS } from './constants.js';
|
9
|
+
import { BATCH, INSTANT, FLYOUT, CLEAR_FILTERS, SAVED_FILTERS } from './constants.js';
|
10
10
|
import { usePrefix, IconButton } from '@carbon/react';
|
11
|
-
import React__default, { useState, useRef, useEffect } from 'react';
|
11
|
+
import React__default, { useState, useRef, useContext, useEffect } from 'react';
|
12
12
|
import { breakpoints, px } from '@carbon/layout';
|
13
13
|
import { ActionSet } from '../../../../ActionSet/ActionSet.js';
|
14
14
|
import { Filter } from '@carbon/react/icons';
|
15
15
|
import PropTypes from '../../../../../node_modules/prop-types/index.js';
|
16
16
|
import cx from 'classnames';
|
17
17
|
import { pkg } from '../../../../../settings.js';
|
18
|
+
import { FilterContext } from './FilterProvider.js';
|
18
19
|
import useFilters from './hooks/useFilters.js';
|
19
20
|
import useShouldDisableButtons from './hooks/useShouldDisableButtons.js';
|
20
21
|
import { useWindowResize } from '../../../../../global/js/hooks/useWindowResize.js';
|
@@ -138,6 +139,10 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
138
139
|
handleResize(current);
|
139
140
|
});
|
140
141
|
|
142
|
+
/** Context */
|
143
|
+
var _useContext = useContext(FilterContext),
|
144
|
+
localDispatch = _useContext.dispatch;
|
145
|
+
|
141
146
|
/** Memos */
|
142
147
|
var showActionSet = updateMethod === BATCH;
|
143
148
|
var carbonPrefix = usePrefix();
|
@@ -174,6 +179,16 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
174
179
|
|
175
180
|
// Update the last applied filters
|
176
181
|
lastAppliedFilters.current = JSON.stringify(filtersObjectArray);
|
182
|
+
|
183
|
+
// Dispatch action from local filter context to track filters in order
|
184
|
+
// to keep history if `isFetching` becomes true. If so, react-table
|
185
|
+
// clears all filter history
|
186
|
+
localDispatch({
|
187
|
+
type: SAVED_FILTERS,
|
188
|
+
payload: {
|
189
|
+
savedFilters: filtersObjectArray
|
190
|
+
}
|
191
|
+
});
|
177
192
|
};
|
178
193
|
|
179
194
|
/** Renders all filters */
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
import { slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../../../../_virtual/_rollupPluginBabelHelpers.js';
|
9
9
|
import { Button, Layer, Search, Accordion, AccordionItem } from '@carbon/react';
|
10
|
-
import { PANEL, BATCH, CLEAR_FILTERS, INSTANT } from './constants.js';
|
10
|
+
import { PANEL, BATCH, CLEAR_FILTERS, INSTANT, SAVED_FILTERS } from './constants.js';
|
11
11
|
import React__default, { useState, useContext, useRef, useMemo, useEffect, useCallback } from 'react';
|
12
12
|
import { panelVariants, innerContainerVariants, actionSetVariants } from './motion/variants.js';
|
13
13
|
import { motion, useReducedMotion } from 'framer-motion';
|
@@ -80,7 +80,8 @@ var FilterPanel = function FilterPanel(_ref) {
|
|
80
80
|
/** Context */
|
81
81
|
var _useContext = useContext(FilterContext),
|
82
82
|
panelOpen = _useContext.panelOpen,
|
83
|
-
setPanelOpen = _useContext.setPanelOpen
|
83
|
+
setPanelOpen = _useContext.setPanelOpen,
|
84
|
+
localDispatch = _useContext.dispatch;
|
84
85
|
var _useFilters = useFilters({
|
85
86
|
updateMethod: updateMethod,
|
86
87
|
filters: filterSections,
|
@@ -145,6 +146,16 @@ var FilterPanel = function FilterPanel(_ref) {
|
|
145
146
|
|
146
147
|
// Update the last applied filters
|
147
148
|
lastAppliedFilters.current = JSON.stringify(filtersObjectArray);
|
149
|
+
|
150
|
+
// Dispatch action from local filter context to track filters in order
|
151
|
+
// to keep history if `isFetching` becomes true. If so, react-table
|
152
|
+
// clears all filter history
|
153
|
+
localDispatch({
|
154
|
+
type: SAVED_FILTERS,
|
155
|
+
payload: {
|
156
|
+
savedFilters: filtersObjectArray
|
157
|
+
}
|
158
|
+
});
|
148
159
|
};
|
149
160
|
var renderActionSet = function renderActionSet() {
|
150
161
|
return showActionSet && /*#__PURE__*/React__default.createElement(MotionActionSet, {
|
@@ -6,7 +6,7 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, extends as _extends, objectSpread2 as _objectSpread2, defineProperty as _defineProperty } from '../../../../../../_virtual/_rollupPluginBabelHelpers.js';
|
9
|
-
import { MULTISELECT, DROPDOWN, RADIO, CHECKBOX, NUMBER, DATE, BATCH,
|
9
|
+
import { MULTISELECT, DROPDOWN, RADIO, CHECKBOX, NUMBER, DATE, BATCH, INSTANT, PANEL } from '../constants.js';
|
10
10
|
import { MultiSelect, Dropdown, FormGroup, RadioButtonGroup, RadioButton, NumberInput, DatePicker, DatePickerInput, Layer, Checkbox } from '@carbon/react';
|
11
11
|
import React__default, { useContext, useState, useRef, useCallback, useEffect } from 'react';
|
12
12
|
import OverflowCheckboxes from '../OverflowCheckboxes.js';
|
@@ -31,7 +31,6 @@ var useFilters = function useFilters(_ref) {
|
|
31
31
|
isFetching = _ref.isFetching;
|
32
32
|
var _useContext = useContext(FilterContext),
|
33
33
|
state = _useContext.state,
|
34
|
-
localDispatch = _useContext.dispatch,
|
35
34
|
contextTableId = _useContext.tableId;
|
36
35
|
var savedFilters = state.savedFilters;
|
37
36
|
/** State */
|
@@ -136,16 +135,6 @@ var useFilters = function useFilters(_ref) {
|
|
136
135
|
filterCopy.splice(index, 1);
|
137
136
|
}
|
138
137
|
setFiltersObjectArray(filterCopy);
|
139
|
-
|
140
|
-
// Dispatch action from local filter context to track filters in order
|
141
|
-
// to keep history if `isFetching` becomes true. If so, react-table
|
142
|
-
// clears all filter history
|
143
|
-
localDispatch({
|
144
|
-
type: SAVED_FILTERS,
|
145
|
-
payload: {
|
146
|
-
savedFilters: filterCopy
|
147
|
-
}
|
148
|
-
});
|
149
138
|
if (updateMethod === INSTANT) {
|
150
139
|
setAllFilters(filterCopy);
|
151
140
|
}
|
@@ -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
|
-
|
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
|
-
*
|
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
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
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?:
|
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
|
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;
|
package/lib/components/ConditionBuilder/ConditionBuilderContent/ConditionBuilderContent.d.ts
CHANGED
@@ -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?:
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
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
|
*/
|
@@ -60,10 +60,12 @@ interface CreateFullPageStepBaseProps extends PropsWithChildren {
|
|
60
60
|
title: ReactNode;
|
61
61
|
}
|
62
62
|
type CreateFullPageStepFieldsetProps = {
|
63
|
+
fieldsetLegendText?: string;
|
64
|
+
} | {
|
63
65
|
hasFieldset: false;
|
64
66
|
fieldsetLegendText?: string;
|
65
67
|
} | {
|
66
|
-
hasFieldset
|
68
|
+
hasFieldset: true;
|
67
69
|
fieldsetLegendText: string;
|
68
70
|
};
|
69
71
|
export type CreateFullPageStepProps = CreateFullPageStepBaseProps & CreateFullPageStepFieldsetProps;
|
@@ -33,6 +33,11 @@ var blockClass = "".concat(settings.pkg.prefix, "--create-full-page__step");
|
|
33
33
|
var defaults = {
|
34
34
|
includeStep: true
|
35
35
|
};
|
36
|
+
|
37
|
+
// Try to specify the hasFieldset and fieldsetLegendText Typescript requirements.
|
38
|
+
// Basically, fieldsetLegendText should only be specified when hasFieldset is true.
|
39
|
+
// And usually, hasFieldset won't be specified at all unless it's being set to true.
|
40
|
+
|
36
41
|
exports.CreateFullPageStep = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
37
42
|
var children = _ref.children,
|
38
43
|
className = _ref.className,
|
@@ -143,7 +148,6 @@ exports.CreateFullPageStep.propTypes = {
|
|
143
148
|
/**
|
144
149
|
* This will conditionally disable the submit button in the multi step CreateFullPage
|
145
150
|
*/
|
146
|
-
/**@ts-ignore */
|
147
151
|
disableSubmit: index["default"].bool,
|
148
152
|
/**
|
149
153
|
* This is the legend text that appears above a fieldset html element for accessibility purposes. It is required when the optional `hasFieldset` prop is provided to a FullPageStep.
|
@@ -156,7 +160,6 @@ exports.CreateFullPageStep.propTypes = {
|
|
156
160
|
/**
|
157
161
|
* This optional prop will render your form content inside of a fieldset html element
|
158
162
|
*/
|
159
|
-
/**@ts-ignore */
|
160
163
|
hasFieldset: index["default"].bool,
|
161
164
|
/**
|
162
165
|
* This prop is used to help track dynamic steps. If this value is `false` then the step is not included in the visible steps or the ProgressIndicator
|
@@ -19,6 +19,7 @@ var icons = require('@carbon/react/icons');
|
|
19
19
|
var index = require('../../../../../node_modules/prop-types/index.js');
|
20
20
|
var cx = require('classnames');
|
21
21
|
var settings = require('../../../../../settings.js');
|
22
|
+
var FilterProvider = require('./FilterProvider.js');
|
22
23
|
var useFilters = require('./hooks/useFilters.js');
|
23
24
|
var useShouldDisableButtons = require('./hooks/useShouldDisableButtons.js');
|
24
25
|
var useWindowResize = require('../../../../../global/js/hooks/useWindowResize.js');
|
@@ -147,6 +148,10 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
147
148
|
handleResize(current);
|
148
149
|
});
|
149
150
|
|
151
|
+
/** Context */
|
152
|
+
var _useContext = React.useContext(FilterProvider.FilterContext),
|
153
|
+
localDispatch = _useContext.dispatch;
|
154
|
+
|
150
155
|
/** Memos */
|
151
156
|
var showActionSet = updateMethod === constants.BATCH;
|
152
157
|
var carbonPrefix = react.usePrefix();
|
@@ -183,6 +188,16 @@ var FilterFlyout = function FilterFlyout(_ref) {
|
|
183
188
|
|
184
189
|
// Update the last applied filters
|
185
190
|
lastAppliedFilters.current = JSON.stringify(filtersObjectArray);
|
191
|
+
|
192
|
+
// Dispatch action from local filter context to track filters in order
|
193
|
+
// to keep history if `isFetching` becomes true. If so, react-table
|
194
|
+
// clears all filter history
|
195
|
+
localDispatch({
|
196
|
+
type: constants.SAVED_FILTERS,
|
197
|
+
payload: {
|
198
|
+
savedFilters: filtersObjectArray
|
199
|
+
}
|
200
|
+
});
|
186
201
|
};
|
187
202
|
|
188
203
|
/** Renders all filters */
|
@@ -89,7 +89,8 @@ var FilterPanel = function FilterPanel(_ref) {
|
|
89
89
|
/** Context */
|
90
90
|
var _useContext = React.useContext(FilterProvider.FilterContext),
|
91
91
|
panelOpen = _useContext.panelOpen,
|
92
|
-
setPanelOpen = _useContext.setPanelOpen
|
92
|
+
setPanelOpen = _useContext.setPanelOpen,
|
93
|
+
localDispatch = _useContext.dispatch;
|
93
94
|
var _useFilters = useFilters["default"]({
|
94
95
|
updateMethod: updateMethod,
|
95
96
|
filters: filterSections,
|
@@ -154,6 +155,16 @@ var FilterPanel = function FilterPanel(_ref) {
|
|
154
155
|
|
155
156
|
// Update the last applied filters
|
156
157
|
lastAppliedFilters.current = JSON.stringify(filtersObjectArray);
|
158
|
+
|
159
|
+
// Dispatch action from local filter context to track filters in order
|
160
|
+
// to keep history if `isFetching` becomes true. If so, react-table
|
161
|
+
// clears all filter history
|
162
|
+
localDispatch({
|
163
|
+
type: constants.SAVED_FILTERS,
|
164
|
+
payload: {
|
165
|
+
savedFilters: filtersObjectArray
|
166
|
+
}
|
167
|
+
});
|
157
168
|
};
|
158
169
|
var renderActionSet = function renderActionSet() {
|
159
170
|
return showActionSet && /*#__PURE__*/React__default["default"].createElement(MotionActionSet, {
|
@@ -39,7 +39,6 @@ var useFilters = function useFilters(_ref) {
|
|
39
39
|
isFetching = _ref.isFetching;
|
40
40
|
var _useContext = React.useContext(FilterProvider.FilterContext),
|
41
41
|
state = _useContext.state,
|
42
|
-
localDispatch = _useContext.dispatch,
|
43
42
|
contextTableId = _useContext.tableId;
|
44
43
|
var savedFilters = state.savedFilters;
|
45
44
|
/** State */
|
@@ -144,16 +143,6 @@ var useFilters = function useFilters(_ref) {
|
|
144
143
|
filterCopy.splice(index, 1);
|
145
144
|
}
|
146
145
|
setFiltersObjectArray(filterCopy);
|
147
|
-
|
148
|
-
// Dispatch action from local filter context to track filters in order
|
149
|
-
// to keep history if `isFetching` becomes true. If so, react-table
|
150
|
-
// clears all filter history
|
151
|
-
localDispatch({
|
152
|
-
type: constants.SAVED_FILTERS,
|
153
|
-
payload: {
|
154
|
-
savedFilters: filterCopy
|
155
|
-
}
|
156
|
-
});
|
157
146
|
if (updateMethod === constants.INSTANT) {
|
158
147
|
setAllFilters(filterCopy);
|
159
148
|
}
|
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.
|
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": "
|
123
|
+
"gitHead": "3b2b91c63157d748425c1fa85ed70411e2c7e018"
|
124
124
|
}
|