11import { type FC , useCallback , useState } from 'react'
22
3- import { mdiChevronDoubleRight , mdiChevronDoubleLeft } from '@mdi/js'
3+ import { mdiPageLayoutSidebarRight } from '@mdi/js'
44import classNames from 'classnames'
55
66import type { Scalars } from '@sourcegraph/shared/src/graphql-operations'
@@ -12,7 +12,6 @@ import type { RepoFile } from '@sourcegraph/shared/src/util/url'
1212import {
1313 Button ,
1414 useLocalStorage ,
15- useMatchMedia ,
1615 Tab ,
1716 TabList ,
1817 TabPanel ,
@@ -23,7 +22,6 @@ import {
2322 Tooltip ,
2423} from '@sourcegraph/wildcard'
2524
26- import settingsSchemaJSON from '../../../../schema/settings.schema.json'
2725import type { AuthenticatedUser } from '../auth'
2826import { useFeatureFlag } from '../featureFlags/useFeatureFlag'
2927import { GettingStartedTour } from '../tour/GettingStartedTour'
@@ -41,46 +39,29 @@ interface RepoRevisionSidebarProps extends RepoFile, TelemetryProps, SettingsCas
4139 className : string
4240 authenticatedUser : AuthenticatedUser | null
4341 isSourcegraphDotCom : boolean
42+ isVisible : boolean
43+ handleSidebarToggle : ( value : boolean ) => void
4444}
4545
4646const SIZE_STORAGE_KEY = 'repo-revision-sidebar'
4747const TABS_KEY = 'repo-revision-sidebar-last-tab'
48- const SIDEBAR_KEY = 'repo-revision-sidebar-toggle'
4948/**
5049 * The sidebar for a specific repo revision that shows the list of files and directories.
5150 */
5251export const RepoRevisionSidebar : FC < RepoRevisionSidebarProps > = props => {
5352 const [ persistedTabIndex , setPersistedTabIndex ] = useLocalStorage ( TABS_KEY , 0 )
54- const [ persistedIsVisible , setPersistedIsVisible ] = useLocalStorage (
55- SIDEBAR_KEY ,
56- settingsSchemaJSON . properties . fileSidebarVisibleByDefault . default
57- )
5853 const showOnboardingTour = useShowOnboardingTour ( {
5954 authenticatedUser : props . authenticatedUser ,
6055 isSourcegraphDotCom : props . isSourcegraphDotCom ,
6156 } )
6257
63- const isWideScreen = useMatchMedia ( '(min-width: 768px)' , false )
64- const [ isVisible , setIsVisible ] = useState ( persistedIsVisible && isWideScreen )
65-
6658 const [ initialFilePath , setInitialFilePath ] = useState < string > ( props . filePath )
6759 const [ initialFilePathIsDir , setInitialFilePathIsDir ] = useState < boolean > ( props . isDir )
6860 const onExpandParent = useCallback ( ( parent : string ) => {
6961 setInitialFilePath ( parent )
7062 setInitialFilePathIsDir ( true )
7163 } , [ ] )
7264
73- const handleSidebarToggle = useCallback (
74- ( value : boolean ) => {
75- props . telemetryService . log ( 'FileTreeViewClicked' , {
76- action : 'click' ,
77- label : 'expand / collapse file tree view' ,
78- } )
79- setPersistedIsVisible ( value )
80- setIsVisible ( value )
81- } ,
82- [ setPersistedIsVisible , props . telemetryService ]
83- )
8465 const handleSymbolClick = useCallback (
8566 ( ) => props . telemetryService . log ( 'SymbolTreeViewClicked' ) ,
8667 [ props . telemetryService ]
@@ -94,14 +75,27 @@ export const RepoRevisionSidebar: FC<RepoRevisionSidebarProps> = props => {
9475
9576 return (
9677 < >
97- { isVisible ? (
78+ { props . isVisible && (
9879 < Panel
9980 defaultSize = { 256 }
10081 minSize = { 150 }
10182 position = "left"
10283 storageKey = { SIZE_STORAGE_KEY }
10384 ariaLabel = "File sidebar"
10485 >
86+ < Tooltip content = "Hide sidebar" placement = "right" >
87+ < Button
88+ aria-label = "Hide sidebar"
89+ variant = "icon"
90+ className = { classNames (
91+ 'position-absolute border mr-2' ,
92+ styles . toggle
93+ ) }
94+ onClick = { ( ) => props . handleSidebarToggle ( false ) }
95+ >
96+ < Icon aria-hidden = { true } svgPath = { mdiPageLayoutSidebarRight } />
97+ </ Button >
98+ </ Tooltip >
10599 < div className = "d-flex flex-column h-100 w-100" >
106100 { showOnboardingTour && (
107101 < GettingStartedTour
@@ -120,22 +114,7 @@ export const RepoRevisionSidebar: FC<RepoRevisionSidebarProps> = props => {
120114 behavior = "memoize"
121115 >
122116 < TabList
123- wrapperClassName = "mr-3"
124- actions = {
125- < Tooltip content = "Hide sidebar" placement = "right" >
126- < Button
127- aria-label = "Hide sidebar"
128- onClick = { ( ) => handleSidebarToggle ( false ) }
129- className = "bg-transparent border-0 ml-auto p-1 position-relative focus-behaviour"
130- >
131- < Icon
132- className = { styles . closeIcon }
133- aria-hidden = { true }
134- svgPath = { mdiChevronDoubleLeft }
135- />
136- </ Button >
137- </ Tooltip >
138- }
117+ wrapperClassName = "mr-3 ml-5"
139118 >
140119 < Tab data-tab-content = "files" >
141120 < span className = "tablist-wrapper--tab-label" > Files</ span >
@@ -182,21 +161,8 @@ export const RepoRevisionSidebar: FC<RepoRevisionSidebarProps> = props => {
182161 </ Tabs >
183162 </ div >
184163 </ Panel >
185- ) : (
186- < Tooltip content = "Show sidebar" >
187- < Button
188- aria-label = "Show sidebar"
189- variant = "icon"
190- className = { classNames (
191- 'position-absolute border-top border-bottom border-right mt-4' ,
192- styles . toggle
193- ) }
194- onClick = { ( ) => handleSidebarToggle ( true ) }
195- >
196- < Icon aria-hidden = { true } svgPath = { mdiChevronDoubleRight } />
197- </ Button >
198- </ Tooltip >
199- ) }
164+ )
165+ }
200166
201167 { enableBlobPageSwitchAreasShortcuts && (
202168 < >
@@ -206,7 +172,7 @@ export const RepoRevisionSidebar: FC<RepoRevisionSidebarProps> = props => {
206172 { ...keybinding }
207173 allowDefault = { true }
208174 onMatch = { ( ) => {
209- handleSidebarToggle ( true )
175+ props . handleSidebarToggle ( true )
210176 setPersistedTabIndex ( 0 )
211177 setFileTreeFocusKey ( Date . now ( ) . toString ( ) )
212178 } }
@@ -218,7 +184,7 @@ export const RepoRevisionSidebar: FC<RepoRevisionSidebarProps> = props => {
218184 { ...keybinding }
219185 allowDefault = { true }
220186 onMatch = { ( ) => {
221- handleSidebarToggle ( true )
187+ props . handleSidebarToggle ( true )
222188 setPersistedTabIndex ( 1 )
223189 setSymbolsFocusKey ( Date . now ( ) . toString ( ) )
224190 } }
0 commit comments