Skip to content

Commit

Permalink
feat: Added linking for feature preview modal/panel (#18599)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Nov 14, 2023
1 parent 2bb378b commit c103a60
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
22 changes: 22 additions & 0 deletions frontend/src/layout/FeaturePreviews/featurePreviewsLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { supportLogic } from 'lib/components/Support/supportLogic'
import { userLogic } from 'scenes/userLogic'
import { FEATURE_FLAGS, FeatureFlagKey } from 'lib/constants'
import type { featurePreviewsLogicType } from './featurePreviewsLogicType'
import { actionToUrl, router, urlToAction } from 'kea-router'

/** Features that can only be toggled if you fall under the `${flagKey}-preview` flag */
export const CONSTRAINED_PREVIEWS: Set<FeatureFlagKey> = new Set([FEATURE_FLAGS.POSTHOG_3000])
Expand Down Expand Up @@ -107,4 +108,25 @@ export const featurePreviewsLogic = kea<featurePreviewsLogicType>([
}),
],
}),
urlToAction(({ actions }) => ({
'*': (_, _search, hashParams) => {
if (hashParams['panel'] === 'feature-previews') {
actions.showFeaturePreviewsModal()
}
},
})),
actionToUrl(() => {
return {
showFeaturePreviewsModal: () => {
const hashParams = router.values.hashParams
hashParams['panel'] = 'feature-previews'
return [router.values.location.pathname, router.values.searchParams, hashParams]
},
hideFeaturePreviewsModal: () => {
const hashParams = router.values.hashParams
delete hashParams['panel']
return [router.values.location.pathname, router.values.searchParams, hashParams]
},
}
}),
])
21 changes: 18 additions & 3 deletions frontend/src/lib/components/Support/supportLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,21 @@ export const supportLogic = kea<supportLogicType>([

urlToAction(({ actions, values }) => ({
'*': (_, _search, hashParams) => {
if ('supportModal' in hashParams && !values.isSupportFormOpen) {
if (values.isSupportFormOpen) {
return
}

// Legacy supportModal param
if ('supportModal' in hashParams) {
const [kind, area] = (hashParams['supportModal'] || '').split(':')

actions.openSupportForm(
Object.keys(SUPPORT_KIND_TO_SUBJECT).includes(kind) ? kind : null,
Object.keys(TARGET_AREA_TO_NAME).includes(area) ? area : null
)
} else if ((hashParams['panel'] as string | undefined)?.startsWith('support')) {
const [kind, area] = hashParams['panel'].split(':').slice(1)

actions.openSupportForm(
Object.keys(SUPPORT_KIND_TO_SUBJECT).includes(kind) ? kind : null,
Object.keys(TARGET_AREA_TO_NAME).includes(area) ? area : null
Expand All @@ -322,7 +334,8 @@ export const supportLogic = kea<supportLogicType>([
actionToUrl(({ values }) => {
const updateUrl = (): any => {
const hashParams = router.values.hashParams
hashParams['supportModal'] = `${values.sendSupportRequest.kind || ''}:${
delete hashParams['supportModal'] // legacy value
hashParams['panel'] = `support:${values.sendSupportRequest.kind || ''}:${
values.sendSupportRequest.target_area || ''
}`
return [router.values.location.pathname, router.values.searchParams, hashParams]
Expand All @@ -332,7 +345,9 @@ export const supportLogic = kea<supportLogicType>([
setSendSupportRequestValue: () => updateUrl(),
closeSupportForm: () => {
const hashParams = router.values.hashParams
delete hashParams['supportModal']
delete hashParams['supportModal'] // legacy value
delete hashParams['panel']

return [router.values.location.pathname, router.values.searchParams, hashParams]
},
}
Expand Down

0 comments on commit c103a60

Please sign in to comment.