Skip to content

Commit

Permalink
feat: Add support for opening bug report via URL (#15251)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Apr 26, 2023
1 parent d6d1bfe commit 503b15c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
39 changes: 36 additions & 3 deletions frontend/src/lib/components/Support/supportLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { supportLogicType } from './supportLogicType'
import { forms } from 'kea-forms'
import { UserType } from '~/types'
import { lemonToast } from 'lib/lemon-ui/lemonToast'
import { actionToUrl, router, urlToAction } from 'kea-router'

function getSessionReplayLink(): string {
const LOOK_BACK = 30
Expand Down Expand Up @@ -39,18 +40,19 @@ export const TargetAreaToName = {
experiments: 'Experiments',
feature_flags: 'Feature Flags',
login: 'Login / Sign up / Invites',
session_reply: 'Session Replay',
session_replay: 'Session Replay',
}
export type supportTicketTargetArea = keyof typeof TargetAreaToName | null
export type supportTicketKind = 'bug' | 'feedback' | null

export const URLPathToTargetArea: Record<string, supportTicketTargetArea> = {
insights: 'analytics',
recordings: 'session_reply',
recordings: 'session_replay',
replay: 'session_replay',
dashboard: 'analytics',
feature_flags: 'feature_flags',
experiments: 'experiments',
'web-performance': 'session_reply',
'web-performance': 'session_replay',
events: 'analytics',
'data-management': 'data_management',
cohorts: 'cohorts',
Expand Down Expand Up @@ -169,4 +171,35 @@ export const supportLogic = kea<supportLogicType>([
})
},
})),

urlToAction(({ actions, values }) => ({
'*': (_, _search, hashParams) => {
if ('supportModal' in hashParams && !values.isSupportFormOpen) {
const [kind, area] = (hashParams['supportModal'] || '').split(':')

actions.openSupportForm(
['bug', 'feedback'].includes(kind) ? kind : null,
Object.keys(TargetAreaToName).includes(area) ? area : null
)
}
},
})),
actionToUrl(({ values }) => {
const updateUrl = (): any => {
const hashParams = router.values.hashParams
hashParams['supportModal'] = `${values.sendSupportRequest.kind || ''}:${
values.sendSupportRequest.target_area || ''
}`
return [router.values.location.pathname, router.values.searchParams, hashParams]
}
return {
openSupportForm: () => updateUrl(),
setSendSupportRequestValue: () => updateUrl(),
closeSupportForm: () => {
const hashParams = router.values.hashParams
delete hashParams['supportModal']
return [router.values.location.pathname, router.values.searchParams, hashParams]
},
}
}),
])
9 changes: 8 additions & 1 deletion frontend/src/scenes/scenes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ErrorNetwork as ErrorNetworkComponent } from '~/layout/ErrorNetwork'
import { ErrorProjectUnavailable as ErrorProjectUnavailableComponent } from '~/layout/ErrorProjectUnavailable'
import { urls } from 'scenes/urls'
import { InsightShortId, SessionRecordingsTabs } from '~/types'
import { combineUrl } from 'kea-router'

export const emptySceneParams = { params: {}, searchParams: {}, hashParams: {} }

Expand Down Expand Up @@ -255,11 +256,17 @@ export const sceneConfigurations: Partial<Record<Scene, SceneConfig>> = {
},
}

const preserveParams = (url: string) => (_params: Params, searchParams: Params, hashParams: Params) => {
const combined = combineUrl(url, searchParams, hashParams)
return combined.url
}

// NOTE: These redirects will fully replace the URL. If you want to keep support for query and hash params then you should use the above `preserveParams` function.
export const redirects: Record<
string,
string | ((params: Params, searchParams: Params, hashParams: Params) => string)
> = {
'/': urls.projectHomepage(),
'/': preserveParams(urls.projectHomepage()),
'/saved_insights': urls.savedInsights(),
'/dashboards': urls.dashboards(),
'/plugins': urls.projectApps(),
Expand Down

0 comments on commit 503b15c

Please sign in to comment.