Skip to content

Commit

Permalink
Merge branch 'master' into tom/stripe-templating-1
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE authored Mar 15, 2024
2 parents c7e97c8 + 5209274 commit 14d3333
Show file tree
Hide file tree
Showing 34 changed files with 598 additions and 561 deletions.
2 changes: 1 addition & 1 deletion ee/api/dashboard_collaborator.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DashboardCollaboratorViewSet(
mixins.DestroyModelMixin,
viewsets.GenericViewSet,
):
scope_object = "INTERNAL"
scope_object = "dashboard"
permission_classes = [CanEditDashboardCollaborator]
pagination_class = None
queryset = DashboardPrivilege.objects.select_related("dashboard").filter(user__is_active=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@ import { ActivityLogItem } from 'lib/components/ActivityLog/humanizeActivity'
import { ActivityScope, InsightShortId } from '~/types'

export const teamActivityResponseJson: ActivityLogItem[] = [
{
user: {
first_name: 'sdavasdadadsadas',
last_name: '',
email: '[email protected]',
},
unread: false,
is_staff: false,
is_system: false,
activity: 'updated',
item_id: '1',
scope: ActivityScope.TEAM,
detail: {
name: 'Default Project',
type: undefined,
merge: null,
changes: [
{
type: ActivityScope.TEAM,
after: { poe_v2_enabled: true },
field: 'extra_settings',
action: 'created',
before: null,
},
],
trigger: null,
short_id: null,
},
created_at: '2024-02-08T19:23:53.530402Z',
},
{
user: {
first_name: 'sdavasdadadsadas',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,18 @@ function DefinitionView({ group }: { group: TaxonomicFilterGroup }): JSX.Element
onChange={(value) => setLocalDefinition({ id_field: value })}
/>

<label className="definition-popover-edit-form-label" htmlFor="ID Field">
<label className="definition-popover-edit-form-label" htmlFor="Distinct Id Field">
<span className="label-text">Distinct ID field</span>
</label>
<LemonSelect
value={
'distinct_id_field' in localDefinition ? localDefinition.distinct_id_field : undefined
}
options={columnOptions}
onChange={(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
Expand All @@ -313,7 +324,9 @@ function DefinitionView({ group }: { group: TaxonomicFilterGroup }): JSX.Element
'id_field' in localDefinition &&
localDefinition.id_field &&
'timestamp_field' in localDefinition &&
localDefinition.timestamp_field
localDefinition.timestamp_field &&
'distinct_id_field' in localDefinition &&
localDefinition.distinct_id_field
? null
: 'Field mappings must be specified'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LemonButton, LemonButtonProps } from 'lib/lemon-ui/LemonButton'
import { LemonDropdown } from 'lib/lemon-ui/LemonDropdown'
import { useEffect, useState } from 'react'

import { AnyDataNode } from '~/queries/schema'
import { AnyDataNode, DatabaseSchemaQueryResponseField } from '~/queries/schema'

export interface TaxonomicPopoverProps<ValueType extends TaxonomicFilterValue = TaxonomicFilterValue>
extends Omit<LemonButtonProps, 'children' | 'onClick' | 'sideIcon' | 'sideAction'> {
Expand All @@ -19,6 +19,7 @@ export interface TaxonomicPopoverProps<ValueType extends TaxonomicFilterValue =
placeholder?: React.ReactNode
placeholderClass?: string
dropdownMatchSelectWidth?: boolean
schemaColumns?: DatabaseSchemaQueryResponseField[]
allowClear?: boolean
style?: React.CSSProperties
excludedProperties?: { [key in TaxonomicFilterGroupType]?: TaxonomicFilterValue[] }
Expand Down Expand Up @@ -49,6 +50,7 @@ export function TaxonomicPopover<ValueType extends TaxonomicFilterValue = Taxono
allowClear = false,
excludedProperties,
metadataSource,
schemaColumns,
...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}
schemaColumns={schemaColumns}
metadataSource={metadataSource}
excludedProperties={excludedProperties}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export const legacyEntityToNode = (
custom_name: entity.custom_name || undefined,
id_field: 'id_field' in entity ? entity.id_field : undefined,
timestamp_field: 'timestamp_field' in entity ? entity.timestamp_field : undefined,
distinct_id_field: 'distinct_id_field' in entity ? entity.distinct_id_field : undefined,
table_name: 'table_name' in entity ? entity.table_name : undefined,
}

Expand All @@ -103,6 +104,7 @@ export const legacyEntityToNode = (
...shared,
id_field: entity.id_field || undefined,
timestamp_field: entity.timestamp_field || undefined,
distinct_id_field: entity.distinct_id_field || undefined,
table_name: entity.table_name || undefined,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export const seriesNodeToFilter = (
math_group_type_index: node.math_group_type_index,
properties: node.properties as any, // TODO,
...(isDataWarehouseNode(node)
? { table_name: node.table_name, id_field: node.id_field, timestamp_field: node.timestamp_field }
? {
table_name: node.table_name,
id_field: node.id_field,
timestamp_field: node.timestamp_field,
distinct_id_field: node.distinct_id_field,
}
: {}),
})
return entity
Expand Down
30 changes: 29 additions & 1 deletion frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -764,12 +764,34 @@
"required": ["kind", "source"],
"type": "object"
},
"DataWarehouseEventsModifier": {
"additionalProperties": false,
"properties": {
"distinct_id_field": {
"type": "string"
},
"id_field": {
"type": "string"
},
"table_name": {
"type": "string"
},
"timestamp_field": {
"type": "string"
}
},
"required": ["table_name", "timestamp_field", "distinct_id_field", "id_field"],
"type": "object"
},
"DataWarehouseNode": {
"additionalProperties": false,
"properties": {
"custom_name": {
"type": "string"
},
"distinct_id_field": {
"type": "string"
},
"fixedProperties": {
"description": "Fixed properties in the query, can't be edited in the interface (e.g. scoping down by person)",
"items": {
Expand Down Expand Up @@ -837,7 +859,7 @@
"type": "string"
}
},
"required": ["id", "id_field", "kind", "table_name", "timestamp_field"],
"required": ["distinct_id_field", "id", "id_field", "kind", "table_name", "timestamp_field"],
"type": "object"
},
"DataWarehousePropertyFilter": {
Expand Down Expand Up @@ -2526,6 +2548,12 @@
"additionalProperties": false,
"description": "HogQL Query Options are automatically set per team. However, they can be overriden in the query.",
"properties": {
"dataWarehouseEventsModifiers": {
"items": {
"$ref": "#/definitions/DataWarehouseEventsModifier"
},
"type": "array"
},
"inCohortVia": {
"enum": ["auto", "leftjoin", "subquery", "leftjoin_conjoined"],
"type": "string"
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ export interface HogQLQueryModifiers {
personsArgMaxVersion?: 'auto' | 'v1' | 'v2'
inCohortVia?: 'auto' | 'leftjoin' | 'subquery' | 'leftjoin_conjoined'
materializationMode?: 'auto' | 'legacy_null_as_string' | 'legacy_null_as_null' | 'disabled'
dataWarehouseEventsModifiers?: DataWarehouseEventsModifier[]
}

export interface DataWarehouseEventsModifier {
table_name: string
timestamp_field: string
distinct_id_field: string
id_field: string
}

export interface HogQLQueryResponse {
Expand Down Expand Up @@ -376,6 +384,7 @@ export interface DataWarehouseNode extends EntityNode {
id_field: string
table_name: string
timestamp_field: string
distinct_id_field: string
}

export interface ActionsNode extends EntityNode {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/data-warehouse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface DataWarehouseTableBaseType {
// used for selecting in trends series
id_field?: string
timestamp_field?: string
distinct_id_field?: string
}

export interface DataWarehousePostHogTableType extends DataWarehouseTableBaseType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ export function ActionFilterRow({
const { setNodeRef, attributes, transform, transition, listeners, isDragging } = useSortable({ id: filter.uuid })

const propertyFiltersVisible = typeof filter.order === 'number' ? entityFilterVisible[filter.order] : false
const mathDisabledReason =
filter.type === EntityTypes.DATA_WAREHOUSE ? 'Data Warehouse Series only supports total counts' : ''

let name: string | null | undefined, value: PropertyFilterValue
const {
Expand Down Expand Up @@ -239,6 +237,7 @@ export function ActionFilterRow({
name: item?.name ?? '',
id_field: item?.id_field,
timestamp_field: item?.timestamp_field,
distinct_id_field: item?.distinct_id_field,
table_name: item?.name,
index,
})
Expand Down Expand Up @@ -375,7 +374,6 @@ export function ActionFilterRow({
index={index}
onMathSelect={onMathSelect}
disabled={readOnly}
disabledReason={mathDisabledReason}
style={{ maxWidth: '100%', width: 'initial' }}
mathAvailability={mathAvailability}
/>
Expand All @@ -385,9 +383,15 @@ export function ActionFilterRow({
<TaxonomicStringPopover
groupType={TaxonomicFilterGroupType.NumericalEventProperties}
groupTypes={[
TaxonomicFilterGroupType.DataWarehouseProperties,
TaxonomicFilterGroupType.NumericalEventProperties,
TaxonomicFilterGroupType.Sessions,
]}
schemaColumns={
filter.type == TaxonomicFilterGroupType.DataWarehouse && filter.name
? externalTablesMap[filter.name]?.columns
: []
}
value={mathProperty}
onChange={(currentValue) => onMathPropertySelect(index, currentValue)}
eventNames={name ? [name] : []}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type LocalFilter = ActionFilter & {
uuid: string
id_field?: string
timestamp_field?: string
distinct_id_field?: string
table_name?: string
}

Expand Down Expand Up @@ -104,6 +105,7 @@ export const entityFilterLogic = kea<entityFilterLogicType>([
index: number
id_field?: string
timestamp_field?: string
distinct_id_field?: string
table_name?: string
}
) => ({
Expand Down Expand Up @@ -196,7 +198,17 @@ export const entityFilterLogic = kea<entityFilterLogicType>([
hideModal: () => {
actions.selectFilter(null)
},
updateFilter: async ({ type, index, name, id, custom_name, id_field, timestamp_field, table_name }) => {
updateFilter: async ({
type,
index,
name,
id,
custom_name,
id_field,
timestamp_field,
distinct_id_field,
table_name,
}) => {
actions.setFilters(
values.localFilters.map((filter, i) => {
if (i === index) {
Expand All @@ -210,11 +222,16 @@ export const entityFilterLogic = kea<entityFilterLogicType>([
id_field: typeof id_field === 'undefined' ? filter.id_field : id_field,
timestamp_field:
typeof timestamp_field === 'undefined' ? filter.timestamp_field : timestamp_field,
distinct_id_field:
typeof distinct_id_field === 'undefined'
? filter.distinct_id_field
: distinct_id_field,
table_name: typeof table_name === 'undefined' ? filter.table_name : table_name,
}
} else {
delete filter.id_field
delete filter.timestamp_field
delete filter.distinct_id_field
delete filter.table_name
return {
...filter,
Expand Down
8 changes: 5 additions & 3 deletions frontend/src/scenes/onboarding/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,24 @@ const ProductAnalyticsOnboarding = (): JSX.Element => {
}
const SessionReplayOnboarding = (): JSX.Element => {
const { hasAvailableFeature } = useValues(userLogic)
const { currentTeam } = useValues(teamLogic)

const configOptions: ProductConfigOption[] = [
{
type: 'toggle',
title: 'Capture console logs',
description: `Capture console logs as a part of user session recordings.
Use the console logs alongside recordings to debug any issues with your app.`,
teamProperty: 'capture_console_log_opt_in',
value: true,
value: currentTeam?.capture_console_log_opt_in ?? true,
},
{
type: 'toggle',
title: 'Capture network performance',
description: `Capture performance and network information alongside recordings. Use the
network requests and timings in the recording player to help you debug issues with your app.`,
teamProperty: 'capture_performance_opt_in',
value: true,
value: currentTeam?.capture_performance_opt_in ?? true,
},
]

Expand All @@ -126,7 +128,7 @@ const SessionReplayOnboarding = (): JSX.Element => {
description: `Only record sessions that are longer than the specified duration.
Start with it low and increase it later if you're getting too many short sessions.`,
teamProperty: 'session_recording_minimum_duration_milliseconds',
value: null,
value: currentTeam?.session_recording_minimum_duration_milliseconds || null,
selectOptions: SESSION_REPLAY_MINIMUM_DURATION_OPTIONS,
})
}
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/scenes/onboarding/OnboardingProductConfiguration.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LemonDivider, LemonSelect, LemonSwitch } from '@posthog/lemon-ui'
import { useActions, useValues } from 'kea'
import React, { useEffect } from 'react'
import React, { useEffect, useRef } from 'react'
import { pluginsLogic } from 'scenes/plugins/pluginsLogic'

import { OnboardingStepKey } from './onboardingLogic'
Expand Down Expand Up @@ -51,6 +51,12 @@ export const OnboardingProductConfiguration = ({
const { setConfigOptions, saveConfiguration } = useActions(onboardingProductConfigurationLogic)
const { toggleEnabled } = useActions(pluginsLogic)

const configOptionsRef = useRef(configOptions)

useEffect(() => {
configOptionsRef.current = configOptions
}, [configOptions])

useEffect(() => {
setConfigOptions(options)
}, [])
Expand All @@ -63,9 +69,12 @@ export const OnboardingProductConfiguration = ({
selectOptions: option.selectOptions,
value: option.value,
onChange: (newValue: boolean | string | number) => {
setConfigOptions(
configOptions.map((o) => (o.teamProperty === option.teamProperty ? { ...o, value: newValue } : o))
// Use the current value from the ref to ensure that onChange always accesses
// the latest state of configOptions, preventing the closure from using stale data.
const updatedConfigOptions = configOptionsRef.current.map((o) =>
o.teamProperty === option.teamProperty ? { ...o, value: newValue } : o
)
setConfigOptions(updatedConfigOptions)
},
})),
...defaultEnabledPlugins.map((plugin) => {
Expand Down
Loading

0 comments on commit 14d3333

Please sign in to comment.