Skip to content

Commit

Permalink
fix(hogql): fix saving hogql query nodes (#17522)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr authored Sep 19, 2023
1 parent ea13d0b commit 89b22a3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion frontend/src/scenes/insights/Insight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { InsightSkeleton } from 'scenes/insights/InsightSkeleton'
import { Query } from '~/queries/Query/Query'
import { InsightPageHeader } from 'scenes/insights/InsightPageHeader'
import { containsHogQLQuery, isInsightVizNode } from '~/queries/utils'

import { Node } from '~/queries/schema'
export interface InsightSceneProps {
insightId: InsightShortId | 'new'
}
Expand All @@ -30,6 +30,7 @@ export function Insight({ insightId }: InsightSceneProps): JSX.Element {

// insightDataLogic
const { query, isQueryBasedInsight, showQueryEditor } = useValues(insightDataLogic(insightProps))
const { setQuery: setInsightQuery } = useActions(insightDataLogic(insightProps))

// other logics
useMountedLogic(insightCommandLogic(insightProps))
Expand All @@ -48,6 +49,12 @@ export function Insight({ insightId }: InsightSceneProps): JSX.Element {
insightMode === ItemMode.Edit &&
((isQueryBasedInsight && !containsHogQLQuery(query)) || (!isQueryBasedInsight && showQueryEditor))

const setQuery = (query: Node): void => {
if (!isInsightVizNode(query)) {
setInsightQuery(query)
}
}

return (
<BindLogic logic={insightLogic} props={insightProps}>
<div className={'insights-page'}>
Expand All @@ -57,6 +64,7 @@ export function Insight({ insightId }: InsightSceneProps): JSX.Element {

<Query
query={isInsightVizNode(query) ? { ...query, full: true } : query}
setQuery={insightMode === ItemMode.Edit ? setQuery : undefined}
readOnly={insightMode !== ItemMode.Edit}
context={{
showOpenEditorButton: false,
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/scenes/insights/insightVizDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([
}
},
setQuery: ({ query }) => {
if (props.setQuery) {
props.setQuery(query as InsightVizNode)
}

if (isInsightVizNode(query)) {
if (props.setQuery) {
props.setQuery(query as InsightVizNode)
}

const querySource = query.source
const filters = queryNodeToFilter(querySource)
actions.setFilters(filters)
Expand Down

0 comments on commit 89b22a3

Please sign in to comment.