Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chart & table): make to allow highlight in case of numeric column #19938

Merged
merged 3 commits into from
May 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
ensureIsArray,
GenericDataType,
getTimeFormatterForGranularity,
styled,
t,
tn,
} from '@superset-ui/core';
Expand Down Expand Up @@ -317,7 +318,6 @@ export default function TableChart<D extends DataRecord = DataRecord>(
const getColumnConfigs = useCallback(
(column: DataColumnMeta, i: number): ColumnWithLooseAccessor<D> => {
const { key, label, isNumeric, dataType, isMetric, config = {} } = column;
const isFilter = !isNumeric && emitFilter;
const columnWidth = Number.isNaN(Number(config.columnWidth))
? config.columnWidth
: Number(config.columnWidth);
Expand Down Expand Up @@ -348,7 +348,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
getValueRange(key, alignPositiveNegative);

let className = '';
if (isFilter) {
if (emitFilter) {
className += ' dt-is-filter';
}

Expand Down Expand Up @@ -376,6 +376,19 @@ export default function TableChart<D extends DataRecord = DataRecord>(
});
}

const StyledCell = styled.td`
text-align: ${sharedStyle.textAlign};
background: ${backgroundColor ||
(valueRange
? cellBar({
value: value as number,
valueRange,
alignPositiveNegative,
colorPositiveNegative,
})
: undefined)};
`;

const cellProps = {
// show raw number in title in case of numeric values
title: typeof value === 'number' ? String(value) : undefined,
Expand All @@ -388,27 +401,14 @@ export default function TableChart<D extends DataRecord = DataRecord>(
value == null ? 'dt-is-null' : '',
isActiveFilterValue(key, value) ? ' dt-is-active-filter' : '',
].join(' '),
style: {
...sharedStyle,
background:
backgroundColor ||
(valueRange
? cellBar({
value: value as number,
valueRange,
alignPositiveNegative,
colorPositiveNegative,
})
: undefined),
},
};
if (html) {
// eslint-disable-next-line react/no-danger
return <td {...cellProps} dangerouslySetInnerHTML={html} />;
return <StyledCell {...cellProps} dangerouslySetInnerHTML={html} />;
}
// If cellProps renderes textContent already, then we don't have to
// render `Cell`. This saves some time for large tables.
return <td {...cellProps}>{text}</td>;
return <StyledCell {...cellProps}>{text}</StyledCell>;
},
Header: ({ column: col, onClick, style }) => (
<th
Expand Down