Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Table): Add Tree Table variant #5573

Merged
merged 9 commits into from
Mar 30, 2021
4 changes: 3 additions & 1 deletion packages/react-docs/patternfly-a11y.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ module.exports = {
urls: Object.keys(fullscreenRoutes),
ignoreRules: 'color-contrast,page-has-heading-one,scrollable-region-focusable,bypass',
ignoreIncomplete: true,
skip: /^\/charts\//
// tree-table examples are skipped because aria-level, aria-posinset, aria-setsize are intentionally
// being used slightly unconventionally in those examples
skip: /^\/charts\/|tree-table$/
};
5 changes: 3 additions & 2 deletions packages/react-table/src/components/Table/RowWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { OUIAProps } from '@patternfly/react-core/dist/js/helpers/OUIA/ouia';
import { debounce } from '@patternfly/react-core/dist/js/helpers/util';
import { Tr } from '../TableComposable/Tr';
import { IRow } from './TableTypes';

// legacy export now, RowWrapperRow can simply be typed as IRow in the future
export interface RowWrapperRow {
Expand All @@ -15,7 +16,7 @@ export interface RowWrapperProps extends OUIAProps {
className?: string;
onScroll?: React.UIEventHandler;
onResize?: React.UIEventHandler;
row?: RowWrapperRow;
row?: IRow;
rowProps?: {
rowIndex: number;
rowKey: string;
Expand All @@ -31,7 +32,7 @@ export class RowWrapper extends React.Component<RowWrapperProps> {
isExpanded: undefined as boolean,
isHeightAuto: undefined as boolean,
isEditable: undefined as boolean
} as RowWrapperRow,
} as IRow,
rowProps: null as any
};
_unmounted: boolean;
Expand Down
10 changes: 6 additions & 4 deletions packages/react-table/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
IHeaderRow,
OnFavorite
} from './TableTypes';
import { TreeRowWrapper } from './TreeRowWrapper';

export interface TableProps extends OUIAProps {
/** Adds an accessible name for the Table */
Expand Down Expand Up @@ -104,6 +105,8 @@ export interface TableProps extends OUIAProps {
onFavorite?: OnFavorite;
/** Along with the onSort prop, enables favorites sorting, defaults to true */
canSortFavorites?: boolean;
/** Flag indicating table is a tree table */
isTreeTable?: boolean;
}

export class Table extends React.Component<TableProps, {}> {
Expand All @@ -128,7 +131,8 @@ export class Table extends React.Component<TableProps, {}> {
selectVariant: 'checkbox',
ouiaSafe: true,
isStickyHeader: false,
canSortFavorites: true
canSortFavorites: true,
isTreeTable: false
};
state = {
ouiaStateId: getDefaultOUIAId(Table.displayName)
Expand Down Expand Up @@ -158,7 +162,6 @@ export class Table extends React.Component<TableProps, {}> {
'aria-label': ariaLabel,
caption,
header,
className,
onSort,
onSelect,
canSelectAll,
Expand Down Expand Up @@ -232,7 +235,7 @@ export class Table extends React.Component<TableProps, {}> {
renderers={{
body: {
wrapper: bodyWrapper || BodyWrapper,
row: rowWrapper || RowWrapper,
row: rowWrapper || (this.props.isTreeTable ? TreeRowWrapper : RowWrapper),
cell: BodyCell
},
header: {
Expand All @@ -243,7 +246,6 @@ export class Table extends React.Component<TableProps, {}> {
role={role}
variant={variant}
borders={borders}
className={className}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had changed the props a handful of times while working on this, so in the end while cleaning stuff up, I guess I realized that className was being pulled out of props unnecessarily on line 161. I can put it back, but it's now passed when I spread props to the Provider on line 230.

>
{caption && <caption>{caption}</caption>}
{children}
Expand Down
9 changes: 9 additions & 0 deletions packages/react-table/src/components/Table/TableTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DropdownDirection,
DropdownPosition
} from '@patternfly/react-core/dist/js/components/Dropdown/dropdownConstants';
import * as React from 'react';

export enum TableGridBreakpoint {
none = '',
Expand Down Expand Up @@ -67,6 +68,14 @@ export type OnFavorite = (
rowData: IRowData,
extraData: IExtraData
) => void;
export type OnTreeRowCollapse = (event: any, rowIndex: number, title: React.ReactNode, rowData: IRowData) => void;
export type OnCheckChange = (
event: React.FormEvent<HTMLInputElement>,
isChecked: boolean,
rowIndex: number,
title: React.ReactNode,
rowData: IRowData
) => void;

// Todo: Update type with next breaking change release
// export type IHeaderRow = ColumnType;
Expand Down
27 changes: 27 additions & 0 deletions packages/react-table/src/components/Table/TreeRowWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Table/table';
import { RowWrapperProps } from './RowWrapper';
import { Tr } from '../TableComposable';

export const TreeRowWrapper: React.FunctionComponent<RowWrapperProps> = ({
className,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
rowProps,
Copy link
Contributor

@kmcfaul kmcfaul Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is rowProps something used in only non-composable tables? Why is it being withheld from spreading to the Tr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not totally sure all the reasons the rowData prop exists. At the very least it keeps track of rowIndex and rowKey for the sake of certain callback functions. But, I know that it's already being withheld in the RowWrapper, and if I don't withhold it in the TreeRowWrapper, it spreads all the way to the <tr> element and causes a console warning.

row,
...props
}: RowWrapperProps) => {
const { 'aria-level': level, 'aria-posinset': posinset, 'aria-setsize': setsize, isExpanded, isHidden } = row.props;
return (
<Tr
aria-level={level}
aria-posinset={posinset}
aria-setsize={setsize}
aria-expanded={!!isExpanded}
isHidden={isHidden}
className={css(className, isExpanded && 'pf-m-expandable', isExpanded && styles.modifiers.expanded)}
{...props}
/>
);
};
TreeRowWrapper.displayName = 'TreeRowWrapper';
Loading