Skip to content

Commit

Permalink
fix: display 'and x others...' on tooltip (DHIS2-8753) v32 backport (#…
Browse files Browse the repository at this point in the history
…945)

DHIS2-8753 fix for v32. Backported #927 by cherry-picking dd62dbb and generating a new pot file. Please see the original PR for details (#925)
  • Loading branch information
martinkrulltott committed May 20, 2020
1 parent c090592 commit 0590fdf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/app/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ msgstr ""
msgid "None selected"
msgstr ""

msgid "And 1 other..."
msgstr ""

msgid "And {{numberOfItems}} others..."
msgstr ""

msgid "Unsaved chart"
msgstr ""

Expand Down
35 changes: 26 additions & 9 deletions packages/app/src/components/Layout/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,39 @@ const labels = {
const emptyItems = [];

export class Tooltip extends React.Component {
renderItems = itemDisplayNames => {
const renderLimit = 5;

const itemsToRender = itemDisplayNames
.slice(0, renderLimit)
.map(name => (
<li key={`${this.props.dimensionId}-${name}`}>{name}</li>
));

if (itemDisplayNames.length > renderLimit) {
itemsToRender.push(
<li key={`${this.props.dimensionId}-render-limit`}>
{itemDisplayNames.length - renderLimit === 1
? i18n.t('And 1 other...')
: i18n.t('And {{numberOfItems}} others...', {
numberOfItems:
itemDisplayNames.length - renderLimit,
})}
</li>
);
}

return itemsToRender;
};

renderTooltip = names => (
<Popper
anchorEl={this.props.anchorEl}
open={this.props.open}
placement="bottom-start"
>
<Paper style={styles.tooltip}>
{
<ul style={styles.list}>
{names.map(name => (
<li key={`${this.props.dimensionId}-${name}`}>
{name}
</li>
))}
</ul>
}
{<ul style={styles.list}>{this.renderItems(names)}</ul>}
</Paper>
</Popper>
);
Expand Down

0 comments on commit 0590fdf

Please sign in to comment.