diff --git a/packages/module/patternfly-docs/content/examples/Actions.tsx b/packages/module/patternfly-docs/content/examples/Actions.tsx index 7441d3a..90edec0 100644 --- a/packages/module/patternfly-docs/content/examples/Actions.tsx +++ b/packages/module/patternfly-docs/content/examples/Actions.tsx @@ -1,149 +1,105 @@ /* eslint-disable no-console */ import React from 'react'; -import { debounce } from '@patternfly/react-core'; -import { ActionsColumn, TableGridBreakpoint } from '@patternfly/react-table'; -import { Table as TableDeprecated, TableHeader as TableHeaderDeprecated } from '@patternfly/react-table/deprecated'; +import { + ActionsColumn, + Caption, + IActions, + Table, + TableGridBreakpoint, + Td, + Th, + Thead, + Tr +} from '@patternfly/react-table'; import { CellMeasurerCache, CellMeasurer } from 'react-virtualized'; import { AutoSizer, VirtualTableBody } from '@patternfly/react-virtualized-extension'; -export class ActionsExample extends React.Component { - constructor(props) { - super(props); - const rows = []; - for (let i = 0; i < 100; i++) { - rows.push({ - disableActions: i % 3 === 2, - id: `actions-row-${i}`, - cells: [`one-${i}`, `two-${i}`, `three-${i}`, `four-${i}`, `five-${i}`] - }); - } - - this.actionsVirtualBody = null; - - this.state = { - columns: [ - { title: 'Name', props: { className: 'pf-m-6-col-on-sm pf-m-4-col-on-md pf-m-3-col-on-lg pf-m-2-col-on-xl' } }, - { - title: 'Namespace', - props: { className: 'pf-m-6-col-on-sm pf-m-4-col-on-md pf-m-3-col-on-lg pf-m-2-col-on-xl' } - }, - { - title: 'Labels', - props: { className: 'pf-m-4-col-on-md pf-m-4-col-on-lg pf-m-3-col-on-xl pf-m-hidden pf-m-visible-on-md' } - }, - { title: 'Status', props: { className: 'pf-m-2-col-on-lg pf-m-2-col-on-xl pf-m-hidden pf-m-visible-on-lg' } }, - { title: 'Pod Selector', props: { className: 'pf-m-2-col-on-xl pf-m-hidden pf-m-visible-on-xl' } }, - { title: '', props: { className: 'pf-v5-c-table__action' } } - ], - rows, - actions: [ - { - title: 'Some action', - onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Some action, on row: ', rowId) - }, - { - title:
Another action
, - onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Another action, on row: ', rowId) - }, - { - isSeparator: true - }, - { - title: 'Third action', - onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Third action, on row: ', rowId) - } - ] - }; - - this._handleResize = debounce(this._handleResize.bind(this), 100); - } - - componentDidMount() { - // re-render after resize - window.addEventListener('resize', this._handleResize); +export const ActionsExample: React.FunctionComponent = () => { + interface RowType { + disableActions: boolean; + id: string; + cells: string[]; } - componentWillUnmount() { - window.removeEventListener('resize', this._handleResize); - } - - _handleResize() { - this.forceUpdate(); + const rows: RowType[] = []; + for (let i = 0; i < 100; i++) { + rows.push({ + disableActions: i % 3 === 2, + id: `actions-row-${i}`, + cells: [`one-${i}`, `two-${i}`, `three-${i}`, `four-${i}`, `five-${i}`] + }); } - render() { - const { columns, rows } = this.state; + const columns = ['Name', 'Namespace', 'Labels', 'Status', 'Pod Selector']; - const measurementCache = new CellMeasurerCache({ - fixedWidth: true, - minHeight: 44, - keyMapper: (rowIndex) => rowIndex - }); + const actions: IActions = [ + { + title: 'Some action', + onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Some action, on row: ', rowId) + }, + { + title:
Another action
, + onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Another action, on row: ', rowId) + }, + { + isSeparator: true + }, + { + title: 'Third action', + onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Third action, on row: ', rowId) + } + ]; - const rowRenderer = ({ index, _isScrolling, key, style, parent }) => { - const { rows, columns, actions } = this.state; + const measurementCache = new CellMeasurerCache({ + fixedWidth: true, + minHeight: 44, + keyMapper: (rowIndex) => rowIndex + }); - return ( - - - - {rows[index].cells[0]} - - - {rows[index].cells[1]} - - - {rows[index].cells[2]} - - - {rows[index].cells[3]} - - - {rows[index].cells[4]} - - - - - - - ); - }; + const rowRenderer = ({ index: rowIndex, _isScrolling, key, style, parent }) => ( + + + {columns.map((col, index) => ( + {rows[rowIndex].cells[index]} + ))} + + + + + + ); - return ( -
- - - - - {({ width }) => ( - (this.actionsVirtualBody = ref)} - className="pf-v5-c-table pf-v5-c-virtualized pf-v5-c-window-scroller" - deferredMeasurementCache={measurementCache} - rowHeight={measurementCache.rowHeight} - height={400} - overscanRowCount={2} - columnCount={1} - rows={rows} - rowCount={rows.length} - rowRenderer={rowRenderer} - width={width} - role="grid" - /> - )} - -
- ); - } -} + return ( +
+ + + + + + + + + + + + +
Actions VirtualizedTable
{columns[0]}{columns[1]}{columns[2]}{columns[3]}{columns[4]}
+ + {({ width }) => ( + + )} + +
+ ); +}; diff --git a/packages/module/patternfly-docs/generated/extensions/virtual-scroll-table/react.js b/packages/module/patternfly-docs/generated/extensions/virtual-scroll-table/react.js index d73fdba..29ac790 100644 --- a/packages/module/patternfly-docs/generated/extensions/virtual-scroll-table/react.js +++ b/packages/module/patternfly-docs/generated/extensions/virtual-scroll-table/react.js @@ -220,7 +220,7 @@ pageData.examples = { , 'Actions': props => - console.log('clicked on Some action, on row: ', rowId)\n },\n {\n title:
Another action
,\n onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Another action, on row: ', rowId)\n },\n {\n isSeparator: true\n },\n {\n title: 'Third action',\n onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Third action, on row: ', rowId)\n }\n ]\n };\n\n this._handleResize = debounce(this._handleResize.bind(this), 100);\n }\n\n componentDidMount() {\n // re-render after resize\n window.addEventListener('resize', this._handleResize);\n }\n\n componentWillUnmount() {\n window.removeEventListener('resize', this._handleResize);\n }\n\n _handleResize() {\n this.forceUpdate();\n }\n\n render() {\n const { columns, rows } = this.state;\n\n const measurementCache = new CellMeasurerCache({\n fixedWidth: true,\n minHeight: 44,\n keyMapper: (rowIndex) => rowIndex\n });\n\n const rowRenderer = ({ index, _isScrolling, key, style, parent }) => {\n const { rows, columns, actions } = this.state;\n\n return (\n \n \n \n {rows[index].cells[0]}\n \n \n {rows[index].cells[1]}\n \n \n {rows[index].cells[2]}\n \n \n {rows[index].cells[3]}\n \n \n {rows[index].cells[4]}\n \n \n \n \n \n \n );\n };\n\n return (\n
\n \n \n \n \n {({ width }) => (\n (this.actionsVirtualBody = ref)}\n className=\"pf-v5-c-table pf-v5-c-virtualized pf-v5-c-window-scroller\"\n deferredMeasurementCache={measurementCache}\n rowHeight={measurementCache.rowHeight}\n height={400}\n overscanRowCount={2}\n columnCount={1}\n rows={rows}\n rowCount={rows.length}\n rowRenderer={rowRenderer}\n width={width}\n role=\"grid\"\n />\n )}\n \n
\n );\n }\n}\n","title":"Actions","lang":"js"}}> + {\n interface RowType {\n disableActions: boolean;\n id: string;\n cells: string[];\n }\n\n const rows: RowType[] = [];\n for (let i = 0; i < 100; i++) {\n rows.push({\n disableActions: i % 3 === 2,\n id: `actions-row-${i}`,\n cells: [`one-${i}`, `two-${i}`, `three-${i}`, `four-${i}`, `five-${i}`]\n });\n }\n\n const columns = ['Name', 'Namespace', 'Labels', 'Status', 'Pod Selector'];\n\n const actions: IActions = [\n {\n title: 'Some action',\n onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Some action, on row: ', rowId)\n },\n {\n title:
Another action
,\n onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Another action, on row: ', rowId)\n },\n {\n isSeparator: true\n },\n {\n title: 'Third action',\n onClick: (_event, rowId, _rowData, _extra) => console.log('clicked on Third action, on row: ', rowId)\n }\n ];\n\n const measurementCache = new CellMeasurerCache({\n fixedWidth: true,\n minHeight: 44,\n keyMapper: (rowIndex) => rowIndex\n });\n\n const rowRenderer = ({ index: rowIndex, _isScrolling, key, style, parent }) => (\n \n \n {columns.map((col, index) => (\n {rows[rowIndex].cells[index]}\n ))}\n \n \n \n \n \n );\n\n return (\n
\n \n \n \n \n \n \n \n \n \n \n \n \n
Actions VirtualizedTable
{columns[0]}{columns[1]}{columns[2]}{columns[3]}{columns[4]}
\n \n {({ width }) => (\n \n )}\n \n
\n );\n};\n","title":"Actions","lang":"js"}}>
, 'Filterable with WindowScroller': props =>