Skip to content

Commit

Permalink
rename SourcedPersonsQuery to PersonsQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Sep 19, 2023
1 parent bbdb745 commit 29a5a34
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 139 deletions.
14 changes: 7 additions & 7 deletions frontend/src/queries/nodes/DataTable/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NodeKind,
PersonsNode,
QueryContext,
SourcedPersonsQuery,
PersonsQuery,
} from '~/queries/schema'
import { useCallback, useState } from 'react'
import { BindLogic, useValues } from 'kea'
Expand All @@ -36,7 +36,7 @@ import {
isHogQlAggregation,
isHogQLQuery,
isPersonsNode,
isSourcedPersonsQuery,
isPersonsQuery,
taxonomicFilterToHogQl,
} from '~/queries/utils'
import { PersonPropertyFilters } from '~/queries/nodes/PersonsNode/PersonPropertyFilters'
Expand Down Expand Up @@ -333,16 +333,16 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
].filter((column) => !query.hiddenColumns?.includes(column.dataIndex) && column.dataIndex !== '*')

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

const firstRowLeft = [
isSourcedPersonsQuery(query.source) ? (
isPersonsQuery(query.source) ? (
<LemonButton
onClick={() =>
isSourcedPersonsQuery(query.source)
isPersonsQuery(query.source)
? setQuery?.({ kind: NodeKind.InsightVizNode, source: query.source.source, full: true })
: null
}
Expand All @@ -356,13 +356,13 @@ export function DataTable({ uniqueKey, query, setQuery, context, cachedResults }
showEventFilter && isEventsQuery(query.source) ? (
<EventName query={query.source} setQuery={setQuerySource} />
) : null,
showSearch && (isPersonsNode(query.source) || isSourcedPersonsQuery(query.source)) ? (
showSearch && (isPersonsNode(query.source) || isPersonsQuery(query.source)) ? (
<PersonsSearch query={query.source} setQuery={setQuerySource} />
) : null,
showPropertyFilter && (isEventsQuery(query.source) || isHogQLQuery(query.source)) ? (
<EventPropertyFilters query={query.source} setQuery={setQuerySource} />
) : null,
showPropertyFilter && (isPersonsNode(query.source) || isSourcedPersonsQuery(query.source)) ? (
showPropertyFilter && (isPersonsNode(query.source) || isPersonsQuery(query.source)) ? (
<PersonPropertyFilters query={query.source} setQuery={setQuerySource} />
) : null,
].filter((x) => !!x)
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/queries/nodes/DataTable/renderColumn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isEventsQuery,
isHogQLQuery,
isPersonsNode,
isSourcedPersonsQuery,
isPersonsQuery,
isTimeToSeeDataSessionsQuery,
trimQuotes,
} from '~/queries/utils'
Expand Down Expand Up @@ -217,7 +217,7 @@ export function renderColumn(
<PersonDisplay noLink withIcon person={personRecord} noPopover />
</Link>
)
} else if (key === 'person.$delete' && (isPersonsNode(query.source) || isSourcedPersonsQuery(query.source))) {
} else if (key === 'person.$delete' && (isPersonsNode(query.source) || isPersonsQuery(query.source))) {
const personRecord = record as PersonType
return <DeletePersonButton person={personRecord} />
} else if (key.startsWith('context.columns.')) {
Expand All @@ -236,7 +236,7 @@ export function renderColumn(
} else if (key.startsWith('user.') && isTimeToSeeDataSessionsQuery(query.source)) {
const [parent, child] = key.split('.')
return typeof record === 'object' ? record[parent][child] : 'unknown'
} else if (isSourcedPersonsQuery(query.source)) {
} else if (isPersonsQuery(query.source)) {
if (key === 'id') {
return <div>{String(record[0])}</div>
} else if (key === 'created_at') {
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/queries/nodes/DataTable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const defaultDataTableEventColumns: HogQLExpression[] = [
]

export const defaultDataTablePersonColumns: HogQLExpression[] = ['person', 'id', 'created_at', 'person.$delete']
export const defaultDataTableSourcedPersonColumns: HogQLExpression[] = ['person', 'id', 'created_at']

export function defaultDataTableColumns(kind: NodeKind): HogQLExpression[] {
return kind === NodeKind.PersonsNode
Expand All @@ -20,8 +19,8 @@ export function defaultDataTableColumns(kind: NodeKind): HogQLExpression[] {
? defaultDataTableEventColumns
: kind === NodeKind.EventsNode
? defaultDataTableEventColumns.filter((c) => c !== '*')
: kind === NodeKind.SourcedPersonsQuery
? defaultDataTableSourcedPersonColumns
: kind === NodeKind.PersonsQuery
? defaultDataTablePersonColumns
: []
}

Expand Down
12 changes: 6 additions & 6 deletions frontend/src/queries/nodes/PersonsNode/PersonPropertyFilters.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PersonsNode, SourcedPersonsQuery } from '~/queries/schema'
import { PersonsNode, PersonsQuery } from '~/queries/schema'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
import { AnyPropertyFilter } from '~/types'
import { useState } from 'react'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { isPersonsNode, isSourcedPersonsQuery } from '~/queries/utils'
import { isPersonsNode, isPersonsQuery } from '~/queries/utils'

interface PersonPropertyFiltersProps {
query: PersonsNode | SourcedPersonsQuery
setQuery?: (query: PersonsNode | SourcedPersonsQuery) => void
query: PersonsNode | PersonsQuery
setQuery?: (query: PersonsNode | PersonsQuery) => void
}

let uniqueNode = 0
Expand All @@ -22,11 +22,11 @@ export function PersonPropertyFilters({ query, setQuery }: PersonPropertyFilters
...query,
properties: value,
} as PersonsNode)
} else if (isSourcedPersonsQuery(query)) {
} else if (isPersonsQuery(query)) {
setQuery?.({
...query,
properties: value,
} as SourcedPersonsQuery)
} as PersonsQuery)
}
}}
pageKey={`PersonPropertyFilters.${id}`}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/queries/nodes/PersonsNode/PersonsSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { PersonsNode, SourcedPersonsQuery } from '~/queries/schema'
import { PersonsNode, PersonsQuery } from '~/queries/schema'
import { LemonInput } from 'lib/lemon-ui/LemonInput/LemonInput'
import { IconInfo } from 'lib/lemon-ui/icons'
import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { useDebouncedQuery } from '~/queries/hooks/useDebouncedQuery'

