: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(flags): add reload all to usage tab charts (#106928)
posthog[bot]55c80fc075e2
diff --git a/frontend/src/scenes/feature-flags/FeatureFlagUsageMetrics.tsx b/frontend/src/scenes/feature-flags/FeatureFlagUsageMetrics.tsxindex 6f95a9a6a388..1db3db572cb0 100644--- a/frontend/src/scenes/feature-flags/FeatureFlagUsageMetrics.tsx+++ b/frontend/src/scenes/feature-flags/FeatureFlagUsageMetrics.tsx@@ -1,42 +1,63 @@-import { useActions, useValues } from 'kea'+import { BindLogic, useActions, useValues } from 'kea'import { QueryCard } from 'lib/components/Cards/InsightCard/QueryCard'import { DateFilter } from 'lib/components/DateFilter/DateFilter'+import { dataNodeCollectionLogic } from '~/queries/nodes/DataNode/dataNodeCollectionLogic'+import { ReloadAll } from '~/queries/nodes/DataNode/Reload'+import { featureFlagUsageLogic } from './featureFlagUsageLogic'import { FLAG_EVALUATIONS_RETENTION_DAYS } from './flagEvaluationsTable'+const FEATURE_FLAG_USAGE_DATA_COLLECTION_NODE_ID = 'feature-flag-usage'+export function FeatureFlagUsageMetrics({ id }: { id: number }): JSX.Element {const logic = featureFlagUsageLogic({ id })const { dateRange, dateOptions, readsFlagEvaluationsTable, usageCharts } = useValues(logic)const { setDates } = useActions(logic)return (- <div className="flex flex-col gap-4" data-attr="feature-flag-usage-inline">- <div className="flex flex-wrap items-center gap-2">- <DateFilter- dateFrom={dateRange.date_from ?? null}- dateTo={dateRange.date_to ?? null}- dateOptions={dateOptions}- onChange={(fromDate, toDate) => setDates(fromDate, toDate)}- />- {readsFlagEvaluationsTable && (- <span className="text-secondary text-xs">- Flag evaluations are kept for {FLAG_EVALUATIONS_RETENTION_DAYS} days.- </span>- )}- </div>- <div className="grid grid-cols-1 gap-4 xl:grid-cols-2">- {usageCharts.map((chart) => (- <QueryCard- key={chart.key}- uniqueKey={`feature-flag-usage-${id}-${chart.key}`}- title={chart.title}- description={chart.description}- query={chart.query}+ <BindLogic logic={dataNodeCollectionLogic} props={{ key: FEATURE_FLAG_USAGE_DATA_COLLECTION_NODE_ID }}>+ <div className="flex flex-col gap-4" data-attr="feature-flag-usage-inline">+ <div className="flex flex-wrap items-center gap-2">+ <DateFilter+ dateFrom={dateRange.date_from ?? null}+ dateTo={dateRange.date_to ?? null}+ dateOptions={dateOptions}+ onChange={(fromDate, toDate) => setDates(fromDate, toDate)}/>- ))}+ <ReloadAll />+ {readsFlagEvaluationsTable && (+ <span className="text-secondary text-xs">+ Flag evaluations are kept for {FLAG_EVALUATIONS_RETENTION_DAYS} days.+ </span>+ )}+ </div>+ <div className="grid grid-cols-1 gap-4 xl:grid-cols-2">+ {usageCharts.map((chart) => {+ // The events and flag_evaluations versions of a chart share a chart key, so+ // the query kind keeps their insight and data node logics apart.+ const chartKey = `feature-flag-usage-${id}-${chart.query.kind}-${chart.key}`+ return (+ <QueryCard+ key={chart.key}+ uniqueKey={chartKey}+ title={chart.title}+ description={chart.description}+ query={chart.query}+ context={{+ insightProps: {+ dashboardItemId: `new-AdHoc.${chartKey}`,+ dataNodeCollectionId: FEATURE_FLAG_USAGE_DATA_COLLECTION_NODE_ID,+ query: chart.query,+ },+ ...chart.emptyState,+ }}+ />+ )+ })}+ </div></div>- </div>+ </BindLogic>)}diff --git a/frontend/src/scenes/feature-flags/featureFlagUsageQueries.ts b/frontend/src/scenes/feature-flags/featureFlagUsageQueries.tsindex a7afdee939bf..6d84c9dfe13f 100644--- a/frontend/src/scenes/feature-flags/featureFlagUsageQueries.ts+++ b/frontend/src/scenes/feature-flags/featureFlagUsageQueries.ts@@ -21,6 +21,7 @@ import {ProductKey,TrendsQuery,} from '~/queries/schema/schema-general'+import { QueryContext } from '~/queries/types'import { escapeHogQLString, setLatestVersionsOnQuery } from '~/queries/utils'import {AnyPropertyFilter,@@ -57,6 +58,14 @@ export interface FlagUsageChart<Q extends FlagUsageQuery = FlagUsageQuery> {title: stringdescription: stringquery: Q+ emptyState?: Pick<QueryContext, 'emptyStateHeading' | 'emptyStateDetail'>+}++// A cached empty daily result can hide new calls for hours, so point at Reload and the log, not the query.+const FLAG_CALLS_EMPTY_STATE: FlagUsageChart['emptyState'] = {+ emptyStateHeading: 'No calls to this flag in this date range',+ emptyStateDetail:+ 'New calls can take a few minutes to show in the charts. Click Reload to check again. The log below lists calls as they arrive.',}function flagCalledProperties({ flagKey, aggregationGroupTypeIndex }: FlagUsageQueryOptions): AnyPropertyFilter[] {@@ -114,6 +123,7 @@ export function buildFlagCalledTotalVolumeChart(},ChartDisplayType.ActionsLineGraph),+ emptyState: FLAG_CALLS_EMPTY_STATE,}}@@ -147,6 +157,7 @@ export function buildFlagCalledUniqueCallersChart(},ChartDisplayType.ActionsTable),+ emptyState: FLAG_CALLS_EMPTY_STATE,}}diff --git a/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx b/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsxindex 00224918780d..881028946629 100644--- a/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx+++ b/products/product_analytics/frontend/insights/shared/InsightsTable/InsightsTable.tsx@@ -2,7 +2,7 @@ import './InsightsTable.scss'import { useActions, useValues } from 'kea'import { compare as compareFn } from 'natural-orderby'-import { useCallback, useMemo, useState } from 'react'+import { ReactNode, useCallback, useMemo, useState } from 'react'import { LemonButton } from 'lib/lemon-ui/LemonButton'import { LemonTable, LemonTableColumn } from 'lib/lemon-ui/LemonTable'@@ -68,6 +68,8 @@ export interface InsightsTableProps {isMainInsightView?: boolean/** Whether the insight is in edit mode. */editMode?: boolean+ /** @default 'No insight results' */+ emptyState?: ReactNode}export function InsightsTable({@@ -79,6 +81,7 @@ export function InsightsTable({canCheckUncheckSeries = true,isMainInsightView = false,editMode,+ emptyState = 'No insight results',}: InsightsTableProps): JSX.Element {const { insightProps, isInDashboardContext, insight } = useValues(insightLogic)const {@@ -504,7 +507,7 @@ export function InsightsTable({rowKey="id"loading={insightDataLoading}disableTableWhileLoading={false}- emptyState="No insight results"+ emptyState={emptyState}data-attr="insights-table-graph"useURLForSorting={!editMode}rowRibbonColor={diff --git a/products/product_analytics/frontend/insights/trends/Trends.test.tsx b/products/product_analytics/frontend/insights/trends/Trends.test.tsxnew file mode 100644index 000000000000..f330bf47b336--- /dev/null+++ b/products/product_analytics/frontend/insights/trends/Trends.test.tsx@@ -0,0 +1,38 @@+import '@testing-library/jest-dom'++import { cleanup, configure, screen } from '@testing-library/react'++import { InsightVizNode, NodeKind, TrendsQueryResponse } from '~/queries/schema/schema-general'+import { QueryContext } from '~/queries/types'+import { buildTrendsQuery, renderInsight } from '~/test/insight-testing'+import { ChartDisplayType } from '~/types'++// The full InsightViz tree is heavy to mount under jsdom, so the default 1s findBy timeout flakes on CI.+configure({ asyncUtilTimeout: 5000 })+jest.setTimeout(15000)++afterEach(() => {+ cleanup()+})++describe('TrendInsight', () => {+ it.each<[string, QueryContext<InsightVizNode> | undefined, string]>([+ ['the context copy', { emptyStateHeading: 'No calls to this flag' }, 'No calls to this flag'],+ ['the default copy', undefined, 'No insight results'],+ ])('an empty table shows %s', async (_name, context, expectedText) => {+ renderInsight({+ query: buildTrendsQuery({ trendsFilter: { display: ChartDisplayType.ActionsTable } }),+ context,+ mocks: {+ additionalMockResponses: [+ {+ match: (query) => query.kind === NodeKind.TrendsQuery,+ response: { results: [] } as unknown as TrendsQueryResponse,+ },+ ],+ },+ })++ expect(await screen.findByText(expectedText)).toBeInTheDocument()+ })+})diff --git a/products/product_analytics/frontend/insights/trends/Trends.tsx b/products/product_analytics/frontend/insights/trends/Trends.tsxindex 9061fec047b2..0e1bdc6c68e0 100644--- a/products/product_analytics/frontend/insights/trends/Trends.tsx+++ b/products/product_analytics/frontend/insights/trends/Trends.tsx@@ -6,6 +6,7 @@ import { LemonButton } from '@posthog/lemon-ui'import { PIE_DISPLAY_TYPES } from 'lib/constants'import { WrappingLoadingSkeleton } from 'lib/ui/WrappingLoadingSkeleton/WrappingLoadingSkeleton'import { lazyWithRetry } from 'lib/utils/retryImport'+import { InsightEmptyState } from 'scenes/insights/EmptyStates'import { insightLogic } from 'scenes/insights/insightLogic'import { InsightVizNode } from '~/queries/schema/schema-general'@@ -60,6 +61,17 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }inSharedMode,}+ const tableEmptyState =+ context?.emptyStateHeading !== undefined || context?.emptyStateDetail !== undefined ? (+ <InsightEmptyState+ heading={context.emptyStateHeading}+ detail={context.emptyStateDetail}+ icon={context.emptyStateIcon}+ sampleDataVariant="table"+ insightProps={insightProps}+ />+ ) : undefined+const renderViz = (): JSX.Element => {if (isLifecycle) {return <TrendsLifecycleChart context={context} inSharedMode={inSharedMode} />@@ -84,6 +96,7 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }canEditSeriesNameInline={editMode}editMode={editMode}isMainInsightView={true}+ emptyState={tableEmptyState}/>)}