FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(table): Adds support for custom dataLabel prop on table header by AllenBW · Pull Request #3040 · patternfly/patternfly-react · GitHub

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

Filter by extension

Filter by extension .tsx  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
    • HeaderCell.tsx
    • Table.tsx
      • headerUtils.test.tsx
      • headerUtils.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL