Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Issue 295 - Header tooltips #831

Merged
merged 10 commits into from
Oct 8, 2020
Merged

Issue 295 - Header tooltips #831

merged 10 commits into from
Oct 8, 2020

Conversation

Marc-Andre-Rivet
Copy link
Contributor

Closes #295

  • Adds use_with nested prop to tooltip to allow default column tooltips to be applied to either or both data and header cells (both by default)
  • Adds new tooltip_header prop that behaves similarly to tooltip_data but affects headers instead

: table.querySelector(
`td[data-dash-column="${id}"][data-dash-row="${row}"]:not(.phantom-cell)`
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still using (row, id) but now also deciding what element to select based on header

@@ -858,6 +860,7 @@ export const propTypes = {
tooltip: PropTypes.objectOf(
PropTypes.oneOfType([
PropTypes.exact({
use_with: PropTypes.oneOf(['data', 'header']),
Copy link
Contributor Author

@Marc-Andre-Rivet Marc-Andre-Rivet Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward compatibility addition of use_with to the tooltip prop -- app creator can use it to define whether the default tooltip will be visible on data, headers, or both. This is for consistency and ease of use. Otherwise the only other option available would be the new tooltip_header which require specifying the tooltip for each individual column/row combination.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an explicit 'both' to go along with the implicit one, and just label that as the default? Even though it won't be set as such since it's nested, I think people would in some cases appreciate being able to set this explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure 71e7ce9

})
])
)
),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header equivalent of tooltip_data

this.propsFn,
rowIndex,
columnIndex
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New event handlers for header cells, equivalent but slightly different from the same handlers for the data cells

labelsAndIndices: R.KeyValuePair<any[], number[]>[],
mergeHeaders: boolean
): JSX.Element[][] =>
labelsAndIndices.map(([labels, indices], rowIndex) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean up. TypeScript + R.map + R.addIndex don't make a great mix, requiring explicit typing of everything in most cases. The native implementation is easier to read and is also typed.

}

app = dash.Dash(__name__)
app.layout = DataTable(**props)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test combination of static tooltips with/without usage and data/header tooltips to make sure usage is applied and overrides override.

)
)[row]
)
Copy link
Contributor Author

@Marc-Andre-Rivet Marc-Andre-Rivet Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned this up a bit. Thankfully this wasn't used anywhere so no test needs to be modified.

cell55.move_to()

target.cell(0, "3").move_to()
time.sleep(1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the missing case, ensure the tooltip has had time to appear, just in case.

@Marc-Andre-Rivet Marc-Andre-Rivet marked this pull request as ready for review September 24, 2020 15:12
* for different header columns and cells.
* The `property` name refers to the column ID. Each property
* contains a list of tooltips mapped to the table's `header`
* row index.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Each property contains a list of tooltips" implies to me that we're expecting a structure:

{'col-id': ['first row', 'second row']}

rather than what I think we're actually expecting:

[{'col-id': 'first row'}, {'col-id': 'second row'}]

But the former actually feels a bit more intuitive and compact to me, even if it doesn't match tooltip_data as closely. It simplifies some simple cases: single row headers, or the same tooltip for every row, you would just provide a string or object for the value, rather than an array of strings or objects. What do you think?

Also minor point: I'd just say "The property name" rather than "The property name" - as is I was looking for something called "property" below 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. The current description is inaccurate and misleading.

For consistency, I don't foresee any major problem supporting both syntax (array of objects and object of arrays) for both props.

Copy link
Contributor Author

@Marc-Andre-Rivet Marc-Andre-Rivet Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm if either syntax can cover every use case, I don't think it's a good idea to support both, that'll just confuse people.

Seems to me the *_data props should all match data itself, ie arrayOf(objectOf(...)).

For tooltip_header, I mostly wanted to see if we could simplify the cases of single-row headers and multi-row headers with the same tooltip for all rows, and to do that I was thinking (1) tooltip_header would be an objectOf the row IDs, and (2) you could choose not to use an array inside that. So if all you want is simple text that applies the same to every row (of if there's only one row) you could use:

{'col1-id': 'all rows for col1', 'col2-id': 'all rows for col2'}

or eg markdown for all rows:

{'col1-id': {'type': 'markdown', 'value': '#Wow\nwhat great data!'}}

But of course you'd still need the array form when you have multiple rows and you want them to behave differently:

{
  'col1-id': ['first row', 'second row'],
  'col2-id': [{'type': 'markdown', 'value': '#Big'}, {'type': 'markdown', 'value': '####small'}]
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.. can update to have:

tooltip: objectOf(string | tooltip) w/ new use_with for (both,data,header)
tooltip_conditional: unchanged arrayOf(conditionalTooltip)
tooltip_data: unchanged arrayOf(objectOf(string | tooltip))
tooltip_header: new objectOf(string | tooltip | arrayOf(null|string|tooltip))`

const staticUseWith =
staticTooltip && typeof staticTooltip !== 'string'
? staticTooltip.use_with
: TooltipUsage.Both;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply tooltips to both data and headers by default. This is a change from the pre-existing behavior that would have shown the tooltip only on the data cells but it seems consistent in spirit with the new functionality.

R.findLast
Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 Beautiful. Lovely tests, very easy to read and cover the cases well.

@Marc-Andre-Rivet Marc-Andre-Rivet merged commit 0fd6f61 into dev Oct 8, 2020
@Marc-Andre-Rivet Marc-Andre-Rivet deleted the 295-header-tooltip branch October 8, 2020 20:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Header tooltips
2 participants