Skip to content

Commit

Permalink
fix(notebooks): bind logic for hogql insights (#25623)
Browse files Browse the repository at this point in the history
  • Loading branch information
skoob13 authored Oct 17, 2024
1 parent b3b38cd commit cb1b316
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
18 changes: 18 additions & 0 deletions cypress/e2e/notebooks-insights.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { insight, savedInsights } from '../productAnalytics'

describe('Notebooks', () => {
beforeEach(() => {
cy.clickNavMenu('notebooks')
cy.location('pathname').should('include', '/notebooks')
})
;['SQL', 'TRENDS', 'FUNNELS', 'RETENTION', 'PATHS', 'STICKINESS', 'LIFECYCLE'].forEach((insightType) => {
it(`Can add a ${insightType} insight`, () => {
savedInsights.createNewInsightOfType(insightType)
insight.editName(`${insightType} Insight`)
insight.save()
cy.get('[data-attr="notebooks-add-button"]').click()
cy.get('[data-attr="notebooks-select-button-create"]').click()
cy.get('.ErrorBoundary').should('not.exist')
})
})
})
38 changes: 21 additions & 17 deletions frontend/src/scenes/notebooks/Nodes/NotebookNodeQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Query } from '~/queries/Query/Query'
import { DataTableNode, InsightQueryNode, InsightVizNode, NodeKind, QuerySchema } from '~/queries/schema'
import { createPostHogWidgetNode } from 'scenes/notebooks/Nodes/NodeWrapper'
import { InsightLogicProps, InsightShortId, NotebookNodeType } from '~/types'
import { useActions, useMountedLogic, useValues } from 'kea'
import { BindLogic, useActions, useMountedLogic, useValues } from 'kea'
import { useEffect, useMemo } from 'react'
import { notebookNodeLogic } from './notebookNodeLogic'
import { NotebookNodeProps, NotebookNodeAttributeProperties } from '../Notebook/utils'
Expand Down Expand Up @@ -35,9 +35,11 @@ const Component = ({
const { expanded } = useValues(nodeLogic)
const { setTitlePlaceholder } = useActions(nodeLogic)
const summarizeInsight = useSummarizeInsight()
const { insightName } = useValues(
insightLogic({ dashboardItemId: query.kind === NodeKind.SavedInsightNode ? query.shortId : 'new' })
)

const insightLogicProps = {
dashboardItemId: query.kind === NodeKind.SavedInsightNode ? query.shortId : ('new' as const),
}
const { insightName } = useValues(insightLogic(insightLogicProps))

useEffect(() => {
let title = 'Query'
Expand Down Expand Up @@ -96,19 +98,21 @@ const Component = ({

return (
<div className="flex flex-1 flex-col h-full">
<Query
// use separate keys for the settings and visualization to avoid conflicts with insightProps
uniqueKey={nodeId + '-component'}
query={modifiedQuery}
setQuery={(t) => {
updateAttributes({
query: {
...attributes.query,
source: (t as DataTableNode | InsightVizNode).source,
} as QuerySchema,
})
}}
/>
<BindLogic logic={insightLogic} props={insightLogicProps}>
<Query
// use separate keys for the settings and visualization to avoid conflicts with insightProps
uniqueKey={nodeId + '-component'}
query={modifiedQuery}
setQuery={(t) => {
updateAttributes({
query: {
...attributes.query,
source: (t as DataTableNode | InsightVizNode).source,
} as QuerySchema,
})
}}
/>
</BindLogic>
</div>
)
}
Expand Down

0 comments on commit cb1b316

Please sign in to comment.