-
Notifications
You must be signed in to change notification settings - Fork 377
Closed
Description
Code from Compact expandable table does not work in patternfly-react-seed with "@patternfly/react-table": "^2.13.43".
Error message:
Types of property 'cellFormatters' are incompatible.
Full type error:
Property 'state' in type 'CompactExpandableTable' is not assignable to the same property in base type 'PureComponent<{}, IState, any>'.
Type '{ cells: (string | { cellFormatters: ((value: ReactNode, extra: IExtra) => ReactNode)[]; props: {}; title: string; } | { props: {}; title: string; cellFormatters?: undefined; })[]; rows: ({ cells: string[]; isOpen?: undefined; fullWidth?: undefined; parent?: undefined; noPadding?: undefined; } | { ...; } | { ...; } ...' is not assignable to type 'Readonly<IState>'.
Types of property 'cells' are incompatible.
Type '(string | { cellFormatters: ((value: ReactNode, extra: IExtra) => ReactNode)[]; props: {}; title: string; } | { props: {}; title: string; cellFormatters?: undefined; })[]' is not assignable to type '(string | ICell)[]'.
Type 'string | { cellFormatters: ((value: ReactNode, extra: IExtra) => ReactNode)[]; props: {}; title: string; } | { props: {}; title: string; cellFormatters?: undefined; }' is not assignable to type 'string | ICell'.
Type '{ cellFormatters: ((value: ReactNode, extra: IExtra) => ReactNode)[]; props: {}; title: string; }' is not assignable to type 'string | ICell'.
Type '{ cellFormatters: ((value: ReactNode, extra: IExtra) => ReactNode)[]; props: {}; title: string; }' is not assignable to type 'ICell'.
Types of property 'cellFormatters' are incompatible.
Type '((value: ReactNode, extra: IExtra) => ReactNode)[]' is not assignable to type '((value: any) => IDecorator)[]'.
Type '(value: ReactNode, extra: IExtra) => ReactNode' is not assignable to type '(value: any) => IDecorator'.
Full code:
/**
* Table component.
*/
import * as React from 'react';
import {
IRow,
ICell,
Table,
TableHeader,
TableBody,
TableVariant,
expandable,
} from '@patternfly/react-table';
export interface IState {
cells: Array<ICell | string>;
rows: Array<IRow | string[]>;
}
export class CompactExpandableTable extends React.PureComponent<{}, IState> {
public state = {
cells: [
{
cellFormatters: [expandable],
props: {},
title: 'Header cell',
},
'Branches',
{
props: {},
title: 'Pull requests'
},
'' // deliberately empty
],
rows: [
{
cells: ['one', 'two', 'three', 'four']
},
{
cells: ['parent - 1', 'two', 'three', 'four'],
isOpen: true
},
{
cells: ['child - 1'],
fullWidth: true,
parent: 1,
},
{
cells: ['parent - 2', 'two', 'three', 'four'],
isOpen: false
},
{
cells: ['child - 2'],
parent: 3
},
{
cells: ['parent - 3', 'two', 'three', 'four'],
isOpen: false
},
{
cells: ['child - 3'],
fullWidth: true,
noPadding: true,
parent: 5
}
]
};
public render() {
const { cells, rows } = this.state;
return (
<Table
caption="Compact expandable table"
variant={TableVariant.compact}
onCollapse={this.onCollapse}
rows={rows}
cells={cells}
>
<TableHeader />
<TableBody />
</Table>
);
}
private onCollapse(_, rowKey, isOpen) {
const { rows } = this.state;
/**
* Please do not use rowKey as row index for more complex tables.
* Rather use some kind of identifier like ID passed with each row.
*/
rows[rowKey].isOpen = isOpen;
this.setState({
rows
});
}
}
export default CompactExpandableTable;Metadata
Metadata
Assignees
Labels
No labels