Skip to content

Commit

Permalink
fix(data-warehouse): Use the correct source table for join hogql expr…
Browse files Browse the repository at this point in the history
…essions (#20820)

Use the correct source tabel for join hogql expressions
  • Loading branch information
Gilbert09 authored Mar 12, 2024
1 parent ce10c14 commit 40786e6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions frontend/src/scenes/data-warehouse/ViewLinkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { IconSwapHoriz } from 'lib/lemon-ui/icons'
import { useState } from 'react'
import { viewLinkLogic } from 'scenes/data-warehouse/viewLinkLogic'

import { DatabaseSchemaQueryResponseField } from '~/queries/schema'
import { DatabaseSchemaQueryResponseField, NodeKind } from '~/queries/schema'

export function ViewLinkModal(): JSX.Element {
const { isJoinTableModalOpen } = useValues(viewLinkLogic)
Expand All @@ -45,7 +45,6 @@ export function ViewLinkModal(): JSX.Element {
export function ViewLinkForm(): JSX.Element {
const {
tableOptions,
selectedJoiningTable,
selectedJoiningTableName,
selectedSourceTableName,
sourceTableKeys,
Expand Down Expand Up @@ -116,6 +115,7 @@ export function ViewLinkForm(): JSX.Element {
<HogQLDropdown
hogQLValue={selectedSourceKey ?? ''}
onHogQLValueChange={selectSourceKey}
tableName={selectedSourceTableName ?? ''}
/>
)}
</>
Expand All @@ -132,14 +132,15 @@ export function ViewLinkForm(): JSX.Element {
fullWidth
onSelect={selectJoiningKey}
value={joiningIsUsingHogQLExpression ? '' : selectedJoiningKey ?? undefined}
disabledReason={selectedJoiningTable ? '' : 'Select a table to choose join key'}
disabledReason={selectedJoiningTableName ? '' : 'Select a table to choose join key'}
options={[...joiningTableKeys, { value: '', label: <span>HogQL Expression</span> }]}
placeholder="Select a key"
/>
{joiningIsUsingHogQLExpression && (
<HogQLDropdown
hogQLValue={selectedJoiningKey ?? ''}
onHogQLValueChange={selectJoiningKey}
tableName={selectedJoiningTableName ?? ''}
/>
)}
</>
Expand Down Expand Up @@ -195,14 +196,16 @@ export function ViewLinkForm(): JSX.Element {
const HogQLDropdown = ({
hogQLValue,
onHogQLValueChange,
tableName,
}: {
hogQLValue: string
tableName: string
onHogQLValueChange: (hogQLValue: string) => void
}): JSX.Element => {
const [isHogQLDropdownVisible, setIsHogQLDropdownVisible] = useState(false)

return (
<div className="flex-auto overflow-hidden">
<div className="flex-auto overflow-hidden mt-2">
<LemonDropdown
visible={isHogQLDropdownVisible}
closeOnClickInside={false}
Expand All @@ -213,6 +216,7 @@ const HogQLDropdown = ({
<HogQLEditor
disablePersonProperties
value={hogQLValue}
metadataSource={{ kind: NodeKind.HogQLQuery, query: `SELECT * FROM ${tableName}` }}
onChange={(currentValue) => {
onHogQLValueChange(currentValue)
setIsHogQLDropdownVisible(false)
Expand Down

0 comments on commit 40786e6

Please sign in to comment.