: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
feat(insight-card): link cards to the insight's own project (#110105)
Yasenccfbd6e60b17
diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsxindex ff6b7db11cc6..16e1da66c851 100644--- a/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx+++ b/frontend/src/lib/components/Cards/InsightCard/InsightCard.tsx@@ -223,6 +223,10 @@ export interface InsightCardProps extends Resizeable {onEnterEditModeFromEdge?: (event: React.MouseEvent<HTMLDivElement>, edge: EditModeEdge) => void/** Called when the user mousedowns on the card (drag handle) in view mode to enter edit mode. */onDragHandleMouseDown?: React.MouseEventHandler<HTMLDivElement>+ /** Project the insight belongs to, when that is not the current project. The card's links then open it there. */+ projectId?: number+ /** Shown above the title, for a card that has to name where its insight comes from. */+ contextHeading?: JSX.Element | null}function InsightCardInternal(@@ -262,6 +266,8 @@ function InsightCardInternal(filtersOverride,variablesOverride,children,+ projectId,+ contextHeading,breakdownColorOverride: _breakdownColorOverride,dataColorThemeId: _dataColorThemeId,surveyOpportunity,@@ -465,6 +471,8 @@ function InsightCardInternal(<InsightMetatile={tile}insight={insight}+ projectId={projectId}+ contextHeading={contextHeading}ribbonColor={ribbonColor}dashboardId={dashboardId}canEditDashboard={canEditDashboard}diff --git a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsxindex 1039c0518590..862024edd7c5 100644--- a/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx+++ b/frontend/src/lib/components/Cards/InsightCard/InsightMeta.tsx@@ -120,6 +120,8 @@ interface InsightMetaProps extends Pick<| 'placement'| 'surveyOpportunity'| 'showCreateAnomalyAlertButton'+ | 'projectId'+ | 'contextHeading'> {/** Called when the user mousedowns on the card meta (drag handle) in view mode to enter edit mode. */onDragHandleMouseDown?: React.MouseEventHandler<HTMLDivElement>@@ -167,6 +169,8 @@ export function InsightMeta({onCreateAlert,onEditAlert,onCreateAnomalyAlert,+ projectId,+ contextHeading,}: InsightMetaProps): JSX.Element {const { short_id, name, next_allowed_client_refresh: nextAllowedClientRefresh } = insightconst tileFiltersOverride = tile?.filters_overrides@@ -450,15 +454,16 @@ export function InsightMeta({: undefined// Carries the dashboard's filters and variables, so the link opens exactly what the tile shows- const insightViewUrl = urls.insightView(- short_id,- dashboardId,- variablesOverride,- filtersOverride,- tileFiltersOverride+ // A card showing another project's insight must link into that project, not the current one.+ const inInsightProject = (path: string): string => (projectId ? urls.project(projectId, path) : path)+ const insightViewUrl = inInsightProject(+ urls.insightView(short_id, dashboardId, variablesOverride, filtersOverride, tileFiltersOverride))const copyInsightLink = (): void => {- void copyToClipboard(urls.absolute(urls.currentProject(insightViewUrl)), 'insight link')+ void copyToClipboard(+ urls.absolute(projectId ? insightViewUrl : urls.currentProject(insightViewUrl)),+ 'insight link'+ )}return (@@ -472,7 +477,16 @@ export function InsightMeta({areDetailsShown={areDetailsShown}detailsTooltip="Show insight details, such as creator, last edit, and applied filters."onMouseDown={onDragHandleMouseDown}- topHeading={topHeadingEl}+ topHeading={+ contextHeading ? (+ <span className="flex items-center gap-2 min-w-0">+ {contextHeading}+ {topHeadingEl}+ </span>+ ) : (+ topHeadingEl+ )+ }popoverTopHeading={popoverTopHeadingEl}content={<InsightMetaContent@@ -531,22 +545,24 @@ export function InsightMeta({{canEditInsight && (<><LemonButton- to={+ to={inInsightProject(isDataVisualizationNode(insight.query)? urls.sqlEditor({insightShortId: short_id,dashboard: dashboardId ?? undefined,}): urls.insightEdit(short_id, dashboardId)- }+ )}fullWidth{...getOverrideWarningPropsForButton(filtersOverride, variablesOverride)}>Edit</LemonButton>- <LemonButton onClick={rename} fullWidth>- Rename- </LemonButton>+ {rename && (+ <LemonButton onClick={rename} fullWidth>+ Rename+ </LemonButton>+ )}{tile && (<LemonButton onClick={setOverride} fullWidth>Set override@@ -554,17 +570,19 @@ export function InsightMeta({)}</>)}- <LemonButton- onClick={duplicate}- fullWidth- data-attr={- dashboardId- ? 'duplicate-insight-from-dashboard'- : 'duplicate-insight-from-card-list-view'- }- >- Duplicate- </LemonButton>+ {duplicate && (+ <LemonButton+ onClick={duplicate}+ fullWidth+ data-attr={+ dashboardId+ ? 'duplicate-insight-from-dashboard'+ : 'duplicate-insight-from-card-list-view'+ }+ >+ Duplicate+ </LemonButton>+ )}{showDashboardAlertsMenuItem && insight.id ? (<LemonButtononClick={() => {