interface PersonSearchProps {
query: PersonsNode | SourcedPersonsQuery
setQuery?: (query: PersonsNode | SourcedPersonsQuery) => void
query: PersonsNode | PersonsQuery
setQuery?: (query: PersonsNode | PersonsQuery) => void
}

export function PersonsSearch({ query, setQuery }: PersonSearchProps): JSX.Element {
const { value, onChange } = useDebouncedQuery<PersonsNode | SourcedPersonsQuery, string>(
const { value, onChange } = useDebouncedQuery<PersonsNode | PersonsQuery, string>(
query,
setQuery,
(query) => query.search || '',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
isHogQLQuery,
isInsightVizNode,
isLifecycleQuery,
isSourcedPersonsQuery,
isPersonsQuery,
} from './utils'
import api, { ApiMethodOptions } from 'lib/api'
import { getCurrentTeamId } from 'lib/utils/logics'
Expand Down Expand Up @@ -44,7 +44,7 @@ export function queryExportContext<N extends DataNode = DataNode>(
return queryExportContext(query.source, methodOptions, refresh)
} else if (isDataTableNode(query)) {
return queryExportContext(query.source, methodOptions, refresh)
} else if (isEventsQuery(query) || isSourcedPersonsQuery(query)) {
} else if (isEventsQuery(query) || isPersonsQuery(query)) {
return {
source: query,
max_limit: EXPORT_MAX_LIMIT,
Expand Down
132 changes: 66 additions & 66 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"$ref": "#/definitions/TimeToSeeDataSessionsQuery"
},
{
"$ref": "#/definitions/SourcedPersonsQuery"
"$ref": "#/definitions/PersonsQuery"
}
]
},
Expand Down Expand Up @@ -388,7 +388,7 @@
"$ref": "#/definitions/PersonsNode"
},
{
"$ref": "#/definitions/SourcedPersonsQuery"
"$ref": "#/definitions/PersonsQuery"
},
{
"$ref": "#/definitions/HogQLQuery"
Expand Down Expand Up @@ -1671,6 +1671,70 @@
"required": ["kind"],
"type": "object"
},
"PersonsQuery": {
"additionalProperties": false,
"properties": {
"day": {
"type": "string"
},
"group": {
"type": "string"
},
"kind": {
"const": "PersonsQuery",
"type": "string"
},
"properties": {
"items": {
"anyOf": [
{
"$ref": "#/definitions/PersonPropertyFilter"
},
{
"$ref": "#/definitions/HogQLPropertyFilter"
}
]
},
"type": "array"
},
"response": {
"$ref": "#/definitions/PersonsQueryResponse",
"description": "Cached query response"
},
"search": {
"type": "string"
},
"source": {
"$ref": "#/definitions/InsightQueryNode"
}
},
"required": ["kind", "source"],
"type": "object"
},
"PersonsQueryResponse": {
"additionalProperties": false,
"properties": {
"hogql": {
"type": "string"
},
"results": {
"description": "Results in the format: [ ['uuid', breakdown1, breakdown2, ...], ... ]",
"items": {
"items": {},
"type": "array"
},
"type": "array"
},
"timings": {
"items": {
"$ref": "#/definitions/QueryTiming"
},
"type": "array"
}
},
"required": ["results", "hogql"],
"type": "object"
},
"PropertyFilterValue": {
"anyOf": [
{
Expand Down Expand Up @@ -2059,70 +2123,6 @@
"enum": ["Volume", "Stickiness", "Lifecycle"],
"type": "string"
},
"SourcedPersonsQuery": {
"additionalProperties": false,
"properties": {
"day": {
"type": "string"
},
"group": {
"type": "string"
},
"kind": {
"const": "SourcedPersonsQuery",
"type": "string"
},
"properties": {
"items": {
"anyOf": [
{
"$ref": "#/definitions/PersonPropertyFilter"
},
{
"$ref": "#/definitions/HogQLPropertyFilter"
}
]
},
"type": "array"
},
"response": {
"$ref": "#/definitions/SourcedPersonsQueryResponse",
"description": "Cached query response"
},
"search": {
"type": "string"
},
"source": {
"$ref": "#/definitions/InsightQueryNode"
}
},
"required": ["kind", "source"],
"type": "object"
},
"SourcedPersonsQueryResponse": {
"additionalProperties": false,
"properties": {
"hogql": {
"type": "string"
},
"results": {
"description": "Results in the format: [ ['uuid', breakdown1, breakdown2, ...], ... ]",
"items": {
"items": {},
"type": "array"
},
"type": "array"
},
"timings": {
"items": {
"$ref": "#/definitions/QueryTiming"
},
"type": "array"
}
},
"required": ["results", "hogql"],
"type": "object"
},
"StepOrderValue": {
"enum": ["strict", "unordered", "ordered"],
"type": "string"
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export enum NodeKind {
PersonsNode = 'PersonsNode',
HogQLQuery = 'HogQLQuery',
HogQLMetadata = 'HogQLMetadata',
SourcedPersonsQuery = 'SourcedPersonsQuery',
PersonsQuery = 'PersonsQuery',

// Interface nodes
DataTableNode = 'DataTableNode',
Expand Down Expand Up @@ -78,7 +78,7 @@ export type AnyDataNode =
| HogQLQuery
| HogQLMetadata
| TimeToSeeDataSessionsQuery
| SourcedPersonsQuery
| PersonsQuery

export type QuerySchema =
// Data nodes (see utils.ts)
Expand Down Expand Up @@ -280,7 +280,7 @@ export type HasPropertiesNode = EventsNode | EventsQuery | PersonsNode
export interface DataTableNode extends Node, DataTableNodeViewProps {
kind: NodeKind.DataTableNode
/** Source of the events */
source: EventsNode | EventsQuery | PersonsNode | SourcedPersonsQuery | HogQLQuery | TimeToSeeDataSessionsQuery
source: EventsNode | EventsQuery | PersonsNode | PersonsQuery | HogQLQuery | TimeToSeeDataSessionsQuery

/** Columns shown in the table, unless the `source` provides them. */
columns?: HogQLExpression[]
Expand Down Expand Up @@ -463,21 +463,21 @@ export interface LifecycleQuery extends InsightsQueryBase {
response?: LifecycleQueryResponse
}

export interface SourcedPersonsQueryResponse {
export interface PersonsQueryResponse {
/** Results in the format: [ ['uuid', breakdown1, breakdown2, ...], ... ] */
results: any[][] // typed as any[], not [str, ...any] because python
hogql: string
timings?: QueryTiming[]
}

export interface SourcedPersonsQuery extends DataNode {
kind: NodeKind.SourcedPersonsQuery
export interface PersonsQuery extends DataNode {
kind: NodeKind.PersonsQuery
source: InsightQueryNode
day?: string
group?: string
search?: string
properties?: (PersonPropertyFilter | HogQLPropertyFilter)[]
response?: SourcedPersonsQueryResponse
response?: PersonsQueryResponse
}

export type InsightQueryNode =
Expand Down
Loading

0 comments on commit 29a5a34

Please sign in to comment.