Skip to content

Commit

Permalink
Merge branch 'v6' into upgradeBasicDemo
Browse files Browse the repository at this point in the history
  • Loading branch information
wise-king-sullyman committed Dec 5, 2023
2 parents 5bda599 + b450ab4 commit ded623f
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 284 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- v6
jobs:
call-build-lint-test-workflow:
uses: ./.github/workflows/build-lint-test.yml
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- v6
jobs:
call-build-lint-test-workflow:
uses: ./.github/workflows/build-lint-test.yml
Expand Down
18 changes: 9 additions & 9 deletions packages/module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@patternfly/react-virtualized-extension",
"version": "0.0.0",
"version": "6.0.0-alpha.0",
"description": "This library provides efficient rendering extensions for PatternFly React tables and lists.",
"main": "dist/js/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -36,12 +36,12 @@
"homepage": "https://github.com/patternfly/react-virtualized-extension#readme",
"publishConfig": {
"access": "public",
"tag": "prerelease"
"tag": "alpha"
},
"dependencies": {
"@patternfly/react-core": "^5.0.0",
"@patternfly/react-icons": "^5.0.0",
"@patternfly/react-styles": "^5.0.0",
"@patternfly/react-core": "^6.0.0-alpha.1",
"@patternfly/react-icons": "^6.0.0-alpha.1",
"@patternfly/react-styles": "^6.0.0-alpha.1",
"linear-layout-vector": "0.0.1",
"react-virtualized": "^9.22.5",
"tslib": "^2.5.2"
Expand All @@ -51,10 +51,10 @@
"react-dom": "^17 || ^18"
},
"devDependencies": {
"@patternfly/documentation-framework": "^5.0.15",
"@patternfly/patternfly": "^5.0.0",
"@patternfly/react-table": "^5.0.0",
"@patternfly/react-code-editor": "^5.0.0",
"@patternfly/documentation-framework": "^5.2.22",
"@patternfly/patternfly": "^6.0.0-alpha.9",
"@patternfly/react-table": "^6.0.0-alpha.1",
"@patternfly/react-code-editor": "^6.0.0-alpha.1",
"rimraf": "^5.0.1",
"@patternfly/patternfly-a11y": "^4.3.1",
"react-monaco-editor": "^0.51.0",
Expand Down
228 changes: 92 additions & 136 deletions packages/module/patternfly-docs/content/examples/Actions.tsx
Original file line number Diff line number Diff line change
@@ -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: <div>Another action</div>,
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: <div>Another action</div>,
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 (
<CellMeasurer cache={measurementCache} columnIndex={0} key={key} parent={parent} rowIndex={index}>
<tr data-id={index} style={style} role="row">
<td className={columns[0].props.className} role="gridcell">
{rows[index].cells[0]}
</td>
<td className={columns[1].props.className} role="gridcell">
{rows[index].cells[1]}
</td>
<td className={columns[2].props.className} role="gridcell">
{rows[index].cells[2]}
</td>
<td className={columns[3].props.className} role="gridcell">
{rows[index].cells[3]}
</td>
<td className={columns[4].props.className} role="gridcell">
{rows[index].cells[4]}
</td>
<td className={columns[5].props.className} role="gridcell">
<ActionsColumn
items={actions}
rowData={rows[index]}
extraData={{ rowIndex: index }}
isDisabled={rows[index].disableActions}
/>
</td>
</tr>
</CellMeasurer>
);
};
const rowRenderer = ({ index: rowIndex, _isScrolling, key, style, parent }) => (
<CellMeasurer cache={measurementCache} columnIndex={0} key={key} parent={parent} rowIndex={rowIndex}>
<Tr resetOffset style={style}>
{columns.map((col, index) => (
<Td key={`${rowIndex}-${index + 1}`}>{rows[rowIndex].cells[index]}</Td>
))}
<Td isActionCell>
<ActionsColumn items={actions} isDisabled={rows[rowIndex].disableActions} />
</Td>
</Tr>
</CellMeasurer>
);

return (
<div aria-label="Scrollable Table" className="pf-v5-c-scrollablegrid">
<TableDeprecated
caption="Actions Virtualized Table"
cells={columns}
rows={rows}
gridBreakPoint={TableGridBreakpoint.none}
aria-rowcount={rows.length}
>
<TableHeaderDeprecated />
</TableDeprecated>
<AutoSizer disableHeight>
{({ width }) => (
<VirtualTableBody
ref={(ref) => (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"
/>
)}
</AutoSizer>
</div>
);
}
}
return (
<div aria-label="Scrollable Table" className="pf-v5-c-scrollablegrid">
<Table gridBreakPoint={TableGridBreakpoint.none} aria-rowcount={rows.length} variant="compact">
<Caption>Actions VirtualizedTable</Caption>
<Thead>
<Tr>
<Th key={0}>{columns[0]}</Th>
<Th key={1}>{columns[1]}</Th>
<Th key={2}>{columns[2]}</Th>
<Th key={3}>{columns[3]}</Th>
<Th key={4}>{columns[4]}</Th>
<Td isActionCell></Td>
</Tr>
</Thead>
</Table>
<AutoSizer disableHeight>
{({ width }) => (
<VirtualTableBody
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}
/>
)}
</AutoSizer>
</div>
);
};
Loading

0 comments on commit ded623f

Please sign in to comment.