Skip to content

Commit

Permalink
feat(web-analytics): Add option to change group by in SessionAttribut…
Browse files Browse the repository at this point in the history
…ionExplorer (#23603)

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
robbie-c and github-actions[bot] authored Jul 11, 2024
1 parent e7db718 commit 0389468
Show file tree
Hide file tree
Showing 21 changed files with 1,472 additions and 90 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions frontend/src/queries/nodes/DataNode/DateRange.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DateFilter } from 'lib/components/DateFilter/DateFilter'

import { EventsQuery, HogQLQuery } from '~/queries/schema'
import { isEventsQuery, isHogQLQuery } from '~/queries/utils'
import { EventsQuery, HogQLQuery, SessionAttributionExplorerQuery } from '~/queries/schema'
import { isEventsQuery, isHogQLQuery, isSessionAttributionExplorerQuery } from '~/queries/utils'

interface DateRangeProps<Q extends EventsQuery | HogQLQuery> {
interface DateRangeProps<Q extends EventsQuery | HogQLQuery | SessionAttributionExplorerQuery> {
query: Q
setQuery?: (query: Q) => void
}
export function DateRange<Q extends EventsQuery | HogQLQuery>({
export function DateRange<Q extends EventsQuery | HogQLQuery | SessionAttributionExplorerQuery>({
query,
setQuery,
}: DateRangeProps<Q>): JSX.Element | null {
Expand All @@ -27,7 +27,7 @@ export function DateRange<Q extends EventsQuery | HogQLQuery>({
/>
)
}
if (isHogQLQuery(query)) {
if (isHogQLQuery(query) || isSessionAttributionExplorerQuery(query)) {
return (
<DateFilter
size="medium"
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/queries/nodes/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
EventsQuery,
HogQLQuery,
PersonsNode,
SessionAttributionExplorerQuery,
} from '~/queries/schema'
import { QueryContext } from '~/queries/types'
import {
Expand Down Expand Up @@ -385,7 +386,8 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
].filter((column) => !query.hiddenColumns?.includes(column.dataIndex) && column.dataIndex !== '*')

const setQuerySource = useCallback(
(source: EventsNode | EventsQuery | PersonsNode | ActorsQuery | HogQLQuery) => setQuery?.({ ...query, source }),
(source: EventsNode | EventsQuery | PersonsNode | ActorsQuery | HogQLQuery | SessionAttributionExplorerQuery) =>
setQuery?.({ ...query, source }),
[setQuery]
)

Expand All @@ -404,7 +406,11 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
/>
) : null,
showDateRange && sourceFeatures.has(QueryFeature.dateRangePicker) ? (
<DateRange key="date-range" query={query.source as HogQLQuery | EventsQuery} setQuery={setQuerySource} />
<DateRange
key="date-range"
query={query.source as HogQLQuery | EventsQuery | SessionAttributionExplorerQuery}
setQuery={setQuerySource}
/>
) : null,
showEventFilter && sourceFeatures.has(QueryFeature.eventNameFilter) ? (
<EventName key="event-name" query={query.source as EventsQuery} setQuery={setQuerySource} />
Expand All @@ -415,7 +421,7 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
showPropertyFilter && sourceFeatures.has(QueryFeature.eventPropertyFilters) ? (
<EventPropertyFilters
key="event-property"
query={query.source as EventsQuery}
query={query.source as EventsQuery | HogQLQuery | SessionAttributionExplorerQuery}
setQuery={setQuerySource}
taxonomicGroupTypes={Array.isArray(showPropertyFilter) ? showPropertyFilter : undefined}
/>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/queries/nodes/DataTable/queryFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
isEventsQuery,
isHogQLQuery,
isPersonsNode,
isSessionAttributionExplorerQuery,
isWebOverviewQuery,
isWebStatsTableQuery,
isWebTopClicksQuery,
Expand All @@ -29,7 +30,7 @@ export enum QueryFeature {
export function getQueryFeatures(query: Node): Set<QueryFeature> {
const features = new Set<QueryFeature>()

if (isHogQLQuery(query) || isEventsQuery(query)) {
if (isHogQLQuery(query) || isEventsQuery(query) || isSessionAttributionExplorerQuery(query)) {
features.add(QueryFeature.dateRangePicker)
features.add(QueryFeature.columnsInResponse)
features.add(QueryFeature.eventPropertyFilters)
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/queries/nodes/DataTable/renderColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,14 @@ export function renderColumn(
} else if (key.startsWith('context.columns.')) {
const columnName = trimQuotes(key.substring(16)) // 16 = "context.columns.".length
const Component = context?.columns?.[columnName]?.render
return Component ? <Component record={record} columnName={columnName} value={value} query={query} /> : ''
return Component ? (
<Component record={record} columnName={columnName} value={value} query={query} />
) : (
String(value)
)
} else if (context?.columns?.[key]) {
const Component = context?.columns?.[key]?.render
return Component ? <Component record={record} columnName={key} value={value} query={query} /> : ''
return Component ? <Component record={record} columnName={key} value={value} query={query} /> : String(value)
} else if (key === 'id' && (isPersonsNode(query.source) || isActorsQuery(query.source))) {
return (
<CopyToClipboardInline
Expand Down
22 changes: 11 additions & 11 deletions frontend/src/queries/nodes/EventsNode/EventPropertyFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { useState } from 'react'

import { EventsNode, EventsQuery, HogQLQuery } from '~/queries/schema'
import { isHogQLQuery } from '~/queries/utils'
import { EventsNode, EventsQuery, HogQLQuery, SessionAttributionExplorerQuery } from '~/queries/schema'
import { isHogQLQuery, isSessionAttributionExplorerQuery } from '~/queries/utils'
import { AnyPropertyFilter } from '~/types'

interface EventPropertyFiltersProps<Q extends EventsNode | EventsQuery | HogQLQuery> {
interface EventPropertyFiltersProps<Q extends EventsNode | EventsQuery | HogQLQuery | SessionAttributionExplorerQuery> {
query: Q
setQuery?: (query: Q) => void
taxonomicGroupTypes?: TaxonomicFilterGroupType[]
}

let uniqueNode = 0
export function EventPropertyFilters<Q extends EventsNode | EventsQuery | HogQLQuery>({
query,
setQuery,
taxonomicGroupTypes,
}: EventPropertyFiltersProps<Q>): JSX.Element {
export function EventPropertyFilters<
Q extends EventsNode | EventsQuery | HogQLQuery | SessionAttributionExplorerQuery
>({ query, setQuery, taxonomicGroupTypes }: EventPropertyFiltersProps<Q>): JSX.Element {
const [id] = useState(() => uniqueNode++)
const properties = isHogQLQuery(query) ? query.filters?.properties : query.properties
const eventNames = isHogQLQuery(query) ? [] : query.event ? [query.event] : []
const properties =
isHogQLQuery(query) || isSessionAttributionExplorerQuery(query) ? query.filters?.properties : query.properties
const eventNames =
isHogQLQuery(query) || isSessionAttributionExplorerQuery(query) ? [] : query.event ? [query.event] : []

return !properties || Array.isArray(properties) ? (
<PropertyFilters
Expand All @@ -36,7 +36,7 @@ export function EventPropertyFilters<Q extends EventsNode | EventsQuery | HogQLQ
]
}
onChange={(value: AnyPropertyFilter[]) => {
if (isHogQLQuery(query)) {
if (isHogQLQuery(query) || isSessionAttributionExplorerQuery(query)) {
setQuery?.({ ...query, filters: { ...(query.filters ?? {}), properties: value } })
} else {
setQuery?.({ ...query, properties: value })
Expand Down
Loading

0 comments on commit 0389468

Please sign in to comment.