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(chart-controls): Show detailed data type tooltip when hovering type icon #23970

Merged
merged 10 commits into from
May 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Tooltip } from './Tooltip';
import { ColumnTypeLabel } from './ColumnTypeLabel/ColumnTypeLabel';
import CertifiedIconWithTooltip from './CertifiedIconWithTooltip';
import { ColumnMeta } from '../types';
import { getColumnLabelText, getColumnTooltipNode } from './labelUtils';
import { getColumnLabelText, getColumnTooltipNode, getColumnTypeTooltipNode } from './labelUtils';
import { SQLPopover } from './SQLPopover';

export type ColumnOptionProps = {
Expand All @@ -48,14 +48,20 @@ export function ColumnOption({
const hasExpression = expression && expression !== column_name;
const type = hasExpression ? 'expression' : type_generic;
const [tooltipText, setTooltipText] = useState<ReactNode>(column.column_name);
const [columnTypeTooltipText, setcolumnTypeTooltipText] = useState<ReactNode>(column.type);

useLayoutEffect(() => {
setTooltipText(getColumnTooltipNode(column, labelRef));
setcolumnTypeTooltipText(getColumnTypeTooltipNode(column));
}, [labelRef, column]);

return (
<StyleOverrides>
{showType && type !== undefined && <ColumnTypeLabel type={type} />}
<Tooltip id="metric-type-tooltip" title={columnTypeTooltipText} placement="bottomRight">
<span>
{showType && type !== undefined && <ColumnTypeLabel type={type} />}
</span>
</Tooltip>
<Tooltip id="metric-name-tooltip" title={tooltipText}>
<span
className="option-label column-option-label"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ export const isLabelTruncated = (labelRef?: React.RefObject<any>): boolean =>
export const getColumnLabelText = (column: ColumnMeta): string =>
column.verbose_name || column.column_name;

export const getColumnTypeTooltipNode = (
column: ColumnMeta,
labelRef?: React.RefObject<any>,
): ReactNode => {
if (!column.type) {
return null;
}

return (
<TooltipSection label={t('Column datatype')} text={column.type.toLowerCase()} />
);
};

export const getColumnTooltipNode = (
column: ColumnMeta,
labelRef?: React.RefObject<any>,
Expand Down