Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
headerCol,
sortable,
expandable,
compoundExpand
compoundExpand, IRow
} from './index';
import { rows, columns, actions } from '../../test-helpers/data-sets';
import { ColumnsType } from './base';

describe('Simple table', () => {
test('caption', () => {
Expand Down Expand Up @@ -144,11 +145,11 @@ test('Collapsible table', () => {
});

test('Compound Expandable table', () => {
const compoundColumns: any = [
const compoundColumns: ColumnsType = [
{ title: 'col1', cell: { transforms: [compoundExpand] } },
{ title: 'col2', cell: { transforms: [compoundExpand] } }
];
const compoundRows: any = [
const compoundRows: IRow[] = [
{ isOpen: true, cells: [{ title: '1', props: { isOpen: true } }, { title: '2', props: { isOpen: false } }] },
{ parent: 0, compoundParent: 0, cells: [{ title: 'expanded', props: { colSpan: 2 } }] },
{ isOpen: false, cells: [{ title: '3', props: { isOpen: false } }, { title: '4', props: { isOpen: false } }] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface IExtra extends IExtraData {

export type IFormatterValueType = formatterValueType & {
title?: string | React.ReactNode;
props: any;
props?: any;
};

export interface ISortBy {
Expand Down Expand Up @@ -137,7 +137,7 @@ export interface IRowCell {
}

export interface IRow extends RowType {
cells: (React.ReactNode | IRowCell)[];
cells?: (React.ReactNode | IRowCell)[];
isOpen?: boolean;
parent?: number;
props?: any;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IRowCell } from '../Table';

export const defaultTitle = (data: IRowCell) => (data && data.hasOwnProperty('title') ? data.title : data);
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ import {
textCenter
} from './transformers';
import { DropdownDirection, DropdownPosition } from '@patternfly/react-core';
import { IActions, IActionsResolver, IAreActionsDisabled, IExtraData, IRowData } from '../Table';

const testCellActions = ({ actions, actionResolver, areActionsDisabled, rowData, expectDisabled }) => {
const testCellActions = (
{ actions }: { actions: IActions },
{ actionResolver }: { actionResolver: IActionsResolver },
{ areActionsDisabled }: { areActionsDisabled: IAreActionsDisabled },
{ rowData }: { rowData: IRowData },
{ extraData }: { extraData: IExtraData },
{ expectDisabled }: { expectDisabled: boolean }
) => {
const returnedData = cellActions(actions, actionResolver, areActionsDisabled)('', {
rowIndex: 0,
rowData,
Expand All @@ -28,7 +36,7 @@ const testCellActions = ({ actions, actionResolver, areActionsDisabled, rowData,
});

if (actionResolver) {
actions = actionResolver(rowData);
actions = actionResolver(rowData, extraData);
}

expect(returnedData).toMatchObject({ className: 'pf-c-table__action' });
Expand Down Expand Up @@ -135,7 +143,7 @@ describe('Transformer functions', () => {
actions
},
{
actionResolver: () => null
actionResolver: () => null as any
},
{
actionResolver: () => actions
Expand Down Expand Up @@ -165,7 +173,7 @@ describe('Transformer functions', () => {
const widths = [10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 'max'];
widths.forEach(width =>
test(`${width}`, () => {
expect(cellWidth(width)()).toEqual({ className: `pf-m-width-${width}` });
expect(cellWidth(width as string)()).toEqual({ className: `pf-m-width-${width}` });
})
);
});
Expand Down Expand Up @@ -212,27 +220,27 @@ describe('Transformer functions', () => {

describe('expandedRow', () => {
test('with parent', () => {
const returned = expandedRow(5)(
const returned = expandedRow(String(5))(
{ title: 'test' },
{ rowIndex: 2, rowData: { parent: 1 }, column: { extraParams: {} } }
);
expect(returned).toMatchObject({ colSpan: 5, id: 'expanded-content2' });
});

test('no parent', () => {
expect(expandedRow(5)({ title: 'test' }, { rowData: {}, column: { extraParams: {} } })).toBe(false);
expect(expandedRow(String(5))({ title: 'test' }, { rowData: {}, column: { extraParams: {} } })).toBe(false);
});

test('full width', () => {
const returned = expandedRow(5)(
const returned = expandedRow(String(5))(
{ title: 'test' },
{ rowIndex: 2, rowData: { parent: 1, fullWidth: true }, column: { extraParams: {} } }
);
expect(returned).toMatchObject({ colSpan: 6, id: 'expanded-content2' });
});

test('no padding', () => {
const returned = expandedRow(5)(
const returned = expandedRow(String(5))(
{ title: 'test' },
{ rowIndex: 2, rowData: { parent: 1, noPadding: true }, column: { extraParams: {} } }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export { compoundExpand } from './decorators/compoundExpand';
export { headerCol } from './decorators/headerCol';
export { classNames, Visibility } from './decorators/classNames';

import { IFormatterValueType, IExtra } from '../Table';

export const emptyTD = () => ({
scope: '',
component: 'td'
Expand All @@ -17,14 +19,14 @@ export const scopeColTransformer = () => ({
scope: 'col'
});

export const emptyCol = label => ({
export const emptyCol = (label: IFormatterValueType) => ({
...(label ? {} : { scope: '' })
});

export const parentId = (_value, { rowData }) => ({
export const parentId = (_value: IFormatterValueType, { rowData }: IExtra) => ({
parentId: rowData.parent
});

export const mapProps = (_label, { property, rowData }) => ({
export const mapProps = (_label: IFormatterValueType, { property, rowData }: IExtra) => ({
...(rowData[property] && rowData[property].props)
});