Skip to content

Commit

Permalink
Merge branch 'master' into feat/store-text-alongside-notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Sep 13, 2023
2 parents 1654591 + ab0e989 commit a501070
Show file tree
Hide file tree
Showing 54 changed files with 957 additions and 444 deletions.
3 changes: 3 additions & 0 deletions docker-compose.hobby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ services:
extends:
file: docker-compose.base.yml
service: db
# Pin to postgres 12 until we have a process for pg_upgrade to postgres 15 for exsisting installations
image: ${DOCKER_REGISTRY_PREFIX:-}postgres:12-alpine
volumes:
- postgres-data:/var/lib/postgresql/data

redis:
extends:
file: docker-compose.base.yml
Expand Down
2 changes: 1 addition & 1 deletion ee/clickhouse/views/test/test_clickhouse_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ def test_used_in_experiment_is_populated_correctly_for_feature_flag_list(self) -
).json()

# TODO: Make sure permission bool doesn't cause n + 1
with self.assertNumQueries(11):
with self.assertNumQueries(12):
response = self.client.get(f"/api/projects/{self.team.id}/feature_flags")
self.assertEqual(response.status_code, status.HTTP_200_OK)
result = response.json()
Expand Down
38 changes: 22 additions & 16 deletions frontend/src/layout/navigation/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ export function TopBar(): JSX.Element {
const { hideInviteModal } = useActions(inviteLogic)
const { groupNamesTaxonomicTypes } = useValues(groupsModel)
const { featureFlags } = useValues(featureFlagLogic)

const hasNotebooks = !!featureFlags[FEATURE_FLAGS.NOTEBOOKS]

const groupTypes = [
TaxonomicFilterGroupType.Events,
TaxonomicFilterGroupType.Persons,
TaxonomicFilterGroupType.Actions,
TaxonomicFilterGroupType.Cohorts,
TaxonomicFilterGroupType.Insights,
TaxonomicFilterGroupType.FeatureFlags,
TaxonomicFilterGroupType.Plugins,
TaxonomicFilterGroupType.Experiments,
TaxonomicFilterGroupType.Dashboards,
...groupNamesTaxonomicTypes,
]

if (hasNotebooks) {
groupTypes.push(TaxonomicFilterGroupType.Notebooks)
}

return (
<>
<Announcement />
Expand All @@ -48,26 +68,12 @@ export function TopBar(): JSX.Element {
</Link>

<div className="grow">
<UniversalSearchPopover
groupType={TaxonomicFilterGroupType.Events}
groupTypes={[
TaxonomicFilterGroupType.Events,
TaxonomicFilterGroupType.Persons,
TaxonomicFilterGroupType.Actions,
TaxonomicFilterGroupType.Cohorts,
TaxonomicFilterGroupType.Insights,
TaxonomicFilterGroupType.FeatureFlags,
TaxonomicFilterGroupType.Plugins,
TaxonomicFilterGroupType.Experiments,
TaxonomicFilterGroupType.Dashboards,
...groupNamesTaxonomicTypes,
]}
/>
<UniversalSearchPopover groupType={TaxonomicFilterGroupType.Events} groupTypes={groupTypes} />
</div>
<ActivationSidebarToggle />
</div>
<div className="TopBar__segment TopBar__segment--right">
{!!featureFlags[FEATURE_FLAGS.NOTEBOOKS] && <NotebookButton />}
{hasNotebooks && <NotebookButton />}
<NotificationBell />
<HelpButton />
<SitePopover />
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ const api = {
q = { ...q, created_by: createdBy }
}
if (search) {
q = { ...q, s: search }
q = { ...q, search: search }
}
return await apiRequest.withQueryString(q).get()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
PersonType,
PluginType,
PropertyDefinition,
NotebookType,
} from '~/types'
import { cohortsModel } from '~/models/cohortsModel'
import { actionsModel } from '~/models/actionsModel'
Expand All @@ -42,6 +43,7 @@ import { groupDisplayId } from 'scenes/persons/GroupActorDisplay'
import { infiniteListLogicType } from 'lib/components/TaxonomicFilter/infiniteListLogicType'
import { updatePropertyDefinitions } from '~/models/propertyDefinitionsModel'
import { InlineHogQLEditor } from './InlineHogQLEditor'
import { FEATURE_FLAGS } from 'lib/constants'

export const eventTaxonomicGroupProps: Pick<TaxonomicFilterGroup, 'getPopoverHeader' | 'getIcon'> = {
getPopoverHeader: (eventDefinition: EventDefinition): string => {
Expand Down Expand Up @@ -77,6 +79,8 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
['groupTypes', 'aggregationLabel'],
groupPropertiesModel,
['allGroupProperties'],
featureFlagsLogic,
['featureFlags'],
],
},
actions: () => ({
Expand Down Expand Up @@ -146,15 +150,17 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
s.groupAnalyticsTaxonomicGroupNames,
s.eventNames,
s.excludedProperties,
s.featureFlags,
],
(
teamId,
groupAnalyticsTaxonomicGroups,
groupAnalyticsTaxonomicGroupNames,
eventNames,
excludedProperties
excludedProperties,
featureFlags
): TaxonomicFilterGroup[] => {
return [
const groups = [
{
name: 'Events',
searchPlaceholder: 'events',
Expand Down Expand Up @@ -209,7 +215,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
filter_by_event_names: true,
}).url
: undefined,
expandLabel: ({ count, expandedCount }) =>
expandLabel: ({ count, expandedCount }: { count: number; expandedCount: number }) =>
`Show ${pluralize(expandedCount - count, 'property', 'properties')} that ${pluralize(
eventNames.length,
'has',
Expand Down Expand Up @@ -237,7 +243,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
filter_by_event_names: true,
}).url
: undefined,
expandLabel: ({ count, expandedCount }) =>
expandLabel: ({ count, expandedCount }: { count: number; expandedCount: number }) =>
`Show ${pluralize(expandedCount - count, 'property', 'properties')} that ${pluralize(
eventNames.length,
'has',
Expand Down Expand Up @@ -408,8 +414,8 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
value: '$session_duration',
},
],
getName: (option) => option.name,
getValue: (option) => option.value,
getName: (option: any) => option.name,
getValue: (option: any) => option.value,
getPopoverHeader: () => 'Session',
},
{
Expand All @@ -422,6 +428,21 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>({
...groupAnalyticsTaxonomicGroups,
...groupAnalyticsTaxonomicGroupNames,
]

if (featureFlags[FEATURE_FLAGS.NOTEBOOKS]) {
groups.push({
name: 'Notebooks',
searchPlaceholder: 'notebooks',
type: TaxonomicFilterGroupType.Notebooks,
value: 'notebooks',
endpoint: `api/projects/${teamId}/notebooks/`,
getName: (notebook: NotebookType) => notebook.title || `Notebook ${notebook.short_id}`,
getValue: (notebook: NotebookType) => notebook.short_id,
getPopoverHeader: () => 'Notebooks',
})
}

return groups
},
],
activeTaxonomicGroup: [
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/TaxonomicFilter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export enum TaxonomicFilterGroupType {
GroupNamesPrefix = 'name_groups',
Sessions = 'sessions',
HogQLExpression = 'hogql_expression',
Notebooks = 'notebooks',
}

export interface InfiniteListLogicProps extends TaxonomicFilterLogicProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ function redirectOnSelectItems(
)
} else if (groupType === TaxonomicFilterGroupType.Dashboards) {
router.actions.push(urls.dashboard(value))
} else if (groupType === TaxonomicFilterGroupType.Notebooks) {
router.actions.push(urls.notebook(String(value)))
}
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const FEATURE_FLAGS = {
SURVEY_NPS_RESULTS: 'survey-nps-results', // owner: @liyiy
// owner: #team-monitoring
SESSION_RECORDING_ALLOW_V1_SNAPSHOTS: 'session-recording-allow-v1-snapshots',
HOGQL_INSIGHTS: 'hogql-insights', // owner: @mariusandra
} as const
export type FeatureFlagKey = (typeof FEATURE_FLAGS)[keyof typeof FEATURE_FLAGS]

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/queries/nodes/DataTable/dataTableLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ export const dataTableLogic = kea<dataTableLogicType>([
showReload: query.showReload ?? showIfFull,
showTimings: query.showTimings ?? flagQueryTimingsEnabled,
showElapsedTime:
query.showTimings ||
flagQueryTimingsEnabled ||
(query.showTimings ?? flagQueryTimingsEnabled) ||
(query.showElapsedTime ??
((flagQueryRunningTimeEnabled || source.kind === NodeKind.HogQLQuery) && showIfFull)),
showColumnConfigurator: query.showColumnConfigurator ?? showIfFull,
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/queries/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
isTimeToSeeDataSessionsNode,
isHogQLQuery,
isInsightVizNode,
isLifecycleQuery,
} from './utils'
import api, { ApiMethodOptions } from 'lib/api'
import { getCurrentTeamId } from 'lib/utils/logics'
Expand All @@ -27,6 +28,8 @@ import { toParams } from 'lib/utils'
import { queryNodeToFilter } from './nodes/InsightQuery/utils/queryNodeToFilter'
import { now } from 'lib/dayjs'
import { currentSessionId } from 'lib/internalMetrics'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { FEATURE_FLAGS } from 'lib/constants'

const EXPORT_MAX_LIMIT = 10000

Expand Down Expand Up @@ -104,10 +107,14 @@ export async function query<N extends DataNode = DataNode>(
const logParams: Record<string, any> = {}
const startTime = performance.now()

const hogQLInsightsFlagEnabled = Boolean(
featureFlagLogic.findMounted()?.values.featureFlags?.[FEATURE_FLAGS.HOGQL_INSIGHTS]
)

try {
if (isPersonsNode(queryNode)) {
response = await api.get(getPersonsEndpoint(queryNode), methodOptions)
} else if (isInsightQueryNode(queryNode)) {
} else if (isInsightQueryNode(queryNode) && !(hogQLInsightsFlagEnabled && isLifecycleQuery(queryNode))) {
const filters = queryNodeToFilter(queryNode)
const params = {
...filters,
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,9 @@
],
"description": "Property filters for all series"
},
"response": {
"$ref": "#/definitions/LifecycleQueryResponse"
},
"samplingFactor": {
"description": "Sampling rate",
"type": ["number", "null"]
Expand All @@ -1433,6 +1436,25 @@
"required": ["kind", "series"],
"type": "object"
},
"LifecycleQueryResponse": {
"additionalProperties": false,
"properties": {
"result": {
"items": {
"type": "object"
},
"type": "array"
},
"timings": {
"items": {
"$ref": "#/definitions/QueryTiming"
},
"type": "array"
}
},
"required": ["result"],
"type": "object"
},
"LifecycleToggle": {
"enum": ["new", "resurrecting", "returning", "dormant"],
"type": "string"
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,11 @@ export type LifecycleFilter = Omit<LifecycleFilterType, keyof FilterType> & {
toggledLifecycles?: LifecycleToggle[]
} // using everything except what it inherits from FilterType

export interface LifecycleQueryResponse {
result: Record<string, any>[]
timings?: QueryTiming[]
}

export interface LifecycleQuery extends InsightsQueryBase {
kind: NodeKind.LifecycleQuery
/** Granularity of the response. Can be one of `hour`, `day`, `week` or `month` */
Expand All @@ -448,6 +453,7 @@ export interface LifecycleQuery extends InsightsQueryBase {
series: (EventsNode | ActionsNode)[]
/** Properties specific to the lifecycle insight */
lifecycleFilter?: LifecycleFilter
response?: LifecycleQueryResponse
}

export type InsightQueryNode =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const REGULAR_FEATURE_FLAG: FeatureFlagType = {
performed_rollback: false,
can_edit: true,
tags: [],
surveys: [],
}

const GROUP_FEATURE_FLAG: FeatureFlagType = {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/feature-flags/activityDescriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const featureFlagActionsMapping: Record<
can_edit: () => null,
analytics_dashboards: () => null,
has_enriched_analytics: () => null,
surveys: () => null,
}

export function flagActivityDescriber(logItem: ActivityLogItem, asNotification?: boolean): HumanizedChange {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/scenes/feature-flags/featureFlagLogic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function generateFeatureFlag(
usage_dashboard: 1234,
tags: [],
has_enriched_analytics,
surveys: [],
}
}

Expand Down
Loading

0 comments on commit a501070

Please sign in to comment.