Skip to content

Commit

Permalink
fix(environments): Rejig use of insight/dashboard endpoints (PostHog#…
Browse files Browse the repository at this point in the history
…25469)

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Twixes and github-actions[bot] authored Oct 16, 2024
1 parent cd386bd commit d1c75ab
Show file tree
Hide file tree
Showing 128 changed files with 629 additions and 417 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/copy-clickhouse-udfs.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: Trigger UDFs Workflow

on:
push:
branches:
- master
paths:
- 'posthog/user_scripts/**'
push:
branches:
- master
paths:
- 'posthog/user_scripts/**'

jobs:
trigger_udfs_workflow:
runs-on: ubuntu-latest
steps:
- name: Trigger UDFs Workflow
uses: benc-uk/workflow-dispatch@v1
with:
workflow: .github/workflows/clickhouse-udfs.yml
repo: posthog/posthog-cloud-infra
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
ref: refs/heads/main

trigger_udfs_workflow:
runs-on: ubuntu-latest
steps:
- name: Trigger UDFs Workflow
uses: benc-uk/workflow-dispatch@v1
with:
workflow: .github/workflows/clickhouse-udfs.yml
repo: posthog/posthog-cloud-infra
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
ref: refs/heads/main
2 changes: 2 additions & 0 deletions .storybook/decorators/withKea/kea-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { worker } from '~/mocks/browser'
import { teamLogic } from 'scenes/teamLogic'
import { userLogic } from 'scenes/userLogic'
import { projectLogic } from 'scenes/projectLogic'

