Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for opening bug report via URL #15251

Merged
merged 5 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
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