Skip to content

Commit

Permalink
Ability to specify a HogQL expression for data warehouse
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbachhuber committed Dec 4, 2024
1 parent 700ad9c commit e4f4fbc
Showing 1 changed file with 32 additions and 8 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}

Check failure on line 333 in frontend/src/lib/components/DefinitionPopover/DefinitionPopoverContents.tsx

View workflow job for this annotation

GitHub Actions / Code quality checks

Type 'string | undefined' is not assignable to type 'string'.
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}

Check failure on line 349 in frontend/src/lib/components/DefinitionPopover/DefinitionPopoverContents.tsx

View workflow job for this annotation

GitHub Actions / Code quality checks

Type 'string | undefined' is not assignable to type 'string'.
tableName={_definition.name}
onHogQLValueChange={(value) => setLocalDefinition({ timestamp_field: value })}
/>
)}
</DefinitionPopover.Section>
<div className="flex justify-end">
<LemonButton
Expand Down

0 comments on commit e4f4fbc

Please sign in to comment.