Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(insights): sourced person queries #17470

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
045bd64
feat(insights): sourced person queries
mariusandra Sep 15, 2023
ba73402
Update UI snapshots for `chromium` (1)
github-actions[bot] Sep 15, 2023
e2b1147
Merge remote-tracking branch 'origin' into persons-query-runners
mariusandra Sep 18, 2023
88b9b76
Merge branch 'persons-query-runners' of github.com:PostHog/posthog in…
mariusandra Sep 18, 2023
ab4f744
schema
mariusandra Sep 18, 2023
69c0302
send printed hogql with query
mariusandra Sep 18, 2023
5747dbc
open persons query in new view
mariusandra Sep 18, 2023
99bd927
Merge branch 'master' into persons-query-runners
mariusandra Sep 19, 2023
bbdb745
schema
mariusandra Sep 19, 2023
29a5a34
rename SourcedPersonsQuery to PersonsQuery
mariusandra Sep 19, 2023
e290085
persons query basic version
mariusandra Sep 19, 2023
a0558c1
properties
mariusandra Sep 19, 2023
aee489a
search filter
mariusandra Sep 19, 2023
fa0c6e3
property test
mariusandra Sep 19, 2023
5e9b7fa
specify nodes
mariusandra Sep 19, 2023
5032d24
split filter
mariusandra Sep 19, 2023
8715730
Merge branch 'master' into persons-query-runners
mariusandra Sep 19, 2023
e9dac1f
Merge branch 'master' into persons-query-runners
mariusandra Sep 26, 2023
faa8142
add blank tests
mariusandra Sep 26, 2023
ae7658c
fix string bug
mariusandra Sep 26, 2023
11825be
open query in a notebook
mariusandra Sep 26, 2023
7d61706
filter conditions
mariusandra Sep 26, 2023
2a5a853
open the edit sql button in a notebook
mariusandra Sep 26, 2023
99add59
slight cleanup
mariusandra Sep 26, 2023
20c42a6
columns
mariusandra Sep 26, 2023
5b3abf9
feat(datatable): explicitly enable features per query
mariusandra Sep 28, 2023
13249d5
update
mariusandra Sep 28, 2023
7e75ee7
Merge branch 'datatable-features' into persons-query-runners
mariusandra Sep 28, 2023
d0d2c03
persons table star
mariusandra Sep 28, 2023
c38a241
clarify conditions
mariusandra Sep 28, 2023
386d37c
Merge branch 'datatable-features' into persons-query-runners
mariusandra Sep 28, 2023
9b04626
fix column
mariusandra Sep 28, 2023
a57cdf2
Merge branch 'master' into persons-query-runners
mariusandra Sep 28, 2023
d21720a
person query page filters
mariusandra Sep 28, 2023
c9c3ccd
add distinct_ids table for persons
mariusandra Sep 28, 2023
3012fa1
search in distinct_ids
mariusandra Sep 28, 2023
95e7e97
Update query snapshots
github-actions[bot] Sep 28, 2023
150d594
open hogql button, fix persons display, uuid person urls, values syst…
mariusandra Sep 29, 2023
c81923b
Merge branch 'persons-query-runners' of github.com:PostHog/posthog in…
mariusandra Sep 29, 2023
30f66d2
persons modal as a new page
mariusandra Oct 2, 2023
f4884ed
table field for metadata expressions
mariusandra Oct 2, 2023
189ba49
add hogQLTable to taxonomic filter's HogQL editor
mariusandra Oct 3, 2023
d593e0a
Merge branch 'master' into persons-query-runners
mariusandra Oct 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const commandPaletteLogic = kea<commandPaletteLogicType>({
display: `View person ${input}`,
executor: () => {
const { push } = router.actions
push(urls.person(person.distinct_ids[0]))
push(urls.personDistinctId(person.distinct_ids[0]))
},
},
],
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/lib/components/HogQLEditor/HogQLEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { hogQLEditorLogic } from './hogQLEditorLogic'
export interface HogQLEditorProps {
onChange: (value: string) => void
value: string | undefined
hogQLTable?: string
disablePersonProperties?: boolean
disableAutoFocus?: boolean
disableCmdEnter?: boolean
Expand All @@ -20,6 +21,7 @@ let uniqueNode = 0
export function HogQLEditor({
onChange,
value,
hogQLTable,
disablePersonProperties,
disableAutoFocus,
disableCmdEnter,
Expand All @@ -28,7 +30,7 @@ export function HogQLEditor({
}: HogQLEditorProps): JSX.Element {
const [key] = useState(() => `HogQLEditor.${uniqueNode++}`)
const textareaRef = useRef<HTMLTextAreaElement | null>(null)
const logic = hogQLEditorLogic({ key, value, onChange, textareaRef })
const logic = hogQLEditorLogic({ key, value, onChange, hogQLTable, textareaRef })
const { localValue, error, responseLoading } = useValues(logic)
const { setLocalValue, submit } = useActions(logic)

Expand All @@ -53,7 +55,9 @@ export function HogQLEditor({
maxRows={6}
placeholder={
placeholder ??
(disablePersonProperties
(hogQLTable === 'persons'
? "Enter HogQL expression, such as:\n- properties.$geoip_country_name\n- toInt(properties.$browser_version) * 10\n- concat(properties.name, ' <', properties.email, '>')\n- is_identified ? 'user' : 'anon'"
: disablePersonProperties
? "Enter HogQL expression, such as:\n- properties.$current_url\n- toInt(properties.`Long Field Name`) * 10\n- concat(event, ' ', distinct_id)\n- if(1 < 2, 'small', 'large')"
: "Enter HogQL Expression, such as:\n- properties.$current_url\n- person.properties.$geoip_country_name\n- toInt(properties.`Long Field Name`) * 10\n- concat(event, ' ', distinct_id)\n- if(1 < 2, 'small', 'large')")
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/HogQLEditor/hogQLEditorLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React from 'react'
export interface HogQLEditorLogicProps {
key: string
value: string | undefined
hogQLTable?: string
onChange: (value: string) => void
textareaRef?: React.MutableRefObject<HTMLTextAreaElement | null>
}
Expand All @@ -32,6 +33,7 @@ export const hogQLEditorLogic = kea<hogQLEditorLogicType>([
const response = await query<HogQLMetadata>({
kind: NodeKind.HogQLMetadata,
expr: values.localValue,
table: props.hogQLTable || 'events',
})
breakpoint()
if (response && Array.isArray(response.errors) && response.errors.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface PropertyFiltersProps {
disablePopover?: boolean
style?: CSSProperties
taxonomicGroupTypes?: TaxonomicFilterGroupType[]
hogQLTable?: string
showNestedArrow?: boolean
eventNames?: string[]
logicalRowDivider?: boolean
Expand All @@ -36,6 +37,7 @@ export function PropertyFilters({
showConditionBadge = false,
disablePopover = false, // use bare PropertyFilter without popover
taxonomicGroupTypes,
hogQLTable,
style = {},
showNestedArrow = false,
eventNames = [],
Expand Down Expand Up @@ -88,6 +90,7 @@ export function PropertyFilters({
onComplete={onComplete}
orFiltering={orFiltering}
taxonomicGroupTypes={taxonomicGroupTypes}
hogQLTable={hogQLTable}
eventNames={eventNames}
propertyGroupType={propertyGroupType}
disablePopover={disablePopover || orFiltering}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function TaxonomicPropertyFilter({
orFiltering,
addText = 'Add filter',
hasRowOperator,
hogQLTable,
}: PropertyFilterInternalProps): JSX.Element {
const pageKey = useMemo(() => pageKeyInput || `filter-${uniqueMemoizedIndex++}`, [pageKeyInput])
const groupTypes = taxonomicGroupTypes || [
Expand Down Expand Up @@ -98,6 +99,7 @@ export function TaxonomicPropertyFilter({
value={cohortOrOtherValue}
onChange={taxonomicOnChange}
taxonomicGroupTypes={groupTypes}
hogQLTable={hogQLTable}
eventNames={eventNames}
/>
)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/PropertyFilters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export interface PropertyFilterInternalProps {
orFiltering?: boolean
addText?: string | null
hasRowOperator?: boolean
hogQLTable?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export function InfiniteSelectResults({
const RenderComponent = activeTaxonomicGroup?.render

const listComponent = RenderComponent ? (
<RenderComponent value={value} onChange={(newValue) => selectItem(activeTaxonomicGroup, newValue, newValue)} />
<RenderComponent
{...(activeTaxonomicGroup?.componentProps ?? {})}
value={value}
onChange={(newValue) => selectItem(activeTaxonomicGroup, newValue, newValue)}
/>
) : (
<InfiniteList />
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { HogQLEditor } from 'lib/components/HogQLEditor/HogQLEditor'
export interface InlineHogQLEditorProps {
value?: TaxonomicFilterValue
onChange: (value: TaxonomicFilterValue) => void
hogQLTable?: string
}

export function InlineHogQLEditor({ value, onChange }: InlineHogQLEditorProps): JSX.Element {
export function InlineHogQLEditor({ value, onChange, hogQLTable }: InlineHogQLEditorProps): JSX.Element {
return (
<div className="px-2">
<HogQLEditor
onChange={onChange}
value={String(value ?? '')}
hogQLTable={hogQLTable}
submitText={value ? 'Update HogQL expression' : 'Add HogQL expression'}
disableAutoFocus // :TRICKY: No autofocus here. It's controlled in the TaxonomicFilter.
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function TaxonomicFilter({
excludedProperties,
popoverEnabled = true,
selectFirstItem = true,
hogQLTable = 'events',
}: TaxonomicFilterProps): JSX.Element {
// Generate a unique key for each unique TaxonomicFilter that's rendered
const taxonomicFilterLogicKey = useMemo(
Expand All @@ -50,8 +51,8 @@ export function TaxonomicFilter({
popoverEnabled,
selectFirstItem,
excludedProperties,
hogQLTable,
}

const logic = taxonomicFilterLogic(taxonomicFilterLogicProps)
const { searchQuery, searchPlaceholder, activeTab } = useValues(logic)
const { setSearchQuery, moveUp, moveDown, tabLeft, tabRight, selectSelected } = useActions(logic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
(taxonomicFilterLogicKey) => taxonomicFilterLogicKey,
],
eventNames: [() => [(_, props) => props.eventNames], (eventNames) => eventNames ?? []],
hogQLTable: [() => [(_, props) => props.hogQLTable], (hogQLTable) => hogQLTable ?? 'events'],
excludedProperties: [
() => [(_, props) => props.excludedProperties],
(excludedProperties) => excludedProperties ?? {},
Expand All @@ -146,16 +147,18 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
s.groupAnalyticsTaxonomicGroups,
s.groupAnalyticsTaxonomicGroupNames,
s.eventNames,
s.hogQLTable,
s.excludedProperties,
],
(
teamId,
groupAnalyticsTaxonomicGroups,
groupAnalyticsTaxonomicGroupNames,
eventNames,
hogQLTable,
excludedProperties
): TaxonomicFilterGroup[] => {
const groups = [
const groups: TaxonomicFilterGroup[] = [
{
name: 'Events',
searchPlaceholder: 'events',
Expand Down Expand Up @@ -429,6 +432,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
type: TaxonomicFilterGroupType.HogQLExpression,
render: InlineHogQLEditor,
getPopoverHeader: () => 'HogQL',
componentProps: { hogQLTable },
},
...groupAnalyticsTaxonomicGroups,
...groupAnalyticsTaxonomicGroupNames,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/TaxonomicFilter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface TaxonomicFilterProps {
selectFirstItem?: boolean
/** use to filter results in a group by name, currently only working for EventProperties */
excludedProperties?: { [key in TaxonomicFilterGroupType]?: TaxonomicFilterValue[] }
hogQLTable?: string
}

export interface TaxonomicFilterLogicProps extends TaxonomicFilterProps {
Expand Down Expand Up @@ -56,6 +57,7 @@ export interface TaxonomicFilterGroup {
groupTypeIndex?: number
getFullDetailUrl?: (instance: any) => string
excludedProperties?: string[]
componentProps?: Record<string, any>
}

export enum TaxonomicFilterGroupType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface TaxonomicPopoverProps<ValueType extends TaxonomicFilterValue =
allowClear?: boolean
style?: React.CSSProperties
excludedProperties?: { [key in TaxonomicFilterGroupType]?: TaxonomicFilterValue[] }
hogQLTable?: string
}

/** Like TaxonomicPopover, but convenient when you know you will only use string values */
Expand All @@ -45,6 +46,7 @@ export function TaxonomicPopover<ValueType extends TaxonomicFilterValue = Taxono
placeholderClass = 'text-muted',
allowClear = false,
excludedProperties,
hogQLTable,
...buttonPropsRest
}: TaxonomicPopoverProps<ValueType>): JSX.Element {
const [localValue, setLocalValue] = useState<ValueType>(value || ('' as ValueType))
Expand Down Expand Up @@ -85,6 +87,7 @@ export function TaxonomicPopover<ValueType extends TaxonomicFilterValue = Taxono
}}
taxonomicGroupTypes={groupTypes ?? [groupType]}
eventNames={eventNames}
hogQLTable={hogQLTable}
excludedProperties={excludedProperties}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function redirectOnSelectItems(
} else if (groupType === TaxonomicFilterGroupType.Cohorts) {
router.actions.push(urls.cohort(value))
} else if (groupType === TaxonomicFilterGroupType.Persons) {
router.actions.push(urls.person(String(value)))
router.actions.push(urls.personDistinctId(String(value)))
} else if (groupType.startsWith(TaxonomicFilterGroupType.GroupNamesPrefix)) {
router.actions.push(urls.group((item as Group).group_type_index, String(value)))
} else if (groupType === TaxonomicFilterGroupType.Insights) {
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/lib/lemon-ui/icons/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,17 @@ export function IconQueryEditor(props: LemonIconProps): JSX.Element {
)
}

// https://pictogrammers.com/library/mdi/icon/database-eye/
export function IconQueryEye(props: LemonIconProps): JSX.Element {
return (
<LemonIconBase {...props}>
<path
fill="currentColor"
d="M4 12V9C4 11.2 7.6 13 12 13S20 11.2 20 9V12C20 12.5 19.8 12.9 19.5 13.4C18.7 13.1 17.9 13 17 13C14.5 13 12.1 14.1 10.6 15.9C6.8 15.6 4 14 4 12M12 11C16.4 11 20 9.2 20 7S16.4 3 12 3 4 4.8 4 7 7.6 11 12 11M9.1 19.7L8.8 19L9.1 18.3C9.2 18.1 9.3 18 9.3 17.8C6.2 17.2 4 15.8 4 14V17C4 18.8 6.4 20.3 9.7 20.8C9.5 20.5 9.3 20.1 9.1 19.7M17 18C16.4 18 16 18.4 16 19S16.4 20 17 20 18 19.6 18 19 17.6 18 17 18M23 19C22.1 21.3 19.7 23 17 23S11.9 21.3 11 19C11.9 16.7 14.3 15 17 15S22.1 16.7 23 19M19.5 19C19.5 17.6 18.4 16.5 17 16.5S14.5 17.6 14.5 19 15.6 21.5 17 21.5 19.5 20.4 19.5 19Z"
/>
</LemonIconBase>
)
}
/** Material Design Auto Awesome icon. */
export function IconAutoAwesome(props: LemonIconProps): JSX.Element {
return (
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/queries/nodes/DataNode/dataNodeLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ export const dataNodeLogic = kea<dataNodeLogicType>([
return response && 'timings' in response ? response.timings : null
},
],
responseHogQL: [
(s) => [s.response],
(response): string | null => {
return response && 'hogql' in response && typeof response.hogql === 'string' ? response.hogql : null
},
],
}),
listeners(({ actions, values, cache }) => ({
abortAnyRunningQuery: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { columnConfiguratorLogic, ColumnConfiguratorLogicProps } from './columnC
import { defaultDataTableColumns, extractExpressionComment, removeExpressionComment } from '../utils'
import { DataTableNode, NodeKind } from '~/queries/schema'
import { LemonModal } from 'lib/lemon-ui/LemonModal'
import { isEventsQuery, taxonomicFilterToHogQl, trimQuotes } from '~/queries/utils'
import { isEventsQuery, taxonomicEventFilterToHogQl, trimQuotes } from '~/queries/utils'
import { TaxonomicFilter } from 'lib/components/TaxonomicFilter/TaxonomicFilter'
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
import { PropertyFilterIcon } from 'lib/components/PropertyFilters/components/PropertyFilterIcon'
Expand Down Expand Up @@ -166,7 +166,7 @@ function ColumnConfiguratorModal({ query }: ColumnConfiguratorProps): JSX.Elemen
]}
value={undefined}
onChange={(group, value) => {
const column = taxonomicFilterToHogQl(group.type, value)
const column = taxonomicEventFilterToHogQl(group.type, value)
if (column !== null) {
selectColumn(column)
}
Expand Down
Loading