Skip to content

Commit

Permalink
Merge branch 'master' into fix/timestamp-preference
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra authored Dec 6, 2024
2 parents aed45ba + 58f0a33 commit db073a4
Show file tree
Hide file tree
Showing 32 changed files with 562 additions and 452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { DataWarehouseTableForInsight } from 'scenes/data-warehouse/types'

import { ActionType, CohortType, EventDefinition, PropertyDefinition } from '~/types'

import { HogQLDropdown } from '../HogQLDropdown/HogQLDropdown'
import { taxonomicFilterLogic } from '../TaxonomicFilter/taxonomicFilterLogic'
import { TZLabel } from '../TZLabel'

Expand Down Expand Up @@ -291,8 +292,21 @@ function DefinitionView({ group }: { group: TaxonomicFilterGroup }): JSX.Element
label: column.name + ' (' + column.type + ')',
value: column.name,
}))
const hogqlOption = { label: 'HogQL Expression', value: '' }
const itemValue = localDefinition ? group?.getValue?.(localDefinition) : null

const isUsingHogQLExpression = (value: string | undefined): boolean => {
if (value === undefined) {
return false
}
const column = Object.values(_definition.fields ?? {}).find((n) => n.name == value)
return !column
}

const distinct_id_field_value =
'distinct_id_field' in localDefinition ? localDefinition.distinct_id_field : undefined
const timestamp_field_value = 'timestamp_field' in localDefinition ? localDefinition.timestamp_field : undefined

