-
-
Notifications
You must be signed in to change notification settings - Fork 72
Issue 295 - Header tooltips #831
Conversation
: table.querySelector( | ||
`td[data-dash-column="${id}"][data-dash-row="${row}"]:not(.phantom-cell)` | ||
); | ||
|
There was a problem hiding this comment.
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
src/dash-table/dash/DataTable.js
Outdated
@@ -858,6 +860,7 @@ export const propTypes = { | |||
tooltip: PropTypes.objectOf( | |||
PropTypes.oneOfType([ | |||
PropTypes.exact({ | |||
use_with: PropTypes.oneOf(['data', 'header']), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure 71e7ce9
}) | ||
]) | ||
) | ||
), |
There was a problem hiding this comment.
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 | ||
); |
There was a problem hiding this comment.
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) => |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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] | ||
) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
src/dash-table/dash/DataTable.js
Outdated
* 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. |
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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'}]
}
There was a problem hiding this comment.
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))`
- updated prop description
const staticUseWith = | ||
staticTooltip && typeof staticTooltip !== 'string' | ||
? staticTooltip.use_with | ||
: TooltipUsage.Both; |
There was a problem hiding this comment.
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.
b60ec42
to
455db0a
Compare
There was a problem hiding this 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.
Closes #295
use_with
nested prop totooltip
to allow default column tooltips to be applied to either or bothdata
andheader
cells (both by default)tooltip_header
prop that behaves similarly totooltip_data
but affects headers instead