Skip to content

Commit

Permalink
fix(inventoryCardHelpers): sw-1889 table tooltips (#1224)
Browse files Browse the repository at this point in the history
* inventoryCardHelpers, allow callbacks, info tooltips
  • Loading branch information
cdcabrera committed Nov 7, 2023
1 parent a7292d6 commit def1a6e
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/inventoryCard/inventoryCardHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ const parseInventoryResponse = ({
dataSetRows.push({ cells: dataSetRow, row: rowData, expandedContent });
});

filters.forEach(({ metric, header, ...rest }) => {
filters.forEach(({ metric, header, info, ...rest }) => {
const updatedHeader = header({ columnData: columnData[metric] }, { ...session }, { ...meta });
const updatedInfo = (info && { ...info }) || undefined;
const updatedRest = { ...rest };

if (updatedInfo?.tooltip && typeof updatedInfo.tooltip === 'function') {
updatedInfo.tooltip = updatedInfo.tooltip({ columnData: columnData[metric] }, { ...session }, { ...meta });
}

if (updatedRest.isSort === true && sortDirection && sortColumn === metric) {
updatedRest.isSortActive = true;
updatedRest.sortDirection = sortDirection;
Expand All @@ -149,7 +154,7 @@ const parseInventoryResponse = ({
updatedRest.modifier = tableHelpers.WrapModifierVariant.wrap;
}

dataSetColumnHeaders.push({ metric, ...updatedRest, content: updatedHeader });
dataSetColumnHeaders.push({ metric, ...updatedRest, content: updatedHeader, info: updatedInfo });
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports[`InventoryCardInstancesContext should handle a store response using sele
{
"cell": [Function],
"content": "t([curiosity-inventory.header_display_name,curiosity-inventory.guestsHeader_display_name], {"context":"lorem"})",
"info": undefined,
"label": [Function],
"metric": "display_name",
"width": undefined,
Expand Down
Loading

0 comments on commit def1a6e

Please sign in to comment.