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