Skip to content

Commit

Permalink
fix(TDOPS-872): VList content cell should display a tooltip for 0 val…
Browse files Browse the repository at this point in the history
…ue (#4901)

* fix(TDOPS-872): VList content cell should display a tooltip for 0 value

* enhance proptypes and fix tests

* Cleanup
  • Loading branch information
Gbacc authored Sep 22, 2023
1 parent 9435bbc commit 387afd9
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tall-beds-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-components': patch
---

TDOPS-872 - VList cell content should display a tooltip for 0 value as well
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ exports[`CellMappedData should render checked mapped data cell for a string valu
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Value 1
</div>
Expand Down
20 changes: 13 additions & 7 deletions packages/components/src/VirtualizedList/Content.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,29 @@ import TooltipTrigger from '../TooltipTrigger';

function DefaultRenderer({ cellData, columnData, rowData }) {
const { getTooltipLabel } = columnData;
let tooltipLabel = columnData.tooltipLabel || cellData;
let tooltipLabel = columnData.tooltipLabel != null ? columnData.tooltipLabel : cellData;
if (typeof getTooltipLabel === 'function') {
tooltipLabel = getTooltipLabel(rowData);
}
return tooltipLabel ? (
return tooltipLabel != null ? (
<TooltipTrigger label={tooltipLabel} tooltipPlacement={columnData.tooltipPlacement || 'top'}>
<div className="tc-virtualizedlist-default-cell">{cellData}</div>
<div
className="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
{cellData}
</div>
</TooltipTrigger>
) : (
<div className="tc-virtualizedlist-default-cell">{cellData}</div>
);
}
DefaultRenderer.propTypes = {
cellData: PropTypes.string,
cellData: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
rowData: PropTypes.object,
columnData: PropTypes.shape({
tooltipLabel: PropTypes.string,
tooltipLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
tooltipPlacement: PropTypes.string,
getTooltipLabel: PropTypes.func,
}),
Expand All @@ -41,11 +47,11 @@ export default function Content() {
Content.displayName = 'Content';
Content.defaultProps = defaultColumnConfiguration;
Content.propTypes = {
label: PropTypes.string.isRequired,
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
dataKey: PropTypes.string.isRequired,
width: PropTypes.number.isRequired,
columnData: PropTypes.shape({
tooltipLabel: PropTypes.string,
tooltipLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
tooltipPlacement: PropTypes.string,
getTooltipLabel: PropTypes.func,
}).isRequired,
Expand Down
32 changes: 32 additions & 0 deletions packages/components/src/VirtualizedList/Content.component.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { render, screen } from '@testing-library/react';
import { defaultColumnConfiguration } from './Content.component';

jest.unmock('@talend/design-system');

describe('CellLabel', () => {
const CellContent = defaultColumnConfiguration.cellRenderer;
it('should default render a label', () => {
// given
const label = 'my label';
// when
const { container } = render(<CellContent cellData={label} columnData={{}} />);
// then
expect(container.firstChild).toMatchSnapshot();
});

it('should render a tooltip if available', () => {
// given
const label = 'my label';
// when
render(
<CellContent
cellData={label}
columnData={{
tooltipLabel: 0,
}}
/>,
);
// then
expect(screen.getByTestId('tc-virtualizedlist-default-cell-tooltip')).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ exports[`ListGrid should render react-virtualized list 1`] = `
class="theme-field-value"
>
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
0
</div>
Expand All @@ -69,6 +72,8 @@ exports[`ListGrid should render react-virtualized list 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title with icon and actions
</div>
Expand All @@ -90,6 +95,8 @@ exports[`ListGrid should render react-virtualized list 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row with icon and actions
</div>
Expand Down Expand Up @@ -132,6 +139,8 @@ exports[`ListGrid should render react-virtualized list 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
1
</div>
Expand All @@ -153,6 +162,8 @@ exports[`ListGrid should render react-virtualized list 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title without actions
</div>
Expand All @@ -174,6 +185,8 @@ exports[`ListGrid should render react-virtualized list 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row without actions
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ exports[`ListGrid should render react-virtualized table 1`] = `
style="overflow: hidden; flex: 0 1 0px;"
>
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
0
</div>
Expand All @@ -87,6 +90,8 @@ exports[`ListGrid should render react-virtualized table 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title with icon and actions
</div>
Expand All @@ -100,6 +105,8 @@ exports[`ListGrid should render react-virtualized table 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row with icon and actions
</div>
Expand All @@ -120,6 +127,8 @@ exports[`ListGrid should render react-virtualized table 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
1
</div>
Expand All @@ -133,6 +142,8 @@ exports[`ListGrid should render react-virtualized table 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title without actions
</div>
Expand All @@ -146,6 +157,8 @@ exports[`ListGrid should render react-virtualized table 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row without actions
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ exports[`RowLarge should render large row 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
1
</div>
Expand All @@ -104,6 +106,8 @@ exports[`RowLarge should render large row 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title from second item
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CellLabel should default render a label 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
my label
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ exports[`RendererSelector should render table list by default 1`] = `
style="overflow: hidden; flex: 0 0 50px;"
>
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
0
</div>
Expand All @@ -114,6 +117,8 @@ exports[`RendererSelector should render table list by default 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title with icon and actions
</div>
Expand All @@ -127,6 +132,8 @@ exports[`RendererSelector should render table list by default 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row with icon and actions
</div>
Expand All @@ -149,6 +156,8 @@ exports[`RendererSelector should render table list by default 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
1
</div>
Expand All @@ -162,6 +171,8 @@ exports[`RendererSelector should render table list by default 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title without actions
</div>
Expand All @@ -175,6 +186,8 @@ exports[`RendererSelector should render table list by default 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row without actions
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ exports[`VirtualizedList should render 1`] = `
style="overflow: hidden; flex: 0 0 50px;"
>
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
0
</div>
Expand All @@ -155,6 +158,8 @@ exports[`VirtualizedList should render 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title with icon and actions
</div>
Expand All @@ -168,6 +173,8 @@ exports[`VirtualizedList should render 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row with icon and actions
</div>
Expand Down Expand Up @@ -221,6 +228,8 @@ exports[`VirtualizedList should render 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
1
</div>
Expand All @@ -234,6 +243,8 @@ exports[`VirtualizedList should render 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Title without actions
</div>
Expand All @@ -247,6 +258,8 @@ exports[`VirtualizedList should render 1`] = `
<div
aria-describedby="42"
class="tc-virtualizedlist-default-cell"
data-test="tc-virtualizedlist-default-cell-tooltip"
data-testid="tc-virtualizedlist-default-cell-tooltip"
>
Simple row without actions
</div>
Expand Down

0 comments on commit 387afd9

Please sign in to comment.