export function resetKeaStory(): void {
worker.resetHandlers()
Expand All @@ -18,6 +19,7 @@ export function resetKeaStory(): void {
initKea({ routerLocation: history.location, routerHistory: history })
featureFlagLogic.mount()
teamLogic.mount()
projectLogic.mount()
userLogic.mount()
router.mount()
const { store } = getContext()
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/dashboard-duplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('duplicating dashboards', () => {
let dashboardName, insightName, expectedCopiedDashboardName, expectedCopiedInsightName

beforeEach(() => {
cy.intercept('POST', /\/api\/projects\/\d+\/dashboards/).as('createDashboard')
cy.intercept('POST', /\/api\/environments\/\d+\/dashboards/).as('createDashboard')

dashboardName = randomString('dashboard-')
expectedCopiedDashboardName = `${dashboardName} (Copy)`
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/dashboard-shared.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { dashboards } from '../productAnalytics'

describe('Shared dashboard', () => {
beforeEach(() => {
cy.intercept('GET', /api\/projects\/\d+\/insights\/\?.*/).as('loadInsightList')
cy.intercept('PATCH', /api\/projects\/\d+\/insights\/\d+\/.*/).as('patchInsight')
cy.intercept('POST', /\/api\/projects\/\d+\/dashboards/).as('createDashboard')
cy.intercept('GET', /api\/environments\/\d+\/insights\/\?.*/).as('loadInsightList')
cy.intercept('PATCH', /api\/environments\/\d+\/insights\/\d+\/.*/).as('patchInsight')
cy.intercept('POST', /\/api\/environments\/\d+\/dashboards/).as('createDashboard')
cy.useSubscriptionStatus('unsubscribed')

cy.clickNavMenu('dashboards')
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { randomString } from '../support/random'

describe('Dashboard', () => {
beforeEach(() => {
cy.intercept('GET', /api\/projects\/\d+\/insights\/\?.*/).as('loadInsightList')
cy.intercept('PATCH', /api\/projects\/\d+\/insights\/\d+\/.*/).as('patchInsight')
cy.intercept('POST', /\/api\/projects\/\d+\/dashboards/).as('createDashboard')
cy.intercept('GET', /api\/environments\/\d+\/insights\/\?.*/).as('loadInsightList')
cy.intercept('PATCH', /api\/environments\/\d+\/insights\/\d+\/.*/).as('patchInsight')
cy.intercept('POST', /\/api\/environments\/\d+\/dashboards/).as('createDashboard')

cy.clickNavMenu('dashboards')
cy.location('pathname').should('include', '/dashboard')
Expand Down Expand Up @@ -306,7 +306,7 @@ describe('Dashboard', () => {
})

it('Move dashboard item', () => {
cy.intercept('PATCH', /api\/projects\/\d+\/dashboards\/\d+\/move_tile.*/).as('moveTile')
cy.intercept('PATCH', /api\/environments\/\d+\/dashboards\/\d+\/move_tile.*/).as('moveTile')

const sourceDashboard = randomString('source-dashboard')
const targetDashboard = randomString('target-dashboard')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/insights-saved.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Insights - saved', () => {
})

it('If cache empty, initiate async refresh', () => {
cy.intercept('GET', /\/api\/projects\/\d+\/insights\/?\?[^/]*?refresh=async/).as('getInsightsRefreshAsync')
cy.intercept('GET', /\/api\/environments\/\d+\/insights\/?\?[^/]*?refresh=async/).as('getInsightsRefreshAsync')
let newInsightId: string
createInsight('saved insight').then((insightId) => {
newInsightId = insightId
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/insights.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('Insights', () => {
})

it('Create new insight and save and continue editing', () => {
cy.intercept('PATCH', /\/api\/projects\/\d+\/insights\/\d+\/?/).as('patchInsight')
cy.intercept('PATCH', /\/api\/environments\/\d+\/insights\/\d+\/?/).as('patchInsight')

const insightName = randomString('insight-name-')
createInsight(insightName)
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/notebooks.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { urls } from 'scenes/urls'
describe('Notebooks', () => {
beforeEach(() => {
cy.fixture('api/session-recordings/recordings.json').then((recordings) => {
cy.intercept('GET', /api\/projects\/\d+\/session_recordings\/?\?.*/, { body: recordings }).as(
cy.intercept('GET', /api\/environments\/\d+\/session_recordings\/?\?.*/, { body: recordings }).as(
'loadSessionRecordingsList'
)
})

cy.fixture('api/session-recordings/recording.json').then((recording) => {
cy.intercept('GET', /api\/projects\/\d+\/session_recordings\/.*\?.*/, { body: recording }).as(
cy.intercept('GET', /api\/environments\/\d+\/session_recordings\/.*\?.*/, { body: recording }).as(
'loadSessionRecording'
)
})
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/projectHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Project Homepage', () => {
beforeEach(() => {
cy.intercept('GET', /\/api\/projects\/\d+\/dashboards\/\d+\//).as('getDashboard')
cy.intercept('GET', /\/api\/environments\/\d+\/dashboards\/\d+\//).as('getDashboard')
cy.clickNavMenu('projecthomepage')
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/trends.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Trends', () => {
})

it('Can load a graph from a URL directly', () => {
cy.intercept('POST', /api\/projects\/\d+\/query\//).as('loadNewQueryInsight')
cy.intercept('POST', /api\/environments\/\d+\/query\//).as('loadNewQueryInsight')

// regression test, the graph wouldn't load when going directly to a URL
cy.visit(
Expand Down
8 changes: 4 additions & 4 deletions cypress/productAnalytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const insight = {
cy.url().should('not.include', '/new')
},
clickTab: (tabName: string): void => {
cy.intercept('POST', /api\/projects\/\d+\/query\//).as('loadNewQueryInsight')
cy.intercept('POST', /api\/environments\/\d+\/query\//).as('loadNewQueryInsight')

cy.get(`[data-attr="insight-${(tabName === 'PATHS' ? 'PATH' : tabName).toLowerCase()}-tab"]`).click()
if (tabName !== 'FUNNELS') {
Expand All @@ -51,7 +51,7 @@ export const insight = {
}
},
newInsight: (insightType: string = 'TRENDS'): void => {
cy.intercept('POST', /api\/projects\/\d+\/query\//).as('loadNewQueryInsight')
cy.intercept('POST', /api\/environments\/\d+\/query\//).as('loadNewQueryInsight')

if (insightType === 'JSON') {
cy.clickNavMenu('savedinsights')
Expand Down Expand Up @@ -86,7 +86,7 @@ export const insight = {
cy.url().should('not.include', '/new') // wait for insight to complete and update URL
},
addInsightToDashboard: (dashboardName: string, options: { visitAfterAdding: boolean }): void => {
cy.intercept('PATCH', /api\/projects\/\d+\/insights\/\d+\/.*/).as('patchInsight')
cy.intercept('PATCH', /api\/environments\/\d+\/insights\/\d+\/.*/).as('patchInsight')

cy.get('[data-attr="save-to-dashboard-button"]').click()
cy.get('[data-attr="dashboard-searchfield"]').type(dashboardName)
Expand Down Expand Up @@ -158,7 +158,7 @@ export const dashboards = {

export const dashboard = {
addInsightToEmptyDashboard: (insightName: string): void => {
cy.intercept('POST', /api\/projects\/\d+\/insights\//).as('postInsight')
cy.intercept('POST', /api\/environments\/\d+\/insights\//).as('postInsight')

cy.get('[data-attr=dashboard-add-graph-header]').contains('Add insight').click()
cy.get('[data-attr=toast-close-button]').click({ multiple: true })
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ beforeEach(() => {
req.reply({ statusCode: 404, body: 'Cypress forced 404' })
)

cy.intercept('GET', /\/api\/projects\/\d+\/insights\/?\?/).as('getInsights')
cy.intercept('GET', /\/api\/environments\/\d+\/insights\/?\?/).as('getInsights')

cy.request('POST', '/api/login/', {
email: '[email protected]',
Expand Down
12 changes: 10 additions & 2 deletions ee/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def extend_api_router() -> None:
projects_router,
organizations_router,
project_feature_flags_router,
project_dashboards_router,
environment_dashboards_router,
legacy_project_dashboards_router,
)

root_router.register(r"billing", billing.BillingViewset, "billing")
Expand Down Expand Up @@ -67,7 +68,14 @@ def extend_api_router() -> None:
"environment_explicit_members",
["team_id"],
)
project_dashboards_router.register(

environment_dashboards_router.register(
r"collaborators",
dashboard_collaborator.DashboardCollaboratorViewSet,
"environment_dashboard_collaborators",
["project_id", "dashboard_id"],
)
legacy_project_dashboards_router.register(
r"collaborators",
dashboard_collaborator.DashboardCollaboratorViewSet,
"project_dashboard_collaborators",
Expand Down
Binary file modified frontend/__snapshots__/scenes-app-max-ai--welcome--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-app-max-ai--welcome--light.png
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.
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.
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.
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/layout/navigation-3000/Navigation.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const meta: Meta = {
decorators: [
mswDecorator({
get: {
'/api/projects/:team_id/dashboards/': require('../../scenes/dashboard/__mocks__/dashboards.json'),
'/api/projects/:team_id/dashboards/1/': require('../../scenes/dashboard/__mocks__/dashboard1.json'),
'/api/projects/:team_id/dashboards/1/collaborators/': [],
'/api/projects/:team_id/insights/my_last_viewed/': require('../../scenes/saved-insights/__mocks__/insightsMyLastViewed.json'),
'/api/projects/:team_id/session_recordings/': EMPTY_PAGINATED_RESPONSE,
'/api/environments/:team_id/dashboards/': require('../../scenes/dashboard/__mocks__/dashboards.json'),
'/api/environments/:team_id/dashboards/1/': require('../../scenes/dashboard/__mocks__/dashboard1.json'),
'/api/environments/:team_id/dashboards/1/collaborators/': [],
'/api/environments/:team_id/insights/my_last_viewed/': require('../../scenes/saved-insights/__mocks__/insightsMyLastViewed.json'),
'/api/environments/:team_id/session_recordings/': EMPTY_PAGINATED_RESPONSE,
},
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const multipliedFeatureFlagsJson = {
export function Dashboards(): JSX.Element {
useStorybookMocks({
get: {
'/api/projects/:team_id/dashboards/': dashboardsJson,
'/api/environments/:team_id/dashboards/': dashboardsJson,
},
})
const { showSidebar } = useActions(navigation3000Logic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const meta: Meta = {
'/api/projects/:id/integrations': { results: [] },
},
post: {
'/api/projects/:team_id/query': {},
'/api/environments/:team_id/query': {},
},
}),
],
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('API helper', () => {
)

expect(fakeFetch).toHaveBeenCalledWith(
'/api/projects/2/events?properties=%5B%7B%22key%22%3A%22something%22%2C%22value%22%3A%22is_set%22%2C%22operator%22%3A%22is_set%22%2C%22type%22%3A%22event%22%7D%5D&limit=10&orderBy=%5B%22-timestamp%22%5D',
'/api/environments/2/events?properties=%5B%7B%22key%22%3A%22something%22%2C%22value%22%3A%22is_set%22%2C%22operator%22%3A%22is_set%22%2C%22type%22%3A%22event%22%7D%5D&limit=10&orderBy=%5B%22-timestamp%22%5D',
{
signal: undefined,
headers: {
Expand Down
Loading

0 comments on commit d1c75ab

Please sign in to comment.