1
1
import type { ReactNode } from 'react' ;
2
- import { Fragment , useMemo , useState } from 'react' ;
2
+ import { Fragment , useEffect , useMemo , useState } from 'react' ;
3
3
import styled from '@emotion/styled' ;
4
4
import { PlatformIcon } from 'platformicons' ;
5
5
@@ -8,6 +8,7 @@ import HighlightTopRightPattern from 'sentry-images/pattern/highlight-top-right.
8
8
import { LinkButton } from 'sentry/components/button' ;
9
9
import { CompactSelect } from 'sentry/components/compactSelect' ;
10
10
import RadioGroup from 'sentry/components/forms/controls/radioGroup' ;
11
+ import useDrawer from 'sentry/components/globalDrawer' ;
11
12
import IdBadge from 'sentry/components/idBadge' ;
12
13
import LoadingIndicator from 'sentry/components/loadingIndicator' ;
13
14
import useCurrentProjectState from 'sentry/components/onboarding/gettingStartedDoc/utils/useCurrentProjectState' ;
@@ -29,19 +30,67 @@ import {
29
30
} from 'sentry/data/platformCategories' ;
30
31
import platforms , { otherPlatform } from 'sentry/data/platforms' ;
31
32
import { t , tct } from 'sentry/locale' ;
33
+ import SidebarPanelStore from 'sentry/stores/sidebarPanelStore' ;
34
+ import { useLegacyStore } from 'sentry/stores/useLegacyStore' ;
32
35
import { space } from 'sentry/styles/space' ;
33
36
import type { SelectValue } from 'sentry/types/core' ;
34
37
import type { PlatformKey , Project } from 'sentry/types/project' ;
35
38
import useOrganization from 'sentry/utils/useOrganization' ;
36
39
import useUrlParams from 'sentry/utils/useUrlParams' ;
37
40
38
- function ReplaysOnboardingSidebar ( props : CommonSidebarProps ) {
41
+ export function useReplaysOnboardingDrawer ( ) {
42
+ const organization = useOrganization ( ) ;
43
+ const currentPanel = useLegacyStore ( SidebarPanelStore ) ;
44
+ const isActive = currentPanel === SidebarPanelKey . REPLAYS_ONBOARDING ;
45
+ const hasProjectAccess = organization . access . includes ( 'project:read' ) ;
46
+
47
+ const { openDrawer} = useDrawer ( ) ;
48
+
49
+ useEffect ( ( ) => {
50
+ if ( isActive && hasProjectAccess ) {
51
+ openDrawer ( ( ) => < DrawerContent /> , {
52
+ ariaLabel : t ( 'Getting Started with Session Replay' ) ,
53
+ // Prevent the drawer from closing when the query params change
54
+ shouldCloseOnLocationChange : location =>
55
+ location . pathname !== window . location . pathname ,
56
+ } ) ;
57
+ }
58
+ } , [ isActive , hasProjectAccess , openDrawer ] ) ;
59
+ }
60
+
61
+ function DrawerContent ( ) {
62
+ useEffect ( ( ) => {
63
+ return ( ) => {
64
+ SidebarPanelStore . hidePanel ( ) ;
65
+ } ;
66
+ } , [ ] ) ;
67
+
68
+ return < SidebarContent /> ;
69
+ }
70
+
71
+ function LegacyReplaysOnboardingSidebar ( props : CommonSidebarProps ) {
39
72
const { currentPanel, collapsed, hidePanel, orientation} = props ;
40
73
const organization = useOrganization ( ) ;
41
74
42
75
const isActive = currentPanel === SidebarPanelKey . REPLAYS_ONBOARDING ;
43
76
const hasProjectAccess = organization . access . includes ( 'project:read' ) ;
44
77
78
+ if ( ! isActive || ! hasProjectAccess ) {
79
+ return null ;
80
+ }
81
+
82
+ return (
83
+ < TaskSidebarPanel
84
+ orientation = { orientation }
85
+ collapsed = { collapsed }
86
+ hidePanel = { hidePanel }
87
+ >
88
+ < SidebarContent />
89
+ </ TaskSidebarPanel >
90
+ ) ;
91
+ }
92
+
93
+ function SidebarContent ( ) {
45
94
const {
46
95
hasDocs,
47
96
projects,
@@ -51,7 +100,7 @@ function ReplaysOnboardingSidebar(props: CommonSidebarProps) {
51
100
supportedProjects,
52
101
unsupportedProjects,
53
102
} = useCurrentProjectState ( {
54
- currentPanel,
103
+ currentPanel : SidebarPanelKey . REPLAYS_ONBOARDING ,
55
104
targetPanel : SidebarPanelKey . REPLAYS_ONBOARDING ,
56
105
onboardingPlatforms : replayOnboardingPlatforms ,
57
106
allPlatforms : replayPlatforms ,
@@ -102,16 +151,13 @@ function ReplaysOnboardingSidebar(props: CommonSidebarProps) {
102
151
} , [ supportedProjects , unsupportedProjects ] ) ;
103
152
104
153
const selectedProject = currentProject ?? projects [ 0 ] ?? allProjects [ 0 ] ;
105
- if ( ! isActive || ! hasProjectAccess || ! selectedProject ) {
154
+
155
+ if ( ! selectedProject ) {
106
156
return null ;
107
157
}
108
158
109
159
return (
110
- < TaskSidebarPanel
111
- orientation = { orientation }
112
- collapsed = { collapsed }
113
- hidePanel = { hidePanel }
114
- >
160
+ < Fragment >
115
161
< TopRightBackgroundImage src = { HighlightTopRightPattern } />
116
162
< TaskList >
117
163
< Heading > { t ( 'Getting Started with Session Replay' ) } </ Heading >
@@ -150,7 +196,7 @@ function ReplaysOnboardingSidebar(props: CommonSidebarProps) {
150
196
</ HeaderActions >
151
197
< OnboardingContent currentProject = { selectedProject } hasDocs = { hasDocs } />
152
198
</ TaskList >
153
- </ TaskSidebarPanel >
199
+ </ Fragment >
154
200
) ;
155
201
}
156
202
@@ -445,4 +491,4 @@ const StyledRadioGroup = styled(RadioGroup)`
445
491
padding: ${ space ( 1 ) } 0;
446
492
` ;
447
493
448
- export default ReplaysOnboardingSidebar ;
494
+ export default LegacyReplaysOnboardingSidebar ;
0 commit comments