| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 3 |
import { Component } from 'react'; |
| 4 |
import { getDefaultOUIAId } from '@patternfly/react-core/dist/esm/helpers/OUIA/ouia'; |
| 5 |
import inlineStyles from '@patternfly/react-styles/css/components/InlineEdit/inline-edit.mjs'; |
| 6 |
import { css } from '@patternfly/react-styles'; |
| 7 |
import { Provider } from '../../../components/Table/base/provider'; |
| 8 |
import { BodyCell } from './BodyCell'; |
| 9 |
import { HeaderCell } from './HeaderCell'; |
| 10 |
import { RowWrapper } from '../../../components'; |
| 11 |
import { BodyWrapper } from './BodyWrapper'; |
| 12 |
import { calculateColumns, RowSelectVariant } from '../../../components'; |
| 13 |
import { TableContext } from './TableContext'; |
| 14 |
import { TableGridBreakpoint, TreeRowWrapper } from '../../../components'; |
| 15 |
class Table extends Component { |
| 16 |
constructor() { |
| 17 |
super(...arguments); |
| 18 |
this.state = { |
| 19 |
ouiaStateId: getDefaultOUIAId(Table.displayName) |
| 20 |
}; |
| 21 |
this.isSelected = (row) => row.selected === true; |
| 22 |
this.areAllRowsSelected = (rows) => { |
| 23 |
if (rows === undefined || rows.length === 0) { |
| 24 |
return false; |
| 25 |
} |
| 26 |
return rows.every((row) => this.isSelected(row) || row.disableSelection || (row.hasOwnProperty('parent') && !row.showSelect)); |
| 27 |
}; |
| 28 |
this.areAllExpanded = (rows) => { |
| 29 |
if (rows === undefined || rows.length === 0) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
return rows.every((row) => row.isOpen === undefined || row.isOpen); |
| 33 |
}; |
| 34 |
} |
| 35 |
render() { |
| 36 |
const _a = this.props, { 'aria-label': ariaLabel, caption, header, onSort, onSelect, canSelectAll, canCollapseAll, isHeaderSelectDisabled, selectVariant, collapseAllAriaLabel, sortBy, children, actions, actionResolver, areActionsDisabled, onCollapse, onExpand, onRowEdit, rowLabeledBy, dropdownPosition, dropdownDirection, actionsMenuAppendTo: menuAppendTo, actionsToggle, contentId, expandId, variant, rows, cells, bodyWrapper, rowWrapper, role, borders, onFavorite, canSortFavorites } = _a, props = __rest(_a, ['aria-label', "caption", "header", "onSort", "onSelect", "canSelectAll", "canCollapseAll", "isHeaderSelectDisabled", "selectVariant", "collapseAllAriaLabel", "sortBy", "children", "actions", "actionResolver", "areActionsDisabled", "onCollapse", "onExpand", "onRowEdit", "rowLabeledBy", "dropdownPosition", "dropdownDirection", "actionsMenuAppendTo", "actionsToggle", "contentId", "expandId", "variant", "rows", "cells", "bodyWrapper", "rowWrapper", "role", "borders", "onFavorite", "canSortFavorites"]); |
| 37 |
if (!ariaLabel && !caption && !header && role !== 'presentation') { |
| 38 |
// eslint-disable-next-line no-console |
| 39 |
console.error('Table: Specify at least one of: header, caption, aria-label'); |
| 40 |
} |
| 41 |
const headerData = calculateColumns(cells, { |
| 42 |
sortBy, |
| 43 |
onSort, |
| 44 |
onSelect, |
| 45 |
canSelectAll: selectVariant === RowSelectVariant.radio ? false : canSelectAll, |
| 46 |
canCollapseAll, |
| 47 |
isHeaderSelectDisabled, |
| 48 |
selectVariant, |
| 49 |
collapseAllAriaLabel, |
| 50 |
allRowsSelected: onSelect ? this.areAllRowsSelected(rows) : false, |
| 51 |
allRowsExpanded: onCollapse ? this.areAllExpanded(rows) : false, |
| 52 |
actions, |
| 53 |
actionResolver, |
| 54 |
areActionsDisabled, |
| 55 |
onCollapse, |
| 56 |
onRowEdit, |
| 57 |
onExpand, |
| 58 |
rowLabeledBy, |
| 59 |
expandId, |
| 60 |
contentId, |
| 61 |
dropdownPosition, |
| 62 |
dropdownDirection, |
| 63 |
menuAppendTo, |
| 64 |
actionsToggle, |
| 65 |
onFavorite, |
| 66 |
canSortFavorites, |
| 67 |
// order of columns: Collapsible | Selectable | Favoritable |
| 68 |
firstUserColumnIndex: [onCollapse, onSelect, onFavorite].filter((callback) => callback).length |
| 69 |
}); |
| 70 |
const table = (_jsxs(TableContext.Provider, { value: { |
| 71 |
headerData, |
| 72 |
headerRows: null, |
| 73 |
rows |
| 74 |
}, children: [header, _jsxs(Provider, Object.assign({}, props, { "aria-label": ariaLabel, renderers: { |
| 75 |
body: { |
| 76 |
wrapper: bodyWrapper || BodyWrapper, |
| 77 |
row: rowWrapper || (this.props.isTreeTable ? TreeRowWrapper : RowWrapper), |
| 78 |
cell: BodyCell |
| 79 |
}, |
| 80 |
header: { |
| 81 |
cell: HeaderCell |
| 82 |
} |
| 83 |
}, columns: headerData, role: role, variant: variant, borders: borders, children: [caption && _jsx("caption", { children: caption }), children] }))] })); |
| 84 |
if (onRowEdit) { |
| 85 |
return _jsx("form", { className: css(inlineStyles.inlineEdit), children: table }); |
| 86 |
} |
| 87 |
return table; |
| 88 |
} |
| 89 |
} |
| 90 |
Table.displayName = 'Table'; |
| 91 |
Table.hasWarnBeta = false; |
| 92 |
Table.defaultProps = { |
| 93 |
children: null, |
| 94 |
className: '', |
| 95 |
variant: null, |
| 96 |
borders: true, |
| 97 |
rowLabeledBy: 'simple-node', |
| 98 |
expandId: 'expandable-toggle', |
| 99 |
contentId: 'expanded-content', |
| 100 |
dropdownPosition: 'right', |
| 101 |
dropdownDirection: 'down', |
| 102 |
actionsMenuAppendTo: 'inline', |
| 103 |
header: undefined, |
| 104 |
caption: undefined, |
| 105 |
'aria-label': undefined, |
| 106 |
gridBreakPoint: TableGridBreakpoint.gridMd, |
| 107 |
role: 'grid', |
| 108 |
canSelectAll: true, |
| 109 |
canCollapseAll: false, |
| 110 |
isHeaderSelectDisabled: false, |
| 111 |
selectVariant: 'checkbox', |
| 112 |
collapseAllAriaLabel: '', |
| 113 |
ouiaSafe: true, |
| 114 |
isStickyHeader: false, |
| 115 |
canSortFavorites: true, |
| 116 |
isTreeTable: false, |
| 117 |
isNested: false |
| 118 |
}; |
| 119 |
export { Table }; |
| 120 |
//# sourceMappingURL=Table.js.map |