Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(projects): keep my tickets open while a project is pending deletion (#115715)

Ben Lea09d8fbcd95e2
diff --git a/frontend/src/layout/navigation-3000/Navigation.tsx b/frontend/src/layout/navigation-3000/Navigation.tsx
index 08975b2ed780..d2c2b1d91f08 100644
--- a/frontend/src/layout/navigation-3000/Navigation.tsx
+++ b/frontend/src/layout/navigation-3000/Navigation.tsx
@@ -143,7 +143,9 @@ export function Navigation({
? 'p-4'
: mode === 'embedded'
? '@container/main-content min-h-screen p-4'
- : undefined
+ : mode === 'minimal' && sceneConfig?.layout !== 'plain'
+ ? '@container/main-content flex flex-col p-4'
+ : undefined
}
>
{children}
diff --git a/frontend/src/layout/navigation-3000/navigationLogic.test.ts b/frontend/src/layout/navigation-3000/navigationLogic.test.ts
new file mode 100644
index 000000000000..9181d286eab3
--- /dev/null
+++ b/frontend/src/layout/navigation-3000/navigationLogic.test.ts
@@ -0,0 +1,32 @@
+import { MOCK_DEFAULT_PROJECT } from 'lib/api.mock'
+
+import { router } from 'kea-router'
+import { expectLogic } from 'kea-test-utils'
+
+import { projectLogic } from 'scenes/projectLogic'
+import { urls } from 'scenes/urls'
+
+import { initKeaTests } from '~/test/init'
+
+import { navigation3000Logic } from './navigationLogic'
+
+describe('navigation3000Logic', () => {
+ it.each([
+ [false, 'full'],
+ [true, 'minimal'],
+ ])('on my tickets, a project with is_pending_deletion=%s shows %s navigation', async (isPendingDeletion, mode) => {
+ initKeaTests()
+ router.actions.push(urls.myTickets())
+ projectLogic.mount()
+ const logic = navigation3000Logic()
+ logic.mount()
+
+ projectLogic.actions.loadCurrentProjectSuccess({
+ ...MOCK_DEFAULT_PROJECT,
+ is_pending_deletion: isPendingDeletion,
+ })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.mode).toEqual(mode)
+ })
+})
diff --git a/frontend/src/layout/navigation-3000/navigationLogic.tsx b/frontend/src/layout/navigation-3000/navigationLogic.tsx
index d1a5a3399409..aeddab0125a5 100644
--- a/frontend/src/layout/navigation-3000/navigationLogic.tsx
+++ b/frontend/src/layout/navigation-3000/navigationLogic.tsx
@@ -8,10 +8,12 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { isEmbeddedPageFrame } from 'lib/utils/embeddedPageFrame'
import { onboardingVariantChrome, resolveOnboardingFlowVariant } from 'scenes/onboarding/onboardingVariants'
import { organizationLogic } from 'scenes/organizationLogic'
+import { projectLogic } from 'scenes/projectLogic'
import { sceneLogic } from 'scenes/sceneLogic'
import { Scene } from 'scenes/sceneTypes'
import type { SceneConfig } from '../../scenes/sceneTypes'
+import type { ProjectType } from '../../types'
import { navigationLogic } from '../navigation/navigationLogic'
export type Navigation3000Mode = 'none' | 'minimal' | 'zen' | 'embedded' | 'full'
@@ -22,6 +24,7 @@ export type ZenModeTrigger = 'shortcut' | 'account_menu' | 'help_menu' | 'exit_b
export interface navigation3000LogicValues {
mobileLayout: boolean // navigationLogic
isCurrentOrganizationUnavailable: boolean // organizationLogic
+ currentProject: ProjectType | null // projectLogic
activeSceneId: string | null // sceneLogic
sceneConfig: SceneConfig | null // sceneLogic
mode: Navigation3000Mode
@@ -50,6 +53,7 @@ export interface navigation3000LogicMeta {
mode: (
sceneConfig: SceneConfig | null,
isCurrentOrganizationUnavailable: boolean,
+ currentProject: ProjectType | null,
zenMode: boolean,
activeSceneId: string | null,
featureFlags: import('lib/logic/featureFlagLogic').FeatureFlagsSet
@@ -74,6 +78,8 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
['mobileLayout'],
organizationLogic,
['isCurrentOrganizationUnavailable'],
+ projectLogic,
+ ['currentProject'],
],
})),
actions({
@@ -110,6 +116,7 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
(s) => [
s.sceneConfig,
s.isCurrentOrganizationUnavailable,
+ s.currentProject,
s.zenMode,
s.activeSceneId,
featureFlagLogic.selectors.featureFlags,
@@ -117,6 +124,7 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
(
sceneConfig: null | import('scenes/sceneTypes').SceneConfig,
isCurrentOrganizationUnavailable: boolean,
+ currentProject: import('~/types').ProjectType | null,
zenMode: boolean,
activeSceneId: string | null,
featureFlags: import('lib/logic/featureFlagLogic').FeatureFlagsSet
@@ -128,7 +136,8 @@ export const navigation3000Logic = kea<navigation3000LogicType>([
if (zenMode) {
return 'zen'
}
- if (isCurrentOrganizationUnavailable) {
+ // My tickets stays open on a project pending deletion, so hide the links into the rest of the app.
+ if (isCurrentOrganizationUnavailable || currentProject?.is_pending_deletion) {
return 'minimal'
}
if (sceneConfig?.layout === 'plain' && !sceneConfig.allowUnauthenticated) {
diff --git a/frontend/src/scenes/projectLogic.test.ts b/frontend/src/scenes/projectLogic.test.ts
index 6ebe82cb41cd..7387aaa66ac7 100644
--- a/frontend/src/scenes/projectLogic.test.ts
+++ b/frontend/src/scenes/projectLogic.test.ts
@@ -1,5 +1,6 @@
import { MOCK_DEFAULT_PROJECT, MOCK_ORGANIZATION_ID } from 'lib/api.mock'
+import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
import posthog from 'posthog-js'
@@ -62,4 +63,19 @@ describe('projectLogic', () => {
expect(requestedOrganizationIds).toEqual([MOCK_ORGANIZATION_ID])
})
+
+ it.each([
+ ['/project/997/insights', false],
+ ['/project/997/my-tickets', true],
+ ])('on a project pending deletion, %s stays open: %s', async (path, staysOpen) => {
+ initKeaTests()
+ router.actions.push(path)
+ const logic = projectLogic()
+ logic.mount()
+
+ logic.actions.loadCurrentProjectSuccess({ ...MOCK_DEFAULT_PROJECT, is_pending_deletion: true })
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(router.values.location.pathname === path).toBe(staysOpen)
+ })
})
diff --git a/frontend/src/scenes/projectLogic.ts b/frontend/src/scenes/projectLogic.ts
index f52f1cfb1488..dcc0039f9d79 100644
--- a/frontend/src/scenes/projectLogic.ts
+++ b/frontend/src/scenes/projectLogic.ts
@@ -7,6 +7,7 @@ import api, { ApiConfig } from 'lib/api'
import { lemonToast } from 'lib/lemon-ui/LemonToast'
import { isUserLoggedIn } from 'lib/utils/getAppContext'
import { getAppContext } from 'lib/utils/getAppContext'
+import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { identifierToHuman } from 'lib/utils/strings'
import { organizationsProjectsCancelDeletionCreate } from '~/generated/core/api'
@@ -20,6 +21,12 @@ import { userLogic } from './userLogic'
const CREATE_PROJECT_TIMEOUT_MS = 60_000
+export function isPathOpenWhileProjectPendingDeletion(pathname: string): boolean {
+ // projectBased scenes are served under a /project/:id prefix, so match the lockout path by suffix.
+ // Tickets load from PostHog's support project, not this one, and reply emails link to them.
+ return pathname.endsWith(urls.projectPendingDeletion()) || removeProjectIdIfPresent(pathname) === urls.myTickets()
+}
+
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface projectLogicValues {
currentOrganizationId: string // organizationLogic
@@ -339,9 +346,8 @@ export const projectLogic = kea<projectLogicType>([
actions.guardPendingDeletion(pathname, values.currentProject?.is_pending_deletion)
},
guardPendingDeletion: ({ pathname, isPendingDeletion }) => {
- // projectBased scenes are served under a /project/:id prefix, so match the lockout path by suffix.
const onLockoutScreen = pathname.endsWith(urls.projectPendingDeletion())
- if (isPendingDeletion && !onLockoutScreen) {
+ if (isPendingDeletion && !isPathOpenWhileProjectPendingDeletion(pathname)) {
router.actions.replace(urls.projectPendingDeletion())
} else if (!isPendingDeletion && onLockoutScreen) {
// Reached the lockout screen for a project that isn't being deleted (e.g. switched projects) — send home
diff --git a/frontend/src/scenes/sceneLogic.test.tsx b/frontend/src/scenes/sceneLogic.test.tsx
index 96236a431053..7b8a2c8fc004 100644
--- a/frontend/src/scenes/sceneLogic.test.tsx
+++ b/frontend/src/scenes/sceneLogic.test.tsx
@@ -64,6 +64,8 @@ const testScenes: Record<string, () => any> = {
[Scene.OrganizationPendingDeletion]: sceneImport,
[Scene.PasswordResetComplete]: sceneImport,
[Scene.ProjectCreateFirst]: sceneImport,
+ [Scene.ProjectPendingDeletion]: sceneImport,
+ MyTickets: sceneImport,
[Scene.Settings]: sceneImport,
Inbox: sceneImport,
ScoutTrials: sceneImport,
@@ -811,6 +813,48 @@ describe('sceneLogic', () => {
)
})
+ describe('a project pending deletion', () => {
+ it.each([
+ [
+ 'locks out a page reached by a client-side link',
+ urls.eventDefinitions(),
+ urls.projectPendingDeletion(),
+ Scene.ProjectPendingDeletion,
+ ],
+ [
+ 'locks out an unknown path reached by a client-side link',
+ '/no-such-page',
+ urls.projectPendingDeletion(),
+ Scene.ProjectPendingDeletion,
+ ],
+ ['keeps my tickets open', urls.myTickets(), urls.myTickets(), 'MyTickets'],
+ [
+ 'keeps my tickets open when the project has not finished onboarding',
+ urls.myTickets(),
+ urls.myTickets(),
+ 'MyTickets',
+ { ingested_event: false, completed_snippet_onboarding: false, has_completed_onboarding_for: {} },
+ ],
+ ])('%s', async (_name, target, expectedRoute, expectedScene, team: Partial<TeamType> = {}) => {
+ logic.unmount()
+ initKeaTests(
+ true,
+ { ...MOCK_DEFAULT_TEAM, ...team },
+ { ...MOCK_DEFAULT_PROJECT, is_pending_deletion: true }
+ )
+ await expectLogic(teamLogic).toDispatchActions(['loadCurrentTeamSuccess'])
+ featureFlagLogic.mount()
+ logic = sceneLogic.build({ scenes: testScenes })
+ logic.mount()
+
+ router.actions.push(target)
+ await expectLogic(logic).delay(1)
+
+ expect(removeProjectIdIfPresent(router.values.location.pathname)).toEqual(expectedRoute)
+ expect(logic.values.sceneId).toEqual(expectedScene)
+ })
+ })
+
describe('a blocked organization', () => {
let priorAppContext: AppContext | undefined
diff --git a/frontend/src/scenes/sceneLogic.tsx b/frontend/src/scenes/sceneLogic.tsx
index 816b88a0659c..2f5fbfc4a7c1 100644
--- a/frontend/src/scenes/sceneLogic.tsx
+++ b/frontend/src/scenes/sceneLogic.tsx
@@ -59,6 +59,7 @@ import { parseCouponCampaign } from './coupons/utils'
import { isOnboardingRedirectSuppressed } from './onboarding/legacy/onboardingDelegationState'
import { organizationLogic } from './organizationLogic'
import { preflightLogic } from './PreflightCheck/preflightLogic'
+import { isPathOpenWhileProjectPendingDeletion, projectLogic } from './projectLogic'
import type { SceneProps } from './sceneTypes'
import { inviteLogic } from './settings/organization/inviteLogic'
import { teamLogic } from './teamLogic'
@@ -934,6 +935,16 @@ export const sceneLogic = kea<sceneLogicType>([
return
}
+ if (projectLogic.findMounted()?.values.currentProject?.is_pending_deletion) {
+ // Same reasons as the organization block above, including skipping the onboarding redirects.
+ if (isPathOpenWhileProjectPendingDeletion(router.values.location.pathname)) {
+ actions.loadScene(sceneId, sceneKey, params, method)
+ } else {
+ router.actions.replace(urls.projectPendingDeletion())
+ }
+ return
+ }
+
if (sceneId === Scene.OrganizationDeactivated || sceneId === Scene.OrganizationPendingDeletion) {
// The organization is open again, so let the member back in, as the server does. The server
// only matches the bare block path, and the router writes it with a `/project/<id>` prefix.
@@ -1203,10 +1214,14 @@ export const sceneLogic = kea<sceneLogicType>([
}
mapping['/*'] = (_, __, { method }) => {
- // This route skips `openScene`, so it applies the organization block itself, as the server does.
+ // This route skips `openScene`, so it applies the organization block and the project lockout itself.
if (leaveBlockedOrganizationPath()) {
return
}
+ if (projectLogic.findMounted()?.values.currentProject?.is_pending_deletion) {
+ router.actions.replace(urls.projectPendingDeletion())
+ return
+ }
return actions.loadScene(Scene.Error404, undefined, emptySceneParams, method)
}