@carbon/react 1.85.0 → 1.86.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +797 -797
- package/es/components/AILabel/index.js +1 -1
- package/es/components/Accordion/AccordionItem.d.ts +1 -1
- package/es/components/Accordion/AccordionItem.js +1 -1
- package/es/components/Checkbox/Checkbox.js +1 -1
- package/es/components/CheckboxGroup/CheckboxGroup.js +1 -1
- package/es/components/CodeSnippet/CodeSnippet.d.ts +2 -2
- package/es/components/CodeSnippet/CodeSnippet.js +1 -1
- package/es/components/ComboBox/ComboBox.js +1 -1
- package/es/components/ComposedModal/ComposedModal.js +1 -1
- package/es/components/ContentSwitcher/ContentSwitcher.d.ts +1 -1
- package/es/components/ContentSwitcher/ContentSwitcher.js +1 -1
- package/es/components/DataTable/DataTable.d.ts +230 -170
- package/es/components/DataTable/DataTable.js +508 -519
- package/es/components/DataTable/TableContainer.d.ts +9 -1
- package/es/components/DataTable/TableContainer.js +7 -1
- package/es/components/DataTable/TableExpandHeader.d.ts +1 -1
- package/es/components/DataTable/TableExpandHeader.js +1 -1
- package/es/components/DataTable/TableSelectAll.d.ts +2 -2
- package/es/components/DataTable/TableSelectAll.js +1 -1
- package/es/components/DataTable/TableSelectRow.d.ts +2 -2
- package/es/components/DataTable/TableSelectRow.js +1 -1
- package/es/components/DataTable/TableToolbar.d.ts +1 -1
- package/es/components/DataTable/TableToolbar.js +1 -1
- package/es/components/DataTable/TableToolbarMenu.d.ts +2 -18
- package/es/components/DataTable/TableToolbarMenu.js +0 -1
- package/es/components/DataTable/index.d.ts +1 -1
- package/es/components/DataTable/state/getDerivedStateFromProps.js +5 -1
- package/es/components/DatePicker/DatePicker.js +1 -1
- package/es/components/DatePickerInput/DatePickerInput.js +1 -1
- package/es/components/Dropdown/Dropdown.js +1 -1
- package/es/components/FeatureFlags/index.d.ts +2 -2
- package/es/components/FeatureFlags/index.js +1 -1
- package/es/components/FileUploader/FileUploaderButton.d.ts +1 -1
- package/es/components/FileUploader/FileUploaderButton.js +1 -1
- package/es/components/FileUploader/FileUploaderDropContainer.d.ts +2 -2
- package/es/components/FileUploader/FileUploaderDropContainer.js +1 -1
- package/es/components/FluidTextArea/FluidTextArea.d.ts +1 -1
- package/es/components/FluidTextArea/FluidTextArea.js +1 -1
- package/es/components/InlineCheckbox/InlineCheckbox.js +1 -1
- package/es/components/ListBox/ListBox.js +1 -1
- package/es/components/Loading/Loading.d.ts +1 -1
- package/es/components/Loading/Loading.js +1 -1
- package/es/components/Menu/Menu.js +1 -1
- package/es/components/Modal/Modal.js +1 -1
- package/es/components/MultiSelect/FilterableMultiSelect.js +1 -1
- package/es/components/MultiSelect/MultiSelect.js +1 -1
- package/es/components/Notification/Notification.d.ts +4 -4
- package/es/components/Notification/Notification.js +1 -1
- package/es/components/NumberInput/NumberInput.d.ts +7 -0
- package/es/components/NumberInput/NumberInput.js +80 -25
- package/es/components/OverflowMenu/OverflowMenu.d.ts +2 -6
- package/es/components/OverflowMenu/OverflowMenu.js +1 -1
- package/es/components/Pagination/Pagination.js +22 -5
- package/es/components/RadioButton/RadioButton.js +1 -1
- package/es/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
- package/es/components/RadioTile/RadioTile.js +1 -1
- package/es/components/Search/Search.js +1 -1
- package/es/components/Select/Select.js +1 -1
- package/es/components/Slider/Slider.js +1 -1
- package/es/components/StructuredList/StructuredList.d.ts +5 -5
- package/es/components/StructuredList/StructuredList.js +1 -1
- package/es/components/Tabs/Tabs.d.ts +1 -1
- package/es/components/Tabs/Tabs.js +1 -1
- package/es/components/Tag/DismissibleTag.js +1 -1
- package/es/components/Tag/Tag.js +1 -1
- package/es/components/TextArea/TextArea.js +1 -1
- package/es/components/TextInput/ControlledPasswordInput.js +1 -1
- package/es/components/TextInput/PasswordInput.js +1 -1
- package/es/components/TextInput/TextInput.js +1 -1
- package/es/components/Tile/Tile.js +1 -1
- package/es/components/TileGroup/TileGroup.d.ts +5 -5
- package/es/components/TimePicker/TimePicker.d.ts +8 -0
- package/es/components/TimePicker/TimePicker.js +6 -4
- package/es/components/Tooltip/DefinitionTooltip.d.ts +1 -1
- package/es/components/Tooltip/DefinitionTooltip.js +1 -1
- package/es/components/TreeView/TreeContext.d.ts +19 -0
- package/es/components/TreeView/TreeContext.js +13 -0
- package/es/components/TreeView/TreeNode.d.ts +4 -4
- package/es/components/TreeView/TreeNode.js +56 -108
- package/es/components/TreeView/TreeView.js +42 -79
- package/es/components/UIShell/HeaderMenu.js +1 -1
- package/es/components/UIShell/HeaderMenuItem.d.ts +1 -1
- package/es/components/UIShell/HeaderMenuItem.js +1 -1
- package/es/components/UIShell/HeaderName.d.ts +1 -1
- package/es/components/UIShell/HeaderPanel.js +5 -7
- package/es/components/UIShell/Link.d.ts +2 -2
- package/es/components/UIShell/Link.js +1 -1
- package/es/components/UIShell/Switcher.d.ts +1 -1
- package/es/components/UIShell/Switcher.js +39 -12
- package/es/index.js +1 -1
- package/es/internal/useNoInteractiveChildren.d.ts +25 -0
- package/es/internal/useNoInteractiveChildren.js +39 -32
- package/es/prop-types/deprecate.d.ts +17 -0
- package/es/prop-types/deprecate.js +22 -12
- package/lib/components/AILabel/index.js +2 -2
- package/lib/components/Accordion/AccordionItem.d.ts +1 -1
- package/lib/components/Accordion/AccordionItem.js +1 -1
- package/lib/components/Checkbox/Checkbox.js +1 -1
- package/lib/components/CheckboxGroup/CheckboxGroup.js +1 -1
- package/lib/components/CodeSnippet/CodeSnippet.d.ts +2 -2
- package/lib/components/CodeSnippet/CodeSnippet.js +2 -2
- package/lib/components/ComboBox/ComboBox.js +3 -3
- package/lib/components/ComposedModal/ComposedModal.js +1 -1
- package/lib/components/ContentSwitcher/ContentSwitcher.d.ts +1 -1
- package/lib/components/ContentSwitcher/ContentSwitcher.js +1 -1
- package/lib/components/DataTable/DataTable.d.ts +230 -170
- package/lib/components/DataTable/DataTable.js +507 -518
- package/lib/components/DataTable/TableContainer.d.ts +9 -1
- package/lib/components/DataTable/TableContainer.js +7 -1
- package/lib/components/DataTable/TableExpandHeader.d.ts +1 -1
- package/lib/components/DataTable/TableExpandHeader.js +1 -1
- package/lib/components/DataTable/TableSelectAll.d.ts +2 -2
- package/lib/components/DataTable/TableSelectAll.js +1 -1
- package/lib/components/DataTable/TableSelectRow.d.ts +2 -2
- package/lib/components/DataTable/TableSelectRow.js +1 -1
- package/lib/components/DataTable/TableToolbar.d.ts +1 -1
- package/lib/components/DataTable/TableToolbar.js +1 -1
- package/lib/components/DataTable/TableToolbarMenu.d.ts +2 -18
- package/lib/components/DataTable/TableToolbarMenu.js +0 -1
- package/lib/components/DataTable/index.d.ts +1 -1
- package/lib/components/DataTable/state/getDerivedStateFromProps.js +5 -1
- package/lib/components/DatePicker/DatePicker.js +1 -1
- package/lib/components/DatePickerInput/DatePickerInput.js +1 -1
- package/lib/components/Dropdown/Dropdown.js +3 -3
- package/lib/components/FeatureFlags/index.d.ts +2 -2
- package/lib/components/FeatureFlags/index.js +1 -1
- package/lib/components/FileUploader/FileUploaderButton.d.ts +1 -1
- package/lib/components/FileUploader/FileUploaderButton.js +1 -1
- package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +2 -2
- package/lib/components/FileUploader/FileUploaderDropContainer.js +2 -2
- package/lib/components/FluidTextArea/FluidTextArea.d.ts +1 -1
- package/lib/components/FluidTextArea/FluidTextArea.js +1 -1
- package/lib/components/InlineCheckbox/InlineCheckbox.js +1 -1
- package/lib/components/ListBox/ListBox.js +1 -1
- package/lib/components/Loading/Loading.d.ts +1 -1
- package/lib/components/Loading/Loading.js +1 -1
- package/lib/components/Menu/Menu.js +1 -1
- package/lib/components/Modal/Modal.js +1 -1
- package/lib/components/MultiSelect/FilterableMultiSelect.js +4 -4
- package/lib/components/MultiSelect/MultiSelect.js +2 -2
- package/lib/components/Notification/Notification.d.ts +4 -4
- package/lib/components/Notification/Notification.js +4 -4
- package/lib/components/NumberInput/NumberInput.d.ts +7 -0
- package/lib/components/NumberInput/NumberInput.js +81 -26
- package/lib/components/OverflowMenu/OverflowMenu.d.ts +2 -6
- package/lib/components/OverflowMenu/OverflowMenu.js +2 -2
- package/lib/components/Pagination/Pagination.js +21 -4
- package/lib/components/RadioButton/RadioButton.js +1 -1
- package/lib/components/RadioButtonGroup/RadioButtonGroup.js +1 -1
- package/lib/components/RadioTile/RadioTile.js +2 -2
- package/lib/components/Search/Search.js +1 -1
- package/lib/components/Select/Select.js +2 -2
- package/lib/components/Slider/Slider.js +1 -1
- package/lib/components/StructuredList/StructuredList.d.ts +5 -5
- package/lib/components/StructuredList/StructuredList.js +4 -4
- package/lib/components/Tabs/Tabs.d.ts +1 -1
- package/lib/components/Tabs/Tabs.js +1 -1
- package/lib/components/Tag/DismissibleTag.js +1 -1
- package/lib/components/Tag/Tag.js +4 -4
- package/lib/components/TextArea/TextArea.js +2 -2
- package/lib/components/TextInput/ControlledPasswordInput.js +1 -1
- package/lib/components/TextInput/PasswordInput.js +1 -1
- package/lib/components/TextInput/TextInput.js +2 -2
- package/lib/components/Tile/Tile.js +9 -9
- package/lib/components/TileGroup/TileGroup.d.ts +5 -5
- package/lib/components/TimePicker/TimePicker.d.ts +8 -0
- package/lib/components/TimePicker/TimePicker.js +6 -4
- package/lib/components/Tooltip/DefinitionTooltip.d.ts +1 -1
- package/lib/components/Tooltip/DefinitionTooltip.js +1 -1
- package/lib/components/TreeView/TreeContext.d.ts +19 -0
- package/lib/components/TreeView/TreeContext.js +18 -0
- package/lib/components/TreeView/TreeNode.d.ts +4 -4
- package/lib/components/TreeView/TreeNode.js +55 -107
- package/lib/components/TreeView/TreeView.js +41 -78
- package/lib/components/UIShell/HeaderMenu.js +1 -1
- package/lib/components/UIShell/HeaderMenuItem.d.ts +1 -1
- package/lib/components/UIShell/HeaderMenuItem.js +1 -1
- package/lib/components/UIShell/HeaderName.d.ts +1 -1
- package/lib/components/UIShell/HeaderPanel.js +5 -7
- package/lib/components/UIShell/Link.d.ts +2 -2
- package/lib/components/UIShell/Link.js +1 -1
- package/lib/components/UIShell/Switcher.d.ts +1 -1
- package/lib/components/UIShell/Switcher.js +38 -11
- package/lib/index.js +1 -1
- package/lib/internal/useNoInteractiveChildren.d.ts +25 -0
- package/lib/internal/useNoInteractiveChildren.js +39 -32
- package/lib/prop-types/deprecate.d.ts +17 -0
- package/lib/prop-types/deprecate.js +22 -12
- package/package.json +3 -3
- package/telemetry.yml +15 -14
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
|
|
10
10
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
11
|
|
|
12
|
-
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
|
|
13
12
|
var PropTypes = require('prop-types');
|
|
14
13
|
var React = require('react');
|
|
15
14
|
var isEqual = require('react-fast-compare');
|
|
@@ -60,6 +59,9 @@ const translationKeys = {
|
|
|
60
59
|
unselectRow: 'carbon.table.row.unselect'
|
|
61
60
|
};
|
|
62
61
|
|
|
62
|
+
// TODO: All code comments in this file should be revisited for accuracy and
|
|
63
|
+
// clarity.
|
|
64
|
+
|
|
63
65
|
/**
|
|
64
66
|
* Message ids that will be passed to translateWithId().
|
|
65
67
|
*/
|
|
@@ -85,557 +87,544 @@ const translateWithId = id => defaultTranslations[id];
|
|
|
85
87
|
* and updating the state of the single entity will cascade updates to the
|
|
86
88
|
* consumer.
|
|
87
89
|
*/
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
sortDirection: nextSortState.sortDirection
|
|
125
|
-
})(event);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
});
|
|
130
|
-
/**
|
|
131
|
-
* Get the props associated with the given expand header.
|
|
132
|
-
*/
|
|
133
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getExpandHeaderProps", ({
|
|
134
|
-
onClick,
|
|
135
|
-
onExpand,
|
|
136
|
-
...rest
|
|
137
|
-
} = {}) => {
|
|
138
|
-
const {
|
|
139
|
-
translateWithId: t = translateWithId
|
|
140
|
-
} = this.props;
|
|
141
|
-
const {
|
|
142
|
-
isExpandedAll,
|
|
143
|
-
rowIds,
|
|
144
|
-
rowsById
|
|
145
|
-
} = this.state;
|
|
146
|
-
const isExpanded = isExpandedAll || rowIds.every(id => rowsById[id].isExpanded);
|
|
147
|
-
const translationKey = isExpanded ? translationKeys.collapseAll : translationKeys.expandAll;
|
|
148
|
-
return {
|
|
149
|
-
...rest,
|
|
150
|
-
'aria-label': t(translationKey),
|
|
151
|
-
// Provide a string of all the expanded row id's, separated by a space.
|
|
152
|
-
'aria-controls': rowIds.map(id => `expanded-row-${id}`).join(' '),
|
|
153
|
-
isExpanded,
|
|
154
|
-
// Compose the event handlers so we don't overwrite a consumer's `onClick`
|
|
155
|
-
// handler
|
|
156
|
-
onExpand: events.composeEventHandlers([this.handleOnExpandAll, onExpand, onClick && this.handleOnExpandHeaderClick(onClick, {
|
|
157
|
-
isExpanded
|
|
158
|
-
})])
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
/**
|
|
162
|
-
* Decorate consumer's `onClick` event handler with sort parameters
|
|
163
|
-
*/
|
|
164
|
-
_rollupPluginBabelHelpers.defineProperty(this, "handleOnHeaderClick", (onClick, sortParams) => {
|
|
165
|
-
return event => onClick(event, sortParams);
|
|
166
|
-
});
|
|
167
|
-
/**
|
|
168
|
-
* Decorate consumer's `onClick` event handler with expand parameters
|
|
169
|
-
*/
|
|
170
|
-
_rollupPluginBabelHelpers.defineProperty(this, "handleOnExpandHeaderClick", (onClick, expandParams) => {
|
|
171
|
-
return event => onClick(event, expandParams);
|
|
172
|
-
});
|
|
173
|
-
/**
|
|
174
|
-
* Get the props associated with the given row. Mostly used for expansion.
|
|
175
|
-
*/
|
|
176
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getRowProps", ({
|
|
177
|
-
row,
|
|
178
|
-
onClick,
|
|
179
|
-
...rest
|
|
180
|
-
}) => {
|
|
181
|
-
const {
|
|
182
|
-
translateWithId: t = translateWithId
|
|
183
|
-
} = this.props;
|
|
184
|
-
const translationKey = row.isExpanded ? translationKeys.collapseRow : translationKeys.expandRow;
|
|
90
|
+
const DataTable = props => {
|
|
91
|
+
const {
|
|
92
|
+
children,
|
|
93
|
+
filterRows = filter.defaultFilterRows,
|
|
94
|
+
headers,
|
|
95
|
+
render,
|
|
96
|
+
translateWithId: t = translateWithId,
|
|
97
|
+
size,
|
|
98
|
+
isSortable: isSortableProp,
|
|
99
|
+
useZebraStyles,
|
|
100
|
+
useStaticWidth,
|
|
101
|
+
stickyHeader,
|
|
102
|
+
overflowMenuOnHover,
|
|
103
|
+
experimentalAutoAlign,
|
|
104
|
+
radio,
|
|
105
|
+
rows
|
|
106
|
+
} = props;
|
|
107
|
+
const instanceId = React.useMemo(() => getInstanceId(), []);
|
|
108
|
+
const [state, setState] = React.useState(() => ({
|
|
109
|
+
...getDerivedStateFromProps["default"](props, {}),
|
|
110
|
+
isExpandedAll: false // Start with collapsed state, treat `undefined` as neutral state
|
|
111
|
+
}));
|
|
112
|
+
React.useEffect(() => {
|
|
113
|
+
const nextRowIds = rows.map(row => row.id);
|
|
114
|
+
const nextHeaders = headers.map(header => header.key);
|
|
115
|
+
const hasRowIdsChanged = !isEqual__default["default"](nextRowIds, state.rowIds);
|
|
116
|
+
const currentHeaders = Object.keys(state.cellsById).reduce((acc, cellId) => {
|
|
117
|
+
const headerKey = cellId.split(':')[1];
|
|
118
|
+
if (headerKey && !acc.includes(headerKey)) {
|
|
119
|
+
acc.push(headerKey);
|
|
120
|
+
}
|
|
121
|
+
return acc;
|
|
122
|
+
}, []);
|
|
123
|
+
const hasHeadersChanged = !isEqual__default["default"](nextHeaders, currentHeaders);
|
|
124
|
+
const currentRows = state.rowIds.map(id => {
|
|
125
|
+
const row = state.rowsById[id];
|
|
185
126
|
return {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
// Compose the event handlers so we don't overwrite a consumer's `onClick`
|
|
190
|
-
// handler
|
|
191
|
-
onExpand: events.composeEventHandlers([this.handleOnExpandRow(row.id), onClick]),
|
|
127
|
+
// TODO: Investigate whether it be okay to just return `row`.
|
|
128
|
+
id: row.id,
|
|
129
|
+
disabled: row.disabled,
|
|
192
130
|
isExpanded: row.isExpanded,
|
|
193
|
-
|
|
194
|
-
'aria-controls': `expanded-row-${row.id}`,
|
|
195
|
-
isSelected: row.isSelected,
|
|
196
|
-
disabled: row.disabled
|
|
131
|
+
isSelected: row.isSelected
|
|
197
132
|
};
|
|
198
133
|
});
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
...rest
|
|
205
|
-
}) => {
|
|
206
|
-
return {
|
|
207
|
-
...rest,
|
|
208
|
-
id: `expanded-row-${row.id}`
|
|
209
|
-
};
|
|
210
|
-
});
|
|
211
|
-
/**
|
|
212
|
-
* Gets the props associated with selection for a header or a row, where
|
|
213
|
-
* applicable. Most often used to indicate selection status of the table or
|
|
214
|
-
* for a specific row.
|
|
215
|
-
*/
|
|
216
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getSelectionProps", ({
|
|
217
|
-
onClick,
|
|
218
|
-
row,
|
|
219
|
-
...rest
|
|
220
|
-
} = {}) => {
|
|
221
|
-
const {
|
|
222
|
-
translateWithId: t = translateWithId
|
|
223
|
-
} = this.props;
|
|
134
|
+
const hasRowsChanged = !isEqual__default["default"](rows, currentRows);
|
|
135
|
+
if (hasRowIdsChanged || hasHeadersChanged || hasRowsChanged) {
|
|
136
|
+
setState(prev => getDerivedStateFromProps["default"](props, prev));
|
|
137
|
+
}
|
|
138
|
+
}, [headers, rows]);
|
|
224
139
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Get the props associated with the given header. Mostly used for adding in
|
|
142
|
+
* sorting behavior.
|
|
143
|
+
*/
|
|
144
|
+
const getHeaderProps = ({
|
|
145
|
+
header,
|
|
146
|
+
onClick,
|
|
147
|
+
isSortable = isSortableProp,
|
|
148
|
+
...rest
|
|
149
|
+
}) => {
|
|
150
|
+
const {
|
|
151
|
+
sortDirection,
|
|
152
|
+
sortHeaderKey
|
|
153
|
+
} = state;
|
|
154
|
+
return {
|
|
155
|
+
...rest,
|
|
156
|
+
key: header.key,
|
|
157
|
+
sortDirection,
|
|
158
|
+
isSortable,
|
|
159
|
+
isSortHeader: sortHeaderKey === header.key,
|
|
160
|
+
slug: header.slug,
|
|
161
|
+
decorator: header.decorator,
|
|
162
|
+
onClick: event => {
|
|
163
|
+
const nextSortState = sorting.getNextSortState(props, state, {
|
|
164
|
+
key: header.key
|
|
165
|
+
});
|
|
166
|
+
setState(prev => ({
|
|
167
|
+
...prev,
|
|
168
|
+
...nextSortState
|
|
169
|
+
}));
|
|
170
|
+
onClick && handleOnHeaderClick(onClick, {
|
|
171
|
+
sortHeaderKey: header.key,
|
|
172
|
+
sortDirection: nextSortState.sortDirection
|
|
173
|
+
})(event);
|
|
238
174
|
}
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get the props associated with the given expand header.
|
|
180
|
+
*/
|
|
181
|
+
const getExpandHeaderProps = ({
|
|
182
|
+
onClick,
|
|
183
|
+
onExpand,
|
|
184
|
+
...rest
|
|
185
|
+
} = {}) => {
|
|
186
|
+
const {
|
|
187
|
+
isExpandedAll,
|
|
188
|
+
rowIds,
|
|
189
|
+
rowsById
|
|
190
|
+
} = state;
|
|
191
|
+
const isExpanded = isExpandedAll || rowIds.every(id => rowsById[id].isExpanded);
|
|
192
|
+
const translationKey = isExpanded ? translationKeys.collapseAll : translationKeys.expandAll;
|
|
193
|
+
return {
|
|
194
|
+
...rest,
|
|
195
|
+
'aria-label': t(translationKey),
|
|
196
|
+
// Provide a string of all the expanded row id's, separated by a space.
|
|
197
|
+
'aria-controls': rowIds.map(id => `expanded-row-${id}`).join(' '),
|
|
198
|
+
isExpanded,
|
|
199
|
+
// Compose the event handlers so we don't overwrite a consumer's `onClick`
|
|
200
|
+
// handler
|
|
201
|
+
onExpand: events.composeEventHandlers([handleOnExpandAll, onExpand,
|
|
202
|
+
// TODO: Avoid passing `false` to this function.
|
|
203
|
+
onClick && handleOnExpandHeaderClick(onClick, {
|
|
204
|
+
isExpanded
|
|
205
|
+
})])
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Decorate consumer's `onClick` event handler with sort parameters
|
|
211
|
+
*/
|
|
212
|
+
const handleOnHeaderClick = (onClick, sortParams) => {
|
|
213
|
+
return event => onClick(event, sortParams);
|
|
214
|
+
};
|
|
239
215
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
216
|
+
/**
|
|
217
|
+
* Decorate consumer's `onClick` event handler with expand parameters
|
|
218
|
+
*/
|
|
219
|
+
const handleOnExpandHeaderClick = (onClick, expandParams) => {
|
|
220
|
+
return event => onClick(event, expandParams);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Get the props associated with the given row. Mostly used for expansion.
|
|
225
|
+
*/
|
|
226
|
+
const getRowProps = ({
|
|
227
|
+
row,
|
|
228
|
+
onClick,
|
|
229
|
+
...rest
|
|
230
|
+
}) => {
|
|
231
|
+
const translationKey = row.isExpanded ? translationKeys.collapseRow : translationKeys.expandRow;
|
|
232
|
+
return {
|
|
233
|
+
...rest,
|
|
234
|
+
key: row.id,
|
|
235
|
+
onClick,
|
|
236
|
+
// Compose the event handlers so we don't overwrite a consumer's `onClick`
|
|
237
|
+
// handler
|
|
238
|
+
onExpand: events.composeEventHandlers([handleOnExpandRow(row.id), onClick]),
|
|
239
|
+
isExpanded: row.isExpanded,
|
|
240
|
+
'aria-label': t(translationKey),
|
|
241
|
+
'aria-controls': `expanded-row-${row.id}`,
|
|
242
|
+
isSelected: row.isSelected,
|
|
243
|
+
disabled: row.disabled
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Get the props associated with an expanded row
|
|
249
|
+
*/
|
|
250
|
+
const getExpandedRowProps = ({
|
|
251
|
+
row,
|
|
252
|
+
...rest
|
|
253
|
+
}) => {
|
|
254
|
+
return {
|
|
255
|
+
...rest,
|
|
256
|
+
id: `expanded-row-${row.id}`
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Gets the props associated with selection for a header or a row, where
|
|
262
|
+
* applicable. Most often used to indicate selection status of the table or
|
|
263
|
+
* for a specific row.
|
|
264
|
+
*/
|
|
265
|
+
const getSelectionProps = ({
|
|
266
|
+
onClick,
|
|
267
|
+
row,
|
|
268
|
+
...rest
|
|
269
|
+
} = {}) => {
|
|
270
|
+
// If we're given a row, return the selection state values for that row
|
|
271
|
+
if (row) {
|
|
272
|
+
const translationKey = row.isSelected ? translationKeys.unselectRow : translationKeys.selectRow;
|
|
247
273
|
return {
|
|
248
274
|
...rest,
|
|
275
|
+
checked: row.isSelected,
|
|
276
|
+
onSelect: events.composeEventHandlers([handleOnSelectRow(row.id), onClick]),
|
|
277
|
+
id: `${getTablePrefix()}__select-row-${row.id}`,
|
|
278
|
+
name: `select-row-${instanceId}`,
|
|
249
279
|
'aria-label': t(translationKey),
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
indeterminate,
|
|
253
|
-
name: `select-all-${this.instanceId}`,
|
|
254
|
-
onSelect: events.composeEventHandlers([this.handleSelectAll, onClick])
|
|
255
|
-
};
|
|
256
|
-
});
|
|
257
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getToolbarProps", props => {
|
|
258
|
-
const {
|
|
259
|
-
size
|
|
260
|
-
} = this.props;
|
|
261
|
-
const isSmall = size === 'xs' || size === 'sm';
|
|
262
|
-
return {
|
|
263
|
-
...props,
|
|
264
|
-
size: isSmall ? 'sm' : undefined
|
|
265
|
-
};
|
|
266
|
-
});
|
|
267
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getBatchActionProps", props => {
|
|
268
|
-
const {
|
|
269
|
-
shouldShowBatchActions
|
|
270
|
-
} = this.state;
|
|
271
|
-
const totalSelected = this.getSelectedRows().length;
|
|
272
|
-
return {
|
|
273
|
-
onSelectAll: undefined,
|
|
274
|
-
totalCount: this.state.rowIds.length || 0,
|
|
275
|
-
...props,
|
|
276
|
-
shouldShowBatchActions: shouldShowBatchActions && totalSelected > 0,
|
|
277
|
-
totalSelected,
|
|
278
|
-
onCancel: this.handleOnCancel
|
|
279
|
-
};
|
|
280
|
-
});
|
|
281
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getTableProps", () => {
|
|
282
|
-
const {
|
|
283
|
-
useZebraStyles,
|
|
284
|
-
size = 'lg',
|
|
285
|
-
isSortable,
|
|
286
|
-
useStaticWidth,
|
|
287
|
-
stickyHeader,
|
|
288
|
-
overflowMenuOnHover = false,
|
|
289
|
-
experimentalAutoAlign
|
|
290
|
-
} = this.props;
|
|
291
|
-
return {
|
|
292
|
-
useZebraStyles,
|
|
293
|
-
size,
|
|
294
|
-
isSortable,
|
|
295
|
-
useStaticWidth,
|
|
296
|
-
stickyHeader,
|
|
297
|
-
overflowMenuOnHover,
|
|
298
|
-
experimentalAutoAlign
|
|
299
|
-
};
|
|
300
|
-
});
|
|
301
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getTableContainerProps", () => {
|
|
302
|
-
const {
|
|
303
|
-
stickyHeader,
|
|
304
|
-
useStaticWidth
|
|
305
|
-
} = this.props;
|
|
306
|
-
return {
|
|
307
|
-
stickyHeader,
|
|
308
|
-
useStaticWidth
|
|
280
|
+
disabled: row.disabled,
|
|
281
|
+
radio
|
|
309
282
|
};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
//
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Otherwise, we're working on `TableSelectAll` which handles toggling the
|
|
286
|
+
// selection state of all rows.
|
|
287
|
+
const rowCount = state.rowIds.length;
|
|
288
|
+
const selectedRowCount = getSelectedRows().length;
|
|
289
|
+
const checked = rowCount > 0 && selectedRowCount === rowCount;
|
|
290
|
+
const indeterminate = rowCount > 0 && selectedRowCount > 0 && selectedRowCount !== rowCount;
|
|
291
|
+
const translationKey = checked || indeterminate ? translationKeys.unselectAll : translationKeys.selectAll;
|
|
292
|
+
return {
|
|
293
|
+
...rest,
|
|
294
|
+
'aria-label': t(translationKey),
|
|
295
|
+
checked,
|
|
296
|
+
id: `${getTablePrefix()}__select-all`,
|
|
297
|
+
indeterminate,
|
|
298
|
+
name: `select-all-${instanceId}`,
|
|
299
|
+
onSelect: events.composeEventHandlers([handleSelectAll, onClick])
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
const getToolbarProps = props => {
|
|
303
|
+
const isSmall = size === 'xs' || size === 'sm';
|
|
304
|
+
return {
|
|
305
|
+
...props,
|
|
306
|
+
size: isSmall ? 'sm' : undefined
|
|
307
|
+
};
|
|
308
|
+
};
|
|
309
|
+
const getBatchActionProps = props => {
|
|
310
|
+
const {
|
|
311
|
+
shouldShowBatchActions
|
|
312
|
+
} = state;
|
|
313
|
+
const totalSelected = getSelectedRows().length;
|
|
314
|
+
return {
|
|
315
|
+
onSelectAll: undefined,
|
|
316
|
+
totalCount: state.rowIds.length || 0,
|
|
317
|
+
...props,
|
|
318
|
+
shouldShowBatchActions: shouldShowBatchActions && totalSelected > 0,
|
|
319
|
+
totalSelected,
|
|
320
|
+
onCancel: handleOnCancel
|
|
321
|
+
};
|
|
322
|
+
};
|
|
323
|
+
const getTableProps = () => {
|
|
324
|
+
return {
|
|
325
|
+
useZebraStyles,
|
|
326
|
+
size: size ?? 'lg',
|
|
327
|
+
isSortable: isSortableProp,
|
|
328
|
+
useStaticWidth,
|
|
329
|
+
stickyHeader,
|
|
330
|
+
overflowMenuOnHover: overflowMenuOnHover ?? false,
|
|
331
|
+
experimentalAutoAlign
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
const getTableContainerProps = () => {
|
|
335
|
+
return {
|
|
336
|
+
stickyHeader,
|
|
337
|
+
useStaticWidth
|
|
338
|
+
};
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
// TODO: `getHeaderProps` and `getRowProps` return `key` props. Would it be
|
|
342
|
+
// beneficial for this function to also return a `key` prop?
|
|
343
|
+
/**
|
|
344
|
+
* Get the props associated with the given table cell.
|
|
345
|
+
*/
|
|
346
|
+
const getCellProps = ({
|
|
347
|
+
cell: {
|
|
348
|
+
hasAILabelHeader,
|
|
349
|
+
hasDecoratorHeader
|
|
350
|
+
},
|
|
351
|
+
...rest
|
|
352
|
+
}) => {
|
|
353
|
+
return {
|
|
354
|
+
...rest,
|
|
355
|
+
hasAILabelHeader,
|
|
356
|
+
hasDecoratorHeader
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Helper utility to get all the currently selected rows
|
|
362
|
+
*
|
|
363
|
+
* @returns the array of rowIds that are currently selected
|
|
364
|
+
*/
|
|
365
|
+
const getSelectedRows = () => state.rowIds.filter(id => {
|
|
366
|
+
const row = state.rowsById[id];
|
|
367
|
+
return row.isSelected && !row.disabled;
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Helper utility to get all of the available rows after applying the filter
|
|
372
|
+
*
|
|
373
|
+
* @returns the array of rowIds that are currently included through the filter
|
|
374
|
+
*/
|
|
375
|
+
const getFilteredRowIds = () => {
|
|
376
|
+
const filteredRowIds = typeof state.filterInputValue === 'string' ? filterRows({
|
|
377
|
+
rowIds: state.rowIds,
|
|
378
|
+
headers: headers,
|
|
379
|
+
cellsById: state.cellsById,
|
|
380
|
+
inputValue: state.filterInputValue,
|
|
381
|
+
getCellId: cells.getCellId
|
|
382
|
+
}) : state.rowIds;
|
|
383
|
+
// TODO: Use strict equality check.
|
|
384
|
+
if (filteredRowIds.length == 0) {
|
|
385
|
+
return [];
|
|
386
|
+
}
|
|
387
|
+
return filteredRowIds;
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Helper for getting the table prefix for elements that require an
|
|
392
|
+
* `id` attribute that is unique.
|
|
393
|
+
*/
|
|
394
|
+
const getTablePrefix = () => `data-table-${instanceId}`;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Helper for toggling all selected items in a state. Does not call
|
|
398
|
+
* setState, so use it when setting state.
|
|
399
|
+
*
|
|
400
|
+
* @returns object to put into this.setState (use spread operator)
|
|
401
|
+
*/
|
|
402
|
+
const setAllSelectedState = (initialState, isSelected, filteredRowIds) => {
|
|
403
|
+
const {
|
|
404
|
+
rowIds
|
|
405
|
+
} = initialState;
|
|
406
|
+
// TODO: Use strict inequality check.
|
|
407
|
+
const isFiltered = rowIds.length != filteredRowIds.length;
|
|
408
|
+
return {
|
|
409
|
+
// TODO: Should the `reduce` be typed with `<Record<string,
|
|
410
|
+
// DataTableRow<ColTypes>>>`?
|
|
411
|
+
rowsById: rowIds.reduce((acc, id) => {
|
|
412
|
+
const row = {
|
|
413
|
+
...initialState.rowsById[id]
|
|
414
|
+
};
|
|
415
|
+
if (!row.disabled && (!isFiltered || filteredRowIds.includes(id))) {
|
|
416
|
+
row.isSelected = isSelected;
|
|
417
|
+
}
|
|
418
|
+
acc[id] = row; // Local mutation for performance with large tables
|
|
419
|
+
return acc;
|
|
420
|
+
}, {})
|
|
421
|
+
};
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Handler for the `onCancel` event to hide the batch action bar and
|
|
426
|
+
* deselect all selected rows
|
|
427
|
+
*/
|
|
428
|
+
const handleOnCancel = () => {
|
|
429
|
+
setState(prev => {
|
|
323
430
|
return {
|
|
324
|
-
...
|
|
325
|
-
|
|
326
|
-
|
|
431
|
+
...prev,
|
|
432
|
+
shouldShowBatchActions: false,
|
|
433
|
+
...setAllSelectedState(prev, false, getFilteredRowIds())
|
|
327
434
|
};
|
|
328
435
|
});
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}));
|
|
338
|
-
/**
|
|
339
|
-
* Helper utility to get all of the available rows after applying the filter
|
|
340
|
-
*
|
|
341
|
-
* @returns the array of rowIds that are currently included through the filter
|
|
342
|
-
*/
|
|
343
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getFilteredRowIds", () => {
|
|
344
|
-
const {
|
|
345
|
-
filterRows = filter.defaultFilterRows
|
|
346
|
-
} = this.props;
|
|
347
|
-
const filteredRowIds = typeof this.state.filterInputValue === 'string' ? filterRows({
|
|
348
|
-
rowIds: this.state.rowIds,
|
|
349
|
-
headers: this.props.headers,
|
|
350
|
-
cellsById: this.state.cellsById,
|
|
351
|
-
inputValue: this.state.filterInputValue,
|
|
352
|
-
getCellId: cells.getCellId
|
|
353
|
-
}) : this.state.rowIds;
|
|
354
|
-
if (filteredRowIds.length == 0) {
|
|
355
|
-
return [];
|
|
356
|
-
}
|
|
357
|
-
return filteredRowIds;
|
|
358
|
-
});
|
|
359
|
-
/**
|
|
360
|
-
* Helper for getting the table prefix for elements that require an
|
|
361
|
-
* `id` attribute that is unique.
|
|
362
|
-
*/
|
|
363
|
-
_rollupPluginBabelHelpers.defineProperty(this, "getTablePrefix", () => `data-table-${this.instanceId}`);
|
|
364
|
-
/**
|
|
365
|
-
* Helper for toggling all selected items in a state. Does not call
|
|
366
|
-
* setState, so use it when setting state.
|
|
367
|
-
*
|
|
368
|
-
* @returns object to put into this.setState (use spread operator)
|
|
369
|
-
*/
|
|
370
|
-
_rollupPluginBabelHelpers.defineProperty(this, "setAllSelectedState", (initialState, isSelected, filteredRowIds) => {
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Handler for toggling the selection state of all rows in the database
|
|
440
|
+
*/
|
|
441
|
+
const handleSelectAll = () => {
|
|
442
|
+
setState(prev => {
|
|
443
|
+
const filteredRowIds = getFilteredRowIds();
|
|
371
444
|
const {
|
|
372
|
-
|
|
373
|
-
} =
|
|
374
|
-
const
|
|
445
|
+
rowsById
|
|
446
|
+
} = prev;
|
|
447
|
+
const isSelected = !(Object.values(rowsById).filter(row => row.isSelected && !row.disabled).length > 0);
|
|
375
448
|
return {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
};
|
|
380
|
-
if (!row.disabled && (!isFiltered || filteredRowIds.includes(id))) {
|
|
381
|
-
row.isSelected = isSelected;
|
|
382
|
-
}
|
|
383
|
-
acc[id] = row; // Local mutation for performance with large tables
|
|
384
|
-
return acc;
|
|
385
|
-
}, {})
|
|
449
|
+
...prev,
|
|
450
|
+
shouldShowBatchActions: isSelected,
|
|
451
|
+
...setAllSelectedState(prev, isSelected, filteredRowIds)
|
|
386
452
|
};
|
|
387
453
|
});
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Handler for toggling the selection state of a given row.
|
|
458
|
+
*/
|
|
459
|
+
const handleOnSelectRow = rowId => () => {
|
|
460
|
+
setState(prev => {
|
|
461
|
+
const row = prev.rowsById[rowId];
|
|
462
|
+
if (radio) {
|
|
463
|
+
// TODO:
|
|
464
|
+
// 1. Should the `reduce` be typed with `<Record<string,
|
|
465
|
+
// DataTableRow<ColTypes>>>`?
|
|
466
|
+
// 2. Add better parameter names. Use `acc` and `row`.
|
|
467
|
+
//
|
|
468
|
+
// deselect all radio buttons
|
|
469
|
+
const rowsById = Object.entries(prev.rowsById).reduce((p, c) => {
|
|
470
|
+
const [key, val] = c;
|
|
471
|
+
val.isSelected = false;
|
|
472
|
+
p[key] = val;
|
|
473
|
+
return p;
|
|
474
|
+
}, {});
|
|
394
475
|
return {
|
|
476
|
+
...prev,
|
|
395
477
|
shouldShowBatchActions: false,
|
|
396
|
-
...this.setAllSelectedState(state, false, this.getFilteredRowIds())
|
|
397
|
-
};
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
/**
|
|
401
|
-
* Handler for toggling the selection state of all rows in the database
|
|
402
|
-
*/
|
|
403
|
-
_rollupPluginBabelHelpers.defineProperty(this, "handleSelectAll", () => {
|
|
404
|
-
this.setState(state => {
|
|
405
|
-
const filteredRowIds = this.getFilteredRowIds();
|
|
406
|
-
const {
|
|
407
|
-
rowsById
|
|
408
|
-
} = state;
|
|
409
|
-
const isSelected = !(Object.values(rowsById).filter(row => row.isSelected && !row.disabled).length > 0);
|
|
410
|
-
return {
|
|
411
|
-
shouldShowBatchActions: isSelected,
|
|
412
|
-
...this.setAllSelectedState(state, isSelected, filteredRowIds)
|
|
413
|
-
};
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
/**
|
|
417
|
-
* Handler for toggling the selection state of a given row.
|
|
418
|
-
*/
|
|
419
|
-
_rollupPluginBabelHelpers.defineProperty(this, "handleOnSelectRow", rowId => () => {
|
|
420
|
-
this.setState(state => {
|
|
421
|
-
const row = state.rowsById[rowId];
|
|
422
|
-
if (this.props.radio) {
|
|
423
|
-
// deselect all radio buttons
|
|
424
|
-
const rowsById = Object.entries(state.rowsById).reduce((p, c) => {
|
|
425
|
-
const [key, val] = c;
|
|
426
|
-
val.isSelected = false;
|
|
427
|
-
p[key] = val;
|
|
428
|
-
return p;
|
|
429
|
-
}, {});
|
|
430
|
-
return {
|
|
431
|
-
shouldShowBatchActions: false,
|
|
432
|
-
rowsById: {
|
|
433
|
-
...rowsById,
|
|
434
|
-
[rowId]: {
|
|
435
|
-
...row,
|
|
436
|
-
isSelected: !row.isSelected
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
const selectedRows = state.rowIds.filter(id => state.rowsById[id].isSelected).length;
|
|
442
|
-
// Predict the length of the selected rows after this change occurs
|
|
443
|
-
const selectedRowsCount = !row.isSelected ? selectedRows + 1 : selectedRows - 1;
|
|
444
|
-
return {
|
|
445
|
-
// Basic assumption here is that we want to show the batch action bar if
|
|
446
|
-
// the row is being selected. If it's being unselected, then see if we
|
|
447
|
-
// have a non-zero number of selected rows that batch actions could
|
|
448
|
-
// still apply to
|
|
449
|
-
shouldShowBatchActions: !row.isSelected || selectedRowsCount > 0,
|
|
450
478
|
rowsById: {
|
|
451
|
-
...
|
|
479
|
+
...rowsById,
|
|
452
480
|
[rowId]: {
|
|
453
481
|
...row,
|
|
454
482
|
isSelected: !row.isSelected
|
|
455
483
|
}
|
|
456
484
|
}
|
|
457
485
|
};
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
...
|
|
473
|
-
|
|
474
|
-
...row,
|
|
475
|
-
isExpanded: !row.isExpanded
|
|
476
|
-
}
|
|
486
|
+
}
|
|
487
|
+
const selectedRows = prev.rowIds.filter(id => prev.rowsById[id].isSelected).length;
|
|
488
|
+
// Predict the length of the selected rows after this change occurs
|
|
489
|
+
const selectedRowsCount = !row.isSelected ? selectedRows + 1 : selectedRows - 1;
|
|
490
|
+
return {
|
|
491
|
+
...prev,
|
|
492
|
+
// Basic assumption here is that we want to show the batch action bar if
|
|
493
|
+
// the row is being selected. If it's being unselected, then see if we
|
|
494
|
+
// have a non-zero number of selected rows that batch actions could
|
|
495
|
+
// still apply to
|
|
496
|
+
shouldShowBatchActions: !row.isSelected || selectedRowsCount > 0,
|
|
497
|
+
rowsById: {
|
|
498
|
+
...prev.rowsById,
|
|
499
|
+
[rowId]: {
|
|
500
|
+
...row,
|
|
501
|
+
isSelected: !row.isSelected
|
|
477
502
|
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
/**
|
|
482
|
-
* Handler for changing the expansion state of all rows.
|
|
483
|
-
*/
|
|
484
|
-
_rollupPluginBabelHelpers.defineProperty(this, "handleOnExpandAll", () => {
|
|
485
|
-
this.setState(state => {
|
|
486
|
-
const {
|
|
487
|
-
rowIds,
|
|
488
|
-
isExpandedAll
|
|
489
|
-
} = state;
|
|
490
|
-
return {
|
|
491
|
-
isExpandedAll: !isExpandedAll,
|
|
492
|
-
rowsById: rowIds.reduce((acc, id) => ({
|
|
493
|
-
...acc,
|
|
494
|
-
[id]: {
|
|
495
|
-
...state.rowsById[id],
|
|
496
|
-
isExpanded: !isExpandedAll
|
|
497
|
-
}
|
|
498
|
-
}), {})
|
|
499
|
-
};
|
|
500
|
-
});
|
|
503
|
+
}
|
|
504
|
+
};
|
|
501
505
|
});
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* Handler for toggling the expansion state of a given row.
|
|
510
|
+
*/
|
|
511
|
+
const handleOnExpandRow = rowId => () => {
|
|
512
|
+
setState(prev => {
|
|
513
|
+
const row = prev.rowsById[rowId];
|
|
514
|
+
const {
|
|
515
|
+
isExpandedAll
|
|
516
|
+
} = prev;
|
|
517
|
+
return {
|
|
518
|
+
...prev,
|
|
519
|
+
isExpandedAll: row.isExpanded ? false : isExpandedAll,
|
|
520
|
+
rowsById: {
|
|
521
|
+
...prev.rowsById,
|
|
522
|
+
[rowId]: {
|
|
523
|
+
...row,
|
|
524
|
+
isExpanded: !row.isExpanded
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
};
|
|
511
528
|
});
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
/**
|
|
532
|
+
* Handler for changing the expansion state of all rows.
|
|
533
|
+
*/
|
|
534
|
+
const handleOnExpandAll = () => {
|
|
535
|
+
setState(prev => {
|
|
536
|
+
const {
|
|
537
|
+
rowIds,
|
|
538
|
+
isExpandedAll
|
|
539
|
+
} = prev;
|
|
540
|
+
return {
|
|
541
|
+
...prev,
|
|
542
|
+
isExpandedAll: !isExpandedAll,
|
|
543
|
+
// TODO: Add generic to `reduce`.
|
|
544
|
+
rowsById: rowIds.reduce((acc, id) => ({
|
|
545
|
+
...acc,
|
|
546
|
+
[id]: {
|
|
547
|
+
...prev.rowsById[id],
|
|
548
|
+
isExpanded: !isExpandedAll
|
|
549
|
+
}
|
|
550
|
+
}), {})
|
|
551
|
+
};
|
|
527
552
|
});
|
|
528
|
-
|
|
529
|
-
...getDerivedStateFromProps["default"](_props, {}),
|
|
530
|
-
isExpandedAll: false // Start with collapsed state, treat `undefined` as neutral state
|
|
531
|
-
};
|
|
532
|
-
this.instanceId = getInstanceId();
|
|
533
|
-
}
|
|
553
|
+
};
|
|
534
554
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
}
|
|
557
|
-
render() {
|
|
558
|
-
const {
|
|
559
|
-
children,
|
|
560
|
-
filterRows = filter.defaultFilterRows,
|
|
561
|
-
headers,
|
|
562
|
-
render
|
|
563
|
-
} = this.props;
|
|
564
|
-
const {
|
|
565
|
-
filterInputValue,
|
|
566
|
-
rowIds,
|
|
567
|
-
rowsById,
|
|
568
|
-
cellsById
|
|
569
|
-
} = this.state;
|
|
570
|
-
const filteredRowIds = typeof filterInputValue === 'string' ? filterRows({
|
|
571
|
-
rowIds,
|
|
572
|
-
headers,
|
|
573
|
-
cellsById,
|
|
574
|
-
inputValue: filterInputValue,
|
|
575
|
-
getCellId: cells.getCellId
|
|
576
|
-
}) : rowIds;
|
|
577
|
-
const renderProps = {
|
|
578
|
-
// Data derived from state
|
|
579
|
-
rows: denormalize["default"](filteredRowIds, rowsById, cellsById),
|
|
580
|
-
headers: this.props.headers,
|
|
581
|
-
selectedRows: denormalize["default"](this.getSelectedRows(), rowsById, cellsById),
|
|
582
|
-
// Prop accessors/getters
|
|
583
|
-
getHeaderProps: this.getHeaderProps,
|
|
584
|
-
getExpandHeaderProps: this.getExpandHeaderProps,
|
|
585
|
-
getRowProps: this.getRowProps,
|
|
586
|
-
getExpandedRowProps: this.getExpandedRowProps,
|
|
587
|
-
getSelectionProps: this.getSelectionProps,
|
|
588
|
-
getToolbarProps: this.getToolbarProps,
|
|
589
|
-
getBatchActionProps: this.getBatchActionProps,
|
|
590
|
-
getTableProps: this.getTableProps,
|
|
591
|
-
getTableContainerProps: this.getTableContainerProps,
|
|
592
|
-
getCellProps: this.getCellProps,
|
|
593
|
-
// Custom event handlers
|
|
594
|
-
onInputChange: this.handleOnInputValueChange,
|
|
595
|
-
// Expose internal state change actions
|
|
596
|
-
sortBy: headerKey => this.handleSortBy(headerKey)(),
|
|
597
|
-
selectAll: this.handleSelectAll,
|
|
598
|
-
selectRow: rowId => this.handleOnSelectRow(rowId)(),
|
|
599
|
-
expandRow: rowId => this.handleOnExpandRow(rowId)(),
|
|
600
|
-
expandAll: this.handleOnExpandAll,
|
|
601
|
-
radio: this.props.radio
|
|
602
|
-
};
|
|
603
|
-
if (typeof render !== 'undefined') {
|
|
604
|
-
return render(renderProps);
|
|
555
|
+
/**
|
|
556
|
+
* Handler for transitioning to the next sort state of the table
|
|
557
|
+
*
|
|
558
|
+
* @param headerKey - The field for the header that we are sorting by.
|
|
559
|
+
*/
|
|
560
|
+
const handleSortBy = headerKey => () => {
|
|
561
|
+
setState(prev => sorting.getNextSortState(props, prev, {
|
|
562
|
+
key: headerKey
|
|
563
|
+
}));
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
/**
|
|
567
|
+
* Event handler for transitioning input value state changes for the table
|
|
568
|
+
* filter component.
|
|
569
|
+
*/
|
|
570
|
+
const handleOnInputValueChange = (event, defaultValue) => {
|
|
571
|
+
if (event.target) {
|
|
572
|
+
setState(prev => ({
|
|
573
|
+
...prev,
|
|
574
|
+
filterInputValue: event.target.value
|
|
575
|
+
}));
|
|
605
576
|
}
|
|
606
|
-
if (
|
|
607
|
-
|
|
577
|
+
if (defaultValue) {
|
|
578
|
+
setState(prev => ({
|
|
579
|
+
...prev,
|
|
580
|
+
filterInputValue: defaultValue
|
|
581
|
+
}));
|
|
608
582
|
}
|
|
609
|
-
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
// TODO: Could getFilteredRowIds be used here?
|
|
586
|
+
const filteredRowIds = typeof state.filterInputValue === 'string' ? filterRows({
|
|
587
|
+
rowIds: state.rowIds,
|
|
588
|
+
headers,
|
|
589
|
+
cellsById: state.cellsById,
|
|
590
|
+
inputValue: state.filterInputValue,
|
|
591
|
+
getCellId: cells.getCellId
|
|
592
|
+
}) : state.rowIds;
|
|
593
|
+
const renderProps = {
|
|
594
|
+
// Data derived from state
|
|
595
|
+
rows: denormalize["default"](filteredRowIds, state.rowsById, state.cellsById),
|
|
596
|
+
headers: headers,
|
|
597
|
+
selectedRows: denormalize["default"](getSelectedRows(), state.rowsById, state.cellsById),
|
|
598
|
+
// Prop accessors/getters
|
|
599
|
+
getHeaderProps,
|
|
600
|
+
getExpandHeaderProps,
|
|
601
|
+
getRowProps,
|
|
602
|
+
getExpandedRowProps,
|
|
603
|
+
getSelectionProps,
|
|
604
|
+
getToolbarProps,
|
|
605
|
+
getBatchActionProps,
|
|
606
|
+
getTableProps,
|
|
607
|
+
getTableContainerProps,
|
|
608
|
+
getCellProps,
|
|
609
|
+
// Custom event handlers
|
|
610
|
+
onInputChange: handleOnInputValueChange,
|
|
611
|
+
// Expose internal state change actions
|
|
612
|
+
sortBy: headerKey => handleSortBy(headerKey)(),
|
|
613
|
+
selectAll: handleSelectAll,
|
|
614
|
+
selectRow: rowId => handleOnSelectRow(rowId)(),
|
|
615
|
+
expandRow: rowId => handleOnExpandRow(rowId)(),
|
|
616
|
+
expandAll: handleOnExpandAll,
|
|
617
|
+
radio: radio
|
|
618
|
+
};
|
|
619
|
+
if (typeof render !== 'undefined') {
|
|
620
|
+
return render(renderProps);
|
|
621
|
+
}
|
|
622
|
+
if (typeof children !== 'undefined') {
|
|
623
|
+
return children(renderProps);
|
|
610
624
|
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
// functional component.
|
|
615
|
-
//
|
|
616
|
-
// Static properties for sub-components
|
|
617
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "Table", void 0);
|
|
618
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableActionList", void 0);
|
|
619
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableBatchAction", void 0);
|
|
620
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableBatchActions", void 0);
|
|
621
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableBody", void 0);
|
|
622
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableCell", void 0);
|
|
623
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableContainer", void 0);
|
|
624
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableDecoratorRow", void 0);
|
|
625
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableExpandHeader", void 0);
|
|
626
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableExpandRow", void 0);
|
|
627
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableExpandedRow", void 0);
|
|
628
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableHead", void 0);
|
|
629
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableHeader", void 0);
|
|
630
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableRow", void 0);
|
|
631
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableSelectAll", void 0);
|
|
632
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableSelectRow", void 0);
|
|
633
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableSlugRow", void 0);
|
|
634
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableToolbar", void 0);
|
|
635
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableToolbarAction", void 0);
|
|
636
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableToolbarContent", void 0);
|
|
637
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableToolbarSearch", void 0);
|
|
638
|
-
_rollupPluginBabelHelpers.defineProperty(DataTable, "TableToolbarMenu", void 0);
|
|
625
|
+
return null;
|
|
626
|
+
};
|
|
627
|
+
DataTable.translationKeys = Object.values(translationKeys);
|
|
639
628
|
DataTable.Table = Table.Table;
|
|
640
629
|
DataTable.TableActionList = TableActionList["default"];
|
|
641
630
|
DataTable.TableBatchAction = TableBatchAction["default"];
|
|
@@ -735,4 +724,4 @@ DataTable.propTypes = {
|
|
|
735
724
|
useZebraStyles: PropTypes__default["default"].bool
|
|
736
725
|
};
|
|
737
726
|
|
|
738
|
-
exports
|
|
727
|
+
exports.DataTable = DataTable;
|