Skip to content

Commit

Permalink
fix(hogql): pass parameter and use logic directly (#23338)
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE authored Jun 28, 2024
1 parent 9ce8bc5 commit c6c3b12
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
9 changes: 4 additions & 5 deletions frontend/src/queries/nodes/HogQLQuery/HogQLQueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Monaco } from '@monaco-editor/react'
import { IconInfo, IconMagicWand } from '@posthog/icons'
import { LemonInput, Link } from '@posthog/lemon-ui'
import clsx from 'clsx'
import { useActions, useMountedLogic, useValues } from 'kea'
import { useActions, useValues } from 'kea'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
import { FEATURE_FLAGS } from 'lib/constants'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
Expand Down Expand Up @@ -52,18 +52,17 @@ export function HogQLQueryEditor(props: HogQLQueryEditorProps): JSX.Element {
monaco,
}
const logic = hogQLQueryEditorLogic(hogQLQueryEditorLogicProps)
const { queryInput, hasErrors, error, prompt, aiAvailable, promptError, promptLoading, isValidView } =
useValues(logic)
const { queryInput, prompt, aiAvailable, promptError, promptLoading } = useValues(logic)
const { setQueryInput, saveQuery, setPrompt, draftFromPrompt, saveAsView } = useActions(logic)

const codeEditorKey = `hogQLQueryEditor/${key}`
const codeEditorLogicProps = {
key: codeEditorKey,
query: queryInput,
language: 'hogql',
language: 'hogQL',
metadataFilters: props.query.filters,
}
useMountedLogic(codeEditorLogic(codeEditorLogicProps))
const { hasErrors, error, isValidView } = useValues(codeEditorLogic(codeEditorLogicProps))

// Using useRef, not useState, as we don't want to reload the component when this changes.
const monacoDisposables = useRef([] as IDisposable[])
Expand Down
15 changes: 2 additions & 13 deletions frontend/src/queries/nodes/HogQLQuery/hogQLQueryEditorLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { actions, connect, kea, key, listeners, path, props, propsChanged, reduc
import { combineUrl } from 'kea-router'
import api from 'lib/api'
import { LemonField } from 'lib/lemon-ui/LemonField'
import { codeEditorLogic } from 'lib/monaco/codeEditorLogic'
// Note: we can only import types and not values from monaco-editor, because otherwise some Monaco code breaks
// auto reload in development. Specifically, on this line:
// `export const suggestWidgetStatusbarMenu = new MenuId('suggestWidgetStatusBar')`
Expand Down Expand Up @@ -39,19 +38,9 @@ export const hogQLQueryEditorLogic = kea<hogQLQueryEditorLogicType>([
actions.setQueryInput(props.query.query)
}
}),
connect((props: HogQLQueryEditorLogicProps) => ({
values: [
codeEditorLogic({
key: `hogQLQueryEditor/${key}`,
query: props.query.query,
language: 'hogql',
metadataFilters: props.query.filters,
metadataSource: props.metadataSource,
}),
['hasErrors', 'error', 'isValidView'],
],
connect({
actions: [dataWarehouseViewsLogic, ['createDataWarehouseSavedQuery']],
})),
}),
actions({
saveQuery: true,
setQueryInput: (queryInput: string) => ({ queryInput }),
Expand Down

0 comments on commit c6c3b12

Please sign in to comment.