Skip to content

Commit

Permalink
Merge branch 'master' into dark-mode-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes committed Mar 26, 2024
2 parents c39d61d + 822cebc commit 6cea5cf
Show file tree
Hide file tree
Showing 27 changed files with 444 additions and 142 deletions.
34 changes: 23 additions & 11 deletions cypress/e2e/trends.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Trends', () => {
cy.get('[data-attr=trend-element-subject-1]').click()
cy.get('[data-attr=taxonomic-tab-actions]').click()
cy.get('[data-attr=taxonomic-filter-searchfield]').click().type('home')
cy.contains('Hogflix homepage view').click({ force: true })
cy.contains('Hogflix homepage view').click()

// then
cy.get('[data-attr=trend-line-graph]').should('exist')
Expand Down Expand Up @@ -66,15 +66,15 @@ describe('Trends', () => {
it('Apply specific filter on default pageview event', () => {
cy.get('[data-attr=trend-element-subject-0]').click()
cy.get('[data-attr=taxonomic-filter-searchfield]').click().type('Pageview')
cy.get('.taxonomic-infinite-list').find('.taxonomic-list-row').contains('Pageview').click({ force: true })
cy.get('.taxonomic-infinite-list').find('.taxonomic-list-row').contains('Pageview').click()
cy.get('[data-attr=trend-element-subject-0]').should('have.text', 'Pageview')

// Apply a property filter
cy.get('[data-attr=show-prop-filter-0]').click()
cy.get('[data-attr=property-select-toggle-0]').click()
cy.get('[data-attr=prop-filter-event_properties-1]').click({ force: true })
cy.get('[data-attr=prop-filter-event_properties-1]').click()

cy.get('[data-attr=prop-val]').click({ force: true })
cy.get('[data-attr=prop-val]').click()
// cypress is odd and even though when a human clicks this the right dropdown opens
// in the test that doesn't happen
cy.get('body').then(($body) => {
Expand All @@ -88,22 +88,22 @@ describe('Trends', () => {
it('Apply 1 overall filter', () => {
cy.get('[data-attr=trend-element-subject-0]').click()
cy.get('[data-attr=taxonomic-filter-searchfield]').click().type('Pageview')
cy.get('.taxonomic-infinite-list').find('.taxonomic-list-row').contains('Pageview').click({ force: true })
cy.get('.taxonomic-infinite-list').find('.taxonomic-list-row').contains('Pageview').click()
cy.get('[data-attr=trend-element-subject-0]').should('have.text', 'Pageview')

cy.get('[data-attr$=add-filter-group]').click()
cy.get('[data-attr=property-select-toggle-0]').click()
cy.get('[data-attr=taxonomic-filter-searchfield]').click()
cy.get('[data-attr=prop-filter-event_properties-1]').click({ force: true })
cy.get('[data-attr=prop-val]').click({ force: true })
cy.get('[data-attr=prop-filter-event_properties-1]').click()
cy.get('[data-attr=prop-val]').click()
// cypress is odd and even though when a human clicks this the right dropdown opens
// in the test that doesn't happen
cy.get('body').then(($body) => {
if ($body.find('[data-attr=prop-val-0]').length === 0) {
cy.get('[data-attr=taxonomic-value-select]').click()
}
})
cy.get('[data-attr=prop-val-0]').click({ force: true })
cy.get('[data-attr=prop-val-0]').click()

cy.get('[data-attr=trend-line-graph]', { timeout: 8000 }).should('exist')
})
Expand All @@ -117,14 +117,14 @@ describe('Trends', () => {

it('Apply pie filter', () => {
cy.get('[data-attr=chart-filter]').click()
cy.get('.Popover').find('.LemonButton').contains('Pie').click({ force: true })
cy.get('.Popover').find('.LemonButton').contains('Pie').click()

cy.get('[data-attr=trend-pie-graph]').should('exist')
})

it('Apply table filter', () => {
cy.get('[data-attr=chart-filter]').click()
cy.get('.Popover').find('.LemonButton').contains('Table').click({ force: true })
cy.get('.Popover').find('.LemonButton').contains('Table').click()

cy.get('[data-attr=insights-table-graph]').should('exist')

Expand All @@ -144,7 +144,7 @@ describe('Trends', () => {

it('Apply property breakdown', () => {
cy.get('[data-attr=add-breakdown-button]').click()
cy.get('[data-attr=prop-filter-event_properties-1]').click({ force: true })
cy.get('[data-attr=prop-filter-event_properties-1]').click()
cy.get('[data-attr=trend-line-graph]').should('exist')
})

Expand All @@ -154,4 +154,16 @@ describe('Trends', () => {
cy.contains('All Users*').click()
cy.get('[data-attr=trend-line-graph]').should('exist')
})

it('Show warning on MAU math in total value insight', () => {
cy.get('[data-attr=chart-filter]').click()
cy.get('.Popover').find('.LemonButton').contains('Pie').click()
cy.get('[data-attr=trend-pie-graph]').should('exist') // Make sure the pie chart is loaded before proceeding

cy.get('[data-attr=math-selector-0]').click()
cy.get('[data-attr=math-monthly_active-0] .LemonIcon').should('exist') // This should be the warning icon

cy.get('[data-attr=math-monthly_active-0]').trigger('mouseenter') // Activate warning tooltip
cy.get('.Tooltip').contains('we recommend using "Unique users" here instead').should('exist')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { actions, connect, events, kea, listeners, path, reducers, selectors } f
import { loaders } from 'kea-loaders'
import { router } from 'kea-router'
import api from 'lib/api'
import { reverseProxyCheckerLogic } from 'lib/components/ReverseProxyChecker/reverseProxyCheckerLogic'
import { permanentlyMount } from 'lib/utils/kea-logic-builders'
import posthog from 'posthog-js'
import { membersLogic } from 'scenes/organization/membersLogic'
Expand Down Expand Up @@ -58,6 +59,8 @@ export const activationLogic = kea<activationLogicType>([
['insights'],
dashboardsModel,
['rawDashboards'],
reverseProxyCheckerLogic,
['hasReverseProxy'],
],
actions: [
inviteLogic,
Expand Down Expand Up @@ -193,6 +196,7 @@ export const activationLogic = kea<activationLogicType>([
s.customEventsCount,
s.installedPlugins,
s.currentTeamSkippedTasks,
s.hasReverseProxy,
],
(
currentTeam,
Expand All @@ -202,7 +206,8 @@ export const activationLogic = kea<activationLogicType>([
dashboards,
customEventsCount,
installedPlugins,
skippedTasks
skippedTasks,
hasReverseProxy
) => {
const tasks: ActivationTaskType[] = []
for (const task of Object.values(ActivationTasks)) {
Expand Down Expand Up @@ -286,7 +291,7 @@ export const activationLogic = kea<activationLogicType>([
id: ActivationTasks.SetUpReverseProxy,
name: 'Set up a reverse proxy',
description: 'Send your events from your own domain to avoid tracking blockers',
completed: false,
completed: hasReverseProxy || false,
canSkip: true,
skipped: skippedTasks.includes(ActivationTasks.SetUpReverseProxy),
url: 'https://posthog.com/docs/advanced/proxy',
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/lib/components/CustomerLogo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
interface CustomerProps {
image: string
alt: string
className?: string
}

interface LogoProps {
src: string
alt: string
className?: string
}

const Logo = ({ src, alt, className = '' }: LogoProps): JSX.Element => (
<img className={`bg-transparent w-full px-3 py-3 h-10 ${className}`} src={src} alt={alt} />
)

export const CustomerLogo = ({ image, alt, className = '' }: CustomerProps): JSX.Element => {
return (
<li className="flex items-center justify-center w-full">
<Logo className={className} src={image} alt={alt} />
</li>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expectLogic } from 'kea-test-utils'

import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'

import { reverseProxyCheckerLogic } from './reverseProxyCheckerLogic'

const hasReverseProxyValues = [['https://proxy.example.com'], [null]]
const doesNotHaveReverseProxyValues = [[null], [null]]

const useMockedValues = (results: (string | null)[][]): void => {
useMocks({
post: {
'/api/projects/:team/query': () => [
200,
{
results,
},
],
},
})
}

describe('reverseProxyCheckerLogic', () => {
let logic: ReturnType<typeof reverseProxyCheckerLogic.build>

beforeEach(() => {
initKeaTests()
localStorage.clear()
logic = reverseProxyCheckerLogic()
})

afterEach(() => {
logic.unmount()
})

it('should not have a reverse proxy set - when no data', async () => {
useMockedValues([])

logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({
hasReverseProxy: false,
})
})

it('should not have a reverse proxy set - when data with no lib_custom_api_host values', async () => {
useMockedValues(doesNotHaveReverseProxyValues)

logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({
hasReverseProxy: false,
})
})

it('should have a reverse proxy set', async () => {
useMockedValues(hasReverseProxyValues)

logic.mount()
await expectLogic(logic).toFinishAllListeners().toMatchValues({
hasReverseProxy: true,
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { afterMount, kea, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
import api from 'lib/api'

import { HogQLQuery, NodeKind } from '~/queries/schema'
import { hogql } from '~/queries/utils'

import type { reverseProxyCheckerLogicType } from './reverseProxyCheckerLogicType'

const CHECK_INTERVAL_MS = 1000 * 60 * 60 // 1 hour

export const reverseProxyCheckerLogic = kea<reverseProxyCheckerLogicType>([
path(['components', 'ReverseProxyChecker', 'reverseProxyCheckerLogic']),
loaders({
hasReverseProxy: [
false as boolean | null,
{
loadHasReverseProxy: async () => {
const query: HogQLQuery = {
kind: NodeKind.HogQLQuery,
query: hogql`SELECT properties.$lib_custom_api_host AS lib_custom_api_host
FROM events
WHERE timestamp >= now() - INTERVAL 1 DAY
AND timestamp <= now()
ORDER BY timestamp DESC
limit 10`,
}

const res = await api.query(query)
return !!res.results?.find((x) => !!x[0])
},
},
],
}),
reducers({
lastCheckedTimestamp: [
0,
{ persist: true },
{
loadHasReverseProxySuccess: () => Date.now(),
},
],
}),
afterMount(({ actions, values }) => {
if (values.lastCheckedTimestamp < Date.now() - CHECK_INTERVAL_MS) {
actions.loadHasReverseProxy()
}
}),
])
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { hogql } from '~/queries/utils'

import type { versionCheckerLogicType } from './versionCheckerLogicType'

const CHECK_INTERVAL_MS = 1000 * 60 * 60 // 6 hour
const CHECK_INTERVAL_MS = 1000 * 60 * 60 * 6 // 6 hour

export type SDKVersion = {
version: string
Expand Down
28 changes: 18 additions & 10 deletions frontend/src/lib/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { LemonSelectOptions } from '@posthog/lemon-ui'

import { ChartDisplayType, Region, SSOProvider } from '../types'
import { ChartDisplayCategory, ChartDisplayType, Region, SSOProvider } from '../types'

// Sync with backend DISPLAY_TYPES_TO_CATEGORIES
export const DISPLAY_TYPES_TO_CATEGORIES: Record<ChartDisplayType, ChartDisplayCategory> = {
[ChartDisplayType.ActionsLineGraph]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsBar]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsAreaGraph]: ChartDisplayCategory.TimeSeries,
[ChartDisplayType.ActionsLineGraphCumulative]: ChartDisplayCategory.CumulativeTimeSeries,
[ChartDisplayType.BoldNumber]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.ActionsPie]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.ActionsBarValue]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.ActionsTable]: ChartDisplayCategory.TotalValue,
[ChartDisplayType.WorldMap]: ChartDisplayCategory.TotalValue,
}
export const NON_TIME_SERIES_DISPLAY_TYPES = Object.entries(DISPLAY_TYPES_TO_CATEGORIES)
.filter(([, category]) => category === ChartDisplayCategory.TotalValue)
.map(([displayType]) => displayType as ChartDisplayType)

/** Display types which don't allow grouping by unit of time. Sync with backend NON_TIME_SERIES_DISPLAY_TYPES. */
export const NON_TIME_SERIES_DISPLAY_TYPES = [
ChartDisplayType.ActionsTable,
ChartDisplayType.ActionsPie,
ChartDisplayType.ActionsBarValue,
ChartDisplayType.WorldMap,
ChartDisplayType.BoldNumber,
]
/** Display types for which `breakdown` is hidden and ignored. Sync with backend NON_BREAKDOWN_DISPLAY_TYPES. */
export const NON_BREAKDOWN_DISPLAY_TYPES = [ChartDisplayType.BoldNumber]
/** Display types which only work with a single series. */
Expand Down Expand Up @@ -149,7 +157,7 @@ export const FEATURE_FLAGS = {
POSTHOG_3000_NAV: 'posthog-3000-nav', // owner: @Twixes
HEDGEHOG_MODE: 'hedgehog-mode', // owner: @benjackwhite
HEDGEHOG_MODE_DEBUG: 'hedgehog-mode-debug', // owner: @benjackwhite
GENERIC_SIGNUP_BENEFITS: 'generic-signup-benefits', // experiment, owner: @raquelmsmith
SIGNUP_BENEFITS: 'signup-benefits', // experiment, owner: @zlwaterfield
WEB_ANALYTICS: 'web-analytics', // owner @robbie-c #team-web-analytics
WEB_ANALYTICS_SAMPLING: 'web-analytics-sampling', // owner @robbie-c #team-web-analytics
HIGH_FREQUENCY_BATCH_EXPORTS: 'high-frequency-batch-exports', // owner: @tomasfarias
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/customers/airbus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/src/lib/customers/hasura.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 6cea5cf

Please sign in to comment.