: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(metrics): keep chart height when an insight opens from a dashboard (#117513)
posthog[bot]1f4eee6043c3
diff --git a/frontend/src/queries/Query/Query.tsx b/frontend/src/queries/Query/Query.tsxindex c22fe318b240..73cc8cf9c1c5 100644--- a/frontend/src/queries/Query/Query.tsx+++ b/frontend/src/queries/Query/Query.tsx@@ -191,6 +191,7 @@ export function Query<Q extends Node>(props: QueryProps<Q>): JSX.Element | nullquery={query}cachedResults={props.cachedResults}context={queryContext}+ embedded={embedded}editMode={!!editMode && !readOnly}setQuery={setQuery as unknown as (query: MetricsQuery) => void}/>@@ -202,6 +203,7 @@ export function Query<Q extends Node>(props: QueryProps<Q>): JSX.Element | nullquery={query}cachedResults={props.cachedResults}context={queryContext}+ embedded={embedded}/>)} else if (isEndpointsUsageOverviewQuery(query)) {diff --git a/products/metrics/frontend/nodes/MetricsHistogramQueryNode.tsx b/products/metrics/frontend/nodes/MetricsHistogramQueryNode.tsxindex c32d60b37b96..371b64acd004 100644--- a/products/metrics/frontend/nodes/MetricsHistogramQueryNode.tsx+++ b/products/metrics/frontend/nodes/MetricsHistogramQueryNode.tsx@@ -22,6 +22,8 @@ export function MetricsHistogramQueryNode(props: {cachedResults?: AnyResponseTypecontext: QueryContextattachTo?: LogicWrapper | BuiltLogic+ /** Set by dashboard tiles and notebooks, which reduce the UI to the data. */+ embedded?: boolean}): JSX.Element | null {const { onData, loadPriority, dataNodeCollectionId } = props.context.insightProps ?? {}const [key] = useState(() => `MetricsHistogramQueryNode.${uniqueNode++}`)@@ -47,11 +49,12 @@ export function MetricsHistogramQueryNode(props: {return (// A dashboard tile sets the height, so a minimum would overflow a short tile. Elsewhere the- // parent can have no height, and the heatmap then needs the minimum to draw at all.+ // parent can have no height, and the heatmap then needs the minimum to draw at all. The insight+ // scene also gets a `dashboardId` when it opens from a tile, so `embedded` must also be set.<divclassName={cn('relative flex flex-col w-full h-full',- props.context.insightProps?.dashboardId == null && 'min-h-[200px]'+ !(props.embedded && props.context.insightProps?.dashboardId != null) && 'min-h-[200px]')}>{responseError ? (diff --git a/products/metrics/frontend/nodes/MetricsQueryNode.tsx b/products/metrics/frontend/nodes/MetricsQueryNode.tsxindex 96f1f28ceda1..80a93b2a5471 100644--- a/products/metrics/frontend/nodes/MetricsQueryNode.tsx+++ b/products/metrics/frontend/nodes/MetricsQueryNode.tsx@@ -28,6 +28,8 @@ interface MetricsQueryNodeProps {cachedResults?: AnyResponseTypecontext: QueryContextattachTo?: LogicWrapper | BuiltLogic+ /** Set by dashboard tiles and notebooks, which reduce the UI to the data. */+ embedded?: boolean/** With `setQuery`, shows the builder above the chart, as the insight editor does. */editMode?: booleansetQuery?: (query: MetricsQuery) => void@@ -138,11 +140,12 @@ function MetricsQueryResults({ dataKey: key, ...props }: MetricsQueryNodeProps &return (// A dashboard tile sets the height, so a minimum would overflow a short tile. Elsewhere the- // parent can have no height, and a chart then needs the minimum to draw at all.+ // parent can have no height, and a chart then needs the minimum to draw at all. The insight+ // scene also gets a `dashboardId` when it opens from a tile, so `embedded` must also be set.<divclassName={cn('relative flex flex-col w-full h-full',- props.context.insightProps?.dashboardId == null && 'min-h-[200px]'+ !(props.embedded && props.context.insightProps?.dashboardId != null) && 'min-h-[200px]')}>{responseError && !responseLoading ? (diff --git a/products/metrics/frontend/nodes/MetricsQueryNodes.test.tsx b/products/metrics/frontend/nodes/MetricsQueryNodes.test.tsxnew file mode 100644index 000000000000..fc331cc98429--- /dev/null+++ b/products/metrics/frontend/nodes/MetricsQueryNodes.test.tsx@@ -0,0 +1,47 @@+import '@testing-library/jest-dom'++import { cleanup, render } from '@testing-library/react'++import { useMocks } from '~/mocks/jest'+import { Query } from '~/queries/Query/Query'+import { MetricsHistogramQuery, MetricsQuery, NodeKind } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'+import { InsightShortId } from '~/types'++const METRICS_QUERY: MetricsQuery = {+ kind: NodeKind.MetricsQuery,+ clauses: [{ name: 'a', metricName: 'request_duration', aggregation: 'sum' }],+ dateRange: { date_from: '-1h' },+}++const HISTOGRAM_QUERY: MetricsHistogramQuery = {+ kind: NodeKind.MetricsHistogramQuery,+ metricName: 'request_duration',+ dateRange: { date_from: '-1h' },+}++describe('metrics query nodes', () => {+ beforeEach(() => {+ useMocks({ post: { '/api/environments/:team_id/query/:kind': () => [200, { results: [] }] } })+ initKeaTests()+ })++ afterEach(() => cleanup())++ it.each([+ ['time series in a dashboard tile', METRICS_QUERY, true, false],+ ['time series in the insight scene opened from a dashboard', METRICS_QUERY, false, true],+ ['heatmap in a dashboard tile', HISTOGRAM_QUERY, true, false],+ ['heatmap in the insight scene opened from a dashboard', HISTOGRAM_QUERY, false, true],+ ])('%s', (_name, query, embedded, expectMinHeight) => {+ const { container } = render(+ <Query+ query={query}+ readOnly+ embedded={embedded}+ context={{ insightProps: { dashboardItemId: 'abc123' as InsightShortId, dashboardId: 1 } }}+ />+ )+ expect(container.querySelector('.min-h-\\[200px\\]') !== null).toBe(expectMinHeight)+ })+})