Skip to content

Commit

Permalink
feat: Summarise insights in Notebooks (#19064)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored and Twixes committed Dec 6, 2023
1 parent 3d0e217 commit 2e919d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
14 changes: 13 additions & 1 deletion frontend/src/scenes/insights/summarizeInsight.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -352,3 +355,12 @@ export function summarizeInsight(
? summarizeInsightFilters(filters, context)
: ''
}

export function useSummarizeInsight(): (query: Node | undefined | null, filters?: Partial<FilterType>) => string {
const { aggregationLabel } = useValues(groupsModel)
const { cohortsById } = useValues(cohortsModel)
const { mathDefinitions } = useValues(mathsLogic)

return (query, filters) =>
summarizeInsight(query, filters || {}, { aggregationLabel, cohortsById, mathDefinitions })
}
14 changes: 10 additions & 4 deletions frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
Expand All @@ -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) {
Expand Down

0 comments on commit 2e919d6

Please sign in to comment.