diff --git a/frontend/src/scenes/insights/summarizeInsight.ts b/frontend/src/scenes/insights/summarizeInsight.ts index a0f4aca3844868..4fcf69fb0924cd 100644 --- a/frontend/src/scenes/insights/summarizeInsight.ts +++ b/frontend/src/scenes/insights/summarizeInsight.ts @@ -1,3 +1,4 @@ +import { useValues } from 'kea' import { RETENTION_FIRST_TIME } from 'lib/constants' import { KEY_MAPPING } from 'lib/taxonomy' import { alphabet, capitalizeFirstLetter } from 'lib/utils' @@ -16,10 +17,12 @@ import { humanizePathsEventTypes, } from 'scenes/insights/utils' import { retentionOptions } from 'scenes/retention/constants' -import { apiValueToMathType, MathCategory, MathDefinition } from 'scenes/trends/mathsLogic' +import { apiValueToMathType, MathCategory, MathDefinition, mathsLogic } from 'scenes/trends/mathsLogic' import { mathsLogicType } from 'scenes/trends/mathsLogicType' +import { cohortsModel } from '~/models/cohortsModel' import { cohortsModelType } from '~/models/cohortsModelType' +import { groupsModel } from '~/models/groupsModel' import { groupsModelType } from '~/models/groupsModelType' import { extractExpressionComment } from '~/queries/nodes/DataTable/utils' import { BreakdownFilter, InsightQueryNode, Node } from '~/queries/schema' @@ -352,3 +355,12 @@ export function summarizeInsight( ? summarizeInsightFilters(filters, context) : '' } + +export function useSummarizeInsight(): (query: Node | undefined | null, filters?: Partial) => string { + const { aggregationLabel } = useValues(groupsModel) + const { cohortsById } = useValues(cohortsModel) + const { mathDefinitions } = useValues(mathsLogic) + + return (query, filters) => + summarizeInsight(query, filters || {}, { aggregationLabel, cohortsById, mathDefinitions }) +} diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx index e41e86158f8064..dd9e194634abc5 100644 --- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx +++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx @@ -14,6 +14,7 @@ import { urls } from 'scenes/urls' import { insightDataLogic } from 'scenes/insights/insightDataLogic' import { insightLogic } from 'scenes/insights/insightLogic' import { JSONContent } from '@tiptap/core' +import { useSummarizeInsight } from 'scenes/insights/summarizeInsight' const DEFAULT_QUERY: QuerySchema = { kind: NodeKind.DataTableNode, @@ -34,6 +35,7 @@ const Component = ({ const nodeLogic = useMountedLogic(notebookNodeLogic) const { expanded } = useValues(nodeLogic) const { setTitlePlaceholder } = useActions(nodeLogic) + const summarizeInsight = useSummarizeInsight() useEffect(() => { let title = 'Query' @@ -46,10 +48,14 @@ const Component = ({ } } if (query.kind === NodeKind.InsightVizNode) { - if (query.source.kind) { - title = query.source.kind.replace('Node', '').replace('Query', '') - } else { - title = 'Insight' + title = summarizeInsight(query) + + if (!title) { + if (query.source.kind) { + title = query.source.kind.replace('Node', '').replace('Query', '') + } else { + title = 'Insight' + } } } if (query.kind === NodeKind.SavedInsightNode) {