Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(insights): show harness icons in sql result tables (#130779)

Paul D'Ambra688ea3ec12b2
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Table.render.test.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Table.render.test.tsx
index 748d528d247d..9b00490a1a8f 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Table.render.test.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Table.render.test.tsx
@@ -10,6 +10,7 @@ import * as hog from 'lib/hog'
import { themeLogic } from 'lib/logic/themeLogic'
import { userLogic } from 'scenes/userLogic'
+import { useMocks } from '~/mocks/jest'
import {
ConditionalFormattingRule,
HogQLQueryResponse,
@@ -76,6 +77,52 @@ describe('SQL table rendering', () => {
beforeEach(() => initKeaTests())
afterEach(cleanup)
+ it.each([false, true])('renders harness names and custom icons, transpose=%s', async (transpose) => {
+ const icon = 'data:image/png;base64,iVBORw0KGgo='
+ useMocks({
+ get: {
+ '/api/projects/:team_id/mcp_analytics/custom_harnesses/': [
+ { id: 'example', name: 'Example harness', match_pattern: 'example', icon },
+ ],
+ },
+ })
+ const result: HogQLQueryResponse = {
+ columns: ['client', 'calls'],
+ types: [
+ ['client', 'String'],
+ ['calls', 'UInt64'],
+ ],
+ column_formats: ['mcp_harness', null],
+ results: [
+ ['Example harness', 7],
+ ['Claude Code', 3],
+ ],
+ }
+ const node: VisualizationNode = {
+ ...query,
+ source: {
+ kind: NodeKind.HogQLQuery,
+ query: 'SELECT properties.$virt_mcp_harness AS client, count() AS calls FROM events GROUP BY client',
+ },
+ tableSettings: { transpose },
+ }
+ const { props, sourceProps } = mountResult(node, result)
+ render(
+ <BindLogic logic={dataNodeLogic} props={sourceProps}>
+ <BindLogic logic={dataVisualizationLogic} props={props}>
+ <Table query={node} uniqueKey={props.key} context={{}} cachedResults={result} />
+ </BindLogic>
+ </BindLogic>
+ )
+ await waitFor(() => {
+ const label = screen.getByText('Example harness').closest('[data-attr="hogqlx-brand-mark-label"]')
+ expect(label).toBeInTheDocument()
+ expect(label?.querySelector('[style]')).toHaveStyle({ '--harness-icon': `url("${icon}")` })
+ })
+ expect(screen.getByText('Claude Code').closest('[data-attr="hogqlx-brand-mark-label"]')).toBeInTheDocument()
+ expect(screen.getByText('7').closest('[data-attr="hogqlx-brand-mark-label"]')).toBeNull()
+ })
+
it.each([false, true])('inspects the original row after sorting or transposing, transpose=%s', (transpose) => {
const node = { ...query, tableSettings: { ...query.tableSettings, transpose } }
const { props, sourceProps } = mountResult(node, response)
diff --git a/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx b/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx
index a0f86cda0687..358a4d99de3c 100644
--- a/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx
+++ b/frontend/src/queries/nodes/DataVisualization/Components/Table.tsx
@@ -13,7 +13,7 @@ import { InsightEmptyState, InsightErrorState } from 'scenes/insights/EmptyState
import { themeLogic } from '~/layout/navigation-3000/themeLogic'
import { HOGQLX_TAGS_NO_ATTRIBUTES, parseHogQLX } from '~/queries/nodes/HogQLX/render'
-import { VisualizationNode, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'
+import { AnyResponseType, VisualizationNode, HogQLQueryResponse, NodeKind } from '~/queries/schema/schema-general'
import { QueryContext } from '~/queries/types'
import { LoadNext } from '../../DataNode/LoadNext'
@@ -67,6 +67,12 @@ function isDateColumn(type: ColumnScalar | undefined): boolean {
return type === 'DATE' || type === 'DATETIME'
}
+function getColumnFormat(response: AnyResponseType | null, sourceColumnName: string): string | null | undefined {
+ return response && 'column_formats' in response
+ ? response.column_formats?.[response.columns.indexOf(sourceColumnName)]
+ : undefined
+}
+
// Numbers sort numerically, dates chronologically by epoch, everything else by a
// numeric-aware string compare, and empty cells sort to the bottom of an ascending sort.
export function compareTableCells(a: TableDataCell<any> | undefined, b: TableDataCell<any> | undefined): number {
@@ -478,10 +484,13 @@ export const Table = (props: TableProps): JSX.Element => {
)
}
+ const sourceColumnName = cell.sourceColumnName ?? column.name
+ const columnFormat = getColumnFormat(response, sourceColumnName)
+
return (
<div className="truncate" title={getCellTitle(cell)}>
{renderColumn(
- cell.sourceColumnName ?? column.name,
+ sourceColumnName,
cell.formattedValue,
tableResults[isTransposed ? index - 1 : data.rowIndex],
recordIndex,
@@ -489,7 +498,10 @@ export const Table = (props: TableProps): JSX.Element => {
{
kind: NodeKind.DataTableNode,
source: props.query.source,
- }
+ },
+ undefined,
+ undefined,
+ columnFormat
)}
</div>
)