return (
<form className="definition-popover-data-warehouse-schema-form">
<div className="flex flex-col justify-between gap-4">
Expand All @@ -310,23 +324,33 @@ function DefinitionView({ group }: { group: TaxonomicFilterGroup }): JSX.Element
<span className="label-text">Distinct ID field</span>
</label>
<LemonSelect
value={
'distinct_id_field' in localDefinition ? localDefinition.distinct_id_field : undefined
}
options={columnOptions}
value={isUsingHogQLExpression(distinct_id_field_value) ? '' : distinct_id_field_value}
options={[...columnOptions, hogqlOption]}
onChange={(value) => setLocalDefinition({ distinct_id_field: value })}
/>
{isUsingHogQLExpression(distinct_id_field_value) && (
<HogQLDropdown
hogQLValue={distinct_id_field_value || ''}
tableName={_definition.name}
onHogQLValueChange={(value) => setLocalDefinition({ distinct_id_field: value })}
/>
)}

<label className="definition-popover-edit-form-label" htmlFor="Timestamp Field">
<span className="label-text">Timestamp field</span>
</label>
<LemonSelect
value={
('timestamp_field' in localDefinition && localDefinition.timestamp_field) || undefined
}
options={columnOptions}
value={isUsingHogQLExpression(timestamp_field_value) ? '' : timestamp_field_value}
options={[...columnOptions, hogqlOption]}
onChange={(value) => setLocalDefinition({ timestamp_field: value })}
/>
{isUsingHogQLExpression(timestamp_field_value) && (
<HogQLDropdown
hogQLValue={timestamp_field_value || ''}
tableName={_definition.name}
onHogQLValueChange={(value) => setLocalDefinition({ timestamp_field: value })}
/>
)}
</DefinitionPopover.Section>
<div className="flex justify-end">
<LemonButton
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/lib/components/HogQLDropdown/HogQLDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { LemonButton, LemonDropdown } from '@posthog/lemon-ui'
import clsx from 'clsx'
import { useState } from 'react'

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

import { HogQLEditor } from '../HogQLEditor/HogQLEditor'

export const HogQLDropdown = ({
hogQLValue,
onHogQLValueChange,
tableName,
className = '',
}: {
hogQLValue: string
tableName: string
className?: string
onHogQLValueChange: (hogQLValue: string) => void
}): JSX.Element => {
const [isHogQLDropdownVisible, setIsHogQLDropdownVisible] = useState(false)

return (
<div className={clsx('flex-auto overflow-hidden', className)}>
<LemonDropdown
visible={isHogQLDropdownVisible}
closeOnClickInside={false}
onClickOutside={() => setIsHogQLDropdownVisible(false)}
overlay={
// eslint-disable-next-line react/forbid-dom-props
<div className="w-120" style={{ maxWidth: 'max(60vw, 20rem)' }}>
<HogQLEditor
value={hogQLValue}
metadataSource={{ kind: NodeKind.HogQLQuery, query: `SELECT * FROM ${tableName}` }}
onChange={(currentValue) => {
onHogQLValueChange(currentValue)
setIsHogQLDropdownVisible(false)
}}
/>
</div>
}
>
<LemonButton
fullWidth
type="secondary"
onClick={() => setIsHogQLDropdownVisible(!isHogQLDropdownVisible)}
>
<code>{hogQLValue}</code>
</LemonButton>
</LemonDropdown>
</div>
)
}
50 changes: 4 additions & 46 deletions frontend/src/scenes/data-warehouse/ViewLinkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
LemonButton,
LemonCheckbox,
LemonDivider,
LemonDropdown,
LemonInput,
LemonModal,
LemonSelect,
Expand All @@ -14,12 +13,12 @@ import {
import { useActions, useValues } from 'kea'
import { Field, Form } from 'kea-forms'
import { CodeSnippet, Language } from 'lib/components/CodeSnippet'
import { HogQLEditor } from 'lib/components/HogQLEditor/HogQLEditor'
import { HogQLDropdown } from 'lib/components/HogQLDropdown/HogQLDropdown'
import { IconSwapHoriz } from 'lib/lemon-ui/icons'
import { useState } from 'react'
import { viewLinkLogic } from 'scenes/data-warehouse/viewLinkLogic'

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

export function ViewLinkModal(): JSX.Element {
const { isJoinTableModalOpen } = useValues(viewLinkLogic)
Expand Down Expand Up @@ -122,6 +121,7 @@ export function ViewLinkForm(): JSX.Element {
/>
{sourceIsUsingHogQLExpression && (
<HogQLDropdown
className="mt-2"
hogQLValue={selectedSourceKey ?? ''}
onHogQLValueChange={selectSourceKey}
tableName={selectedSourceTableName ?? ''}
Expand All @@ -147,6 +147,7 @@ export function ViewLinkForm(): JSX.Element {
/>
{joiningIsUsingHogQLExpression && (
<HogQLDropdown
className="mt-2"
hogQLValue={selectedJoiningKey ?? ''}
onHogQLValueChange={selectJoiningKey}
tableName={selectedJoiningTableName ?? ''}
Expand Down Expand Up @@ -247,49 +248,6 @@ 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 mt-2">
<LemonDropdown
visible={isHogQLDropdownVisible}
closeOnClickInside={false}
onClickOutside={() => setIsHogQLDropdownVisible(false)}
overlay={
// eslint-disable-next-line react/forbid-dom-props
<div className="w-120" style={{ maxWidth: 'max(60vw, 20rem)' }}>
<HogQLEditor
value={hogQLValue}
metadataSource={{ kind: NodeKind.HogQLQuery, query: `SELECT * FROM ${tableName}` }}
onChange={(currentValue) => {
onHogQLValueChange(currentValue)
setIsHogQLDropdownVisible(false)
}}
/>
</div>
}
>
<LemonButton
fullWidth
type="secondary"
onClick={() => setIsHogQLDropdownVisible(!isHogQLDropdownVisible)}
>
<code>{hogQLValue}</code>
</LemonButton>
</LemonDropdown>
</div>
)
}

interface KeyLabelProps {
column: DatabaseSchemaField
}
Expand Down
64 changes: 53 additions & 11 deletions frontend/src/scenes/data-warehouse/new/sourceWizardLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -513,18 +513,60 @@ export const SOURCE_DETAILS: Record<ExternalDataSourceType, SourceConfig> = {
placeholder: 'COMPUTE_WAREHOUSE',
},
{
name: 'user',
label: 'User',
type: 'text',
required: true,
placeholder: 'user',
},
{
name: 'password',
label: 'Password',
type: 'password',
type: 'select',
name: 'auth_type',
label: 'Authentication type',
required: true,
placeholder: '',
defaultValue: 'password',
options: [
{
label: 'Password',
value: 'password',
fields: [
{
name: 'username',
label: 'Username',
type: 'text',
required: true,
placeholder: 'User1',
},
{
name: 'password',
label: 'Password',
type: 'password',
required: true,
placeholder: '',
},
],
},
{
label: 'Key pair',
value: 'keypair',
fields: [
{
name: 'username',
label: 'Username',
type: 'text',
required: true,
placeholder: 'User1',
},
{
name: 'private_key',
label: 'Private key',
type: 'textarea',
required: true,
placeholder: '',
},
{
name: 'passphrase',
label: 'Passphrase',
type: 'password',
required: false,
placeholder: '',
},
],
},
],
},
{
name: 'role',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LemonLabel } from '@posthog/lemon-ui'
import { LemonInput } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { TestAccountFilterSwitch } from 'lib/components/TestAccountFiltersSwitch'
import { EXPERIMENT_DEFAULT_DURATION, FEATURE_FLAGS } from 'lib/constants'
import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
Expand Down Expand Up @@ -31,6 +32,12 @@ export function PrimaryGoalFunnels(): JSX.Element {
const metricIdx = 0
const currentMetric = experiment.metrics[metricIdx] as ExperimentFunnelsQuery

const actionFilterProps = {
...commonActionFilterProps,
// Remove data warehouse from the list because it's not supported in experiments
actionsTaxonomicGroupTypes: [TaxonomicFilterGroupType.Events, TaxonomicFilterGroupType.Actions],
}

return (
<>
<div className="mb-4">
Expand Down Expand Up @@ -107,7 +114,7 @@ export function PrimaryGoalFunnels(): JSX.Element {
seriesIndicatorType="numeric"
sortable={true}
showNestedArrow={true}
{...commonActionFilterProps}
{...actionFilterProps}
/>
<div className="mt-4 space-y-4">
<FunnelAggregationSelect
Expand Down
Loading

0 comments on commit db073a4

Please sign in to comment.