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

feat: truncate long values in table viz, a per-column setting #19383

Merged
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type SharedColumnConfigProp =
| 'd3SmallNumberFormat'
| 'd3TimeFormat'
| 'horizontalAlign'
| 'truncateLongCells'
| 'showCellBars';

const emitTarget: ControlFormItemSpec<'Input'> = {
Expand Down Expand Up @@ -142,6 +143,14 @@ const colorPositiveNegative: ControlFormItemSpec<'Checkbox'> = {
debounceDelay: 200,
};

const truncateLongCells: ControlFormItemSpec<'Checkbox'> = {
controlType: 'Checkbox',
label: t('Truncate Cells'),
description: t('Truncate long cells to the "min width" set above'),
defaultValue: false,
debounceDelay: 400,
};

/**
* All configurable column formatting properties.
*/
Expand All @@ -159,6 +168,7 @@ export const SHARED_COLUMN_CONFIG_PROPS = {
d3TimeFormat,
fractionDigits,
columnWidth,
truncateLongCells,
horizontalAlign,
showCellBars,
alignPositiveNegative,
Expand All @@ -175,6 +185,7 @@ export const DEFAULT_CONFIG_FORM_LAYOUT: ColumnConfigFormLayout = {
'columnWidth',
{ name: 'horizontalAlign', override: { defaultValue: 'left' } },
],
['truncateLongCells'],
],
[GenericDataType.NUMERIC]: [
[
Expand Down
11 changes: 11 additions & 0 deletions superset-frontend/plugins/plugin-chart-table/src/Styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ export default styled.div`
float: right;
}

.dt-truncate-cell {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.dt-truncate-cell:hover {
overflow: visible;
white-space: normal;
height: auto;
}

.dt-pagination {
text-align: right;
/* use padding instead of margin so clientHeight can capture it */
Expand Down
29 changes: 28 additions & 1 deletion superset-frontend/plugins/plugin-chart-table/src/TableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ export default function TableChart<D extends DataRecord = DataRecord>(
? defaultColorPN
: config.colorPositiveNegative;

const { truncateLongCells } = config;

const hasColumnColorFormatters =
isNumeric &&
Array.isArray(columnColorFormatters) &&
Expand Down Expand Up @@ -410,12 +412,37 @@ export default function TableChart<D extends DataRecord = DataRecord>(
].join(' '),
};
if (html) {
if (truncateLongCells) {
// eslint-disable-next-line react/no-danger
return (
<StyledCell {...cellProps}>
<div
className="dt-truncate-cell"
style={columnWidth ? { width: columnWidth } : undefined}
dangerouslySetInnerHTML={html}
/>
</StyledCell>
);
}
// eslint-disable-next-line react/no-danger
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 <StyledCell {...cellProps}>{text}</StyledCell>;
return (
<StyledCell {...cellProps}>
{truncateLongCells ? (
<div
className="dt-truncate-cell"
style={columnWidth ? { width: columnWidth } : undefined}
>
{text}
</div>
) : (
text
)}
</StyledCell>
);
},
Header: ({ column: col, onClick, style, onDragStart, onDrop }) => (
<th
Expand Down