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 @@ -9,6 +9,7 @@ export interface HeaderCellProps {
isVisible?: boolean;
scope?: string;
textCenter?: boolean;
dataLabel?: string;
}

export const HeaderCell: React.FunctionComponent<HeaderCellProps> = ({
Expand All @@ -17,6 +18,7 @@ export const HeaderCell: React.FunctionComponent<HeaderCellProps> = ({
isVisible,
scope = '',
textCenter = false,
dataLabel = '',
...props
}: HeaderCellProps ) => {
const Component = component as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export interface ICell {
data?: any;
header?: any;
cell?: any;
dataLabel?: string;
}

export interface IRowCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ describe('headerUtils', () => {
expect(result[0].cell.formatters.find((formatter) => formatter.name === 'testFunc')).toBeDefined();
expect(result[0].cell.transforms.find((transform) => transform.name === 'testFunc')).toBeDefined();
});

describe('custom dataLabel', () => {
const cells = [{ title: 'expanded first', dataLabel: 'compact first' }, { title: 'expanded second'}] as ICell[];
const mixed = calculateColumns(cells, {});
cells.forEach((oneCell: ICell, key) => {
test(`${oneCell}`, () => {
expect(mixed[key].props['data-label']).toBe(oneCell.dataLabel ||oneCell.title);
});
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ const generateCell = ({ cellFormatters, cellTransforms, columnTransforms, cell }
/**
* Function to map custom simple object properties to expected format with property, header, cell, extra params
* and props.
* @param {*} column to be shown in header - either string or object with title, transformers and formatters (for cels as well).
* @param {*} column to be shown in header - either string or object with title, transformers and formatters (for cells as well).
* @param {*} extra additional object with callbacks for specific formatters.
* @param {*} key cell key to be shown in data-key.
* @param {*} props additional props for each cell.
* @returns {*} object with property, extraParams, header, cell and props.
*/
const mapHeader = (column: ICell, extra: any, key: number, ...props: any) => {
const title = (column.hasOwnProperty('title') ? column.title : column) as string | ICell;
const dataLabel = (column.hasOwnProperty('dataLabel') ? column.dataLabel : typeof title === 'string' ? title : `column-${key}`) as string | ICell;
return {
property:
(typeof title === 'string' &&
Expand All @@ -80,7 +81,7 @@ const mapHeader = (column: ICell, extra: any, key: number, ...props: any) => {
header: generateHeader(column, title),
cell: generateCell(column, extra),
props: {
'data-label': typeof title === 'string' ? title : `column-${key}`,
'data-label': dataLabel,
'data-key': key,
...(column.hasOwnProperty('props') ? column.props : {}),
...props
Expand Down