Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 3f647d2

Browse files
new expand/collapse button
1 parent 043589f commit 3f647d2

File tree

5 files changed

+91
-80
lines changed

5 files changed

+91
-80
lines changed

client/web/src/repo/RepoHeader.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class RepoHeaderContributionStore {
2929
constructor(
3030
/** The common ancestor component's setState method. */
3131
private setState: (callback: (previousState: RepoHeaderContribution[]) => RepoHeaderContribution[]) => void
32-
) {}
32+
) { }
3333

3434
private onRepoHeaderContributionAdd(item: RepoHeaderContribution): void {
3535
if (!item.children || typeof item.children !== 'function') {
@@ -115,7 +115,7 @@ export interface RepoHeaderContext {
115115
actionType: 'nav' | 'dropdown'
116116
}
117117

118-
export interface RepoHeaderActionButton extends ActionButtonDescriptor<RepoHeaderContext> {}
118+
export interface RepoHeaderActionButton extends ActionButtonDescriptor<RepoHeaderContext> { }
119119

120120
interface Props extends PlatformContextProps, TelemetryProps, BreadcrumbsProps {
121121
/**
@@ -168,6 +168,10 @@ export const RepoHeader: React.FunctionComponent<React.PropsWithChildren<Props>>
168168
onLifecyclePropsChange(repoHeaderContributionStore.props)
169169
}, [onLifecyclePropsChange, repoHeaderContributionStore.props])
170170

171+
// useEffect(() => {
172+
// console.log(props.breadcrumbs)
173+
// }, [])
174+
171175
const context: Omit<RepoHeaderContext, 'actionType'> = useMemo(
172176
() => ({
173177
repoName: props.repoName,

client/web/src/repo/RepoRevisionSidebar.tsx

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { type FC, useCallback, useState } from 'react'
22

3-
import { mdiChevronDoubleRight, mdiChevronDoubleLeft } from '@mdi/js'
3+
import { mdiPageLayoutSidebarRight } from '@mdi/js'
44
import classNames from 'classnames'
55

66
import type { Scalars } from '@sourcegraph/shared/src/graphql-operations'
@@ -12,7 +12,6 @@ import type { RepoFile } from '@sourcegraph/shared/src/util/url'
1212
import {
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'
2725
import type { AuthenticatedUser } from '../auth'
2826
import { useFeatureFlag } from '../featureFlags/useFeatureFlag'
2927
import { 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

4646
const SIZE_STORAGE_KEY = 'repo-revision-sidebar'
4747
const 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
*/
5251
export 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
}}

client/web/src/repo/RepositoryFileTreePage.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import type { FC } from 'react'
1+
import { FC, useCallback, useState } from 'react'
22

33
import { Navigate, useLocation } from 'react-router-dom'
44

5+
import settingsSchemaJSON from '../../../../schema/settings.schema.json'
56
import { appendLineRangeQueryParameter } from '@sourcegraph/common'
67
import { TraceSpanProvider } from '@sourcegraph/observability-client'
78
import { getModeFromPath } from '@sourcegraph/shared/src/languages'
89
import { isLegacyFragment, parseQueryAndHash, toRepoURL } from '@sourcegraph/shared/src/util/url'
9-
import { LoadingSpinner } from '@sourcegraph/wildcard'
10+
import { LoadingSpinner, useLocalStorage, useMatchMedia } from '@sourcegraph/wildcard'
1011

1112
import { ErrorBoundary } from '../components/ErrorBoundary'
1213
import type { SourcegraphContext } from '../jscontext'
@@ -58,6 +59,27 @@ export const RepositoryFileTreePage: FC<RepositoryFileTreePageProps> = props =>
5859
return <Navigate to={url} replace={true} />
5960
}
6061

62+
const SIDEBAR_KEY = 'repo-revision-sidebar-toggle'
63+
64+
const [persistedIsVisible, setPersistedIsVisible] = useLocalStorage(
65+
SIDEBAR_KEY,
66+
settingsSchemaJSON.properties.fileSidebarVisibleByDefault.default
67+
)
68+
const isWideScreen = useMatchMedia('(min-width: 768px)', false)
69+
const [isVisible, setIsVisible] = useState(persistedIsVisible && isWideScreen)
70+
71+
const handleSidebarToggle = useCallback(
72+
(value: boolean) => {
73+
props.telemetryService.log('FileTreeViewClicked', {
74+
action: 'click',
75+
label: 'expand / collapse file tree view',
76+
})
77+
setPersistedIsVisible(value)
78+
setIsVisible(value)
79+
},
80+
[setPersistedIsVisible, props.telemetryService]
81+
)
82+
6183
// For blob pages with legacy URL fragment hashes like "#L17:19-21:23$foo:bar"
6284
// redirect to the modern URL fragment hashes like "#L17:19-21:23&tab=foo:bar"
6385
if (!hideRepoRevisionContent && objectType === 'blob' && isLegacyFragment(location.hash)) {
@@ -86,6 +108,8 @@ export const RepositoryFileTreePage: FC<RepositoryFileTreePageProps> = props =>
86108
repoName={repoName}
87109
isDir={objectType === 'tree'}
88110
defaultBranch={resolvedRevision?.defaultBranch || 'HEAD'}
111+
isVisible={isVisible}
112+
handleSidebarToggle={handleSidebarToggle}
89113
/>
90114
{!hideRepoRevisionContent && (
91115
<>
@@ -108,6 +132,7 @@ export const RepositoryFileTreePage: FC<RepositoryFileTreePageProps> = props =>
108132
fetchHighlightedFileLineRanges={props.fetchHighlightedFileLineRanges}
109133
className={styles.pageContent}
110134
context={globalContext}
135+
handleSidebarToggle={handleSidebarToggle}
111136
/>
112137
</TraceSpanProvider>
113138
) : resolvedRevision ? (

client/web/src/repo/blob/BlobPage.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,27 @@ const RenderedNotebookMarkdown = lazyComponent(() => import('./RenderedNotebookM
9191

9292
interface BlobPageProps
9393
extends RepoFile,
94-
ModeSpec,
95-
RepoHeaderContributionsLifecycleProps,
96-
SettingsCascadeProps,
97-
PlatformContextProps,
98-
TelemetryProps,
99-
ExtensionsControllerProps,
100-
HoverThresholdProps,
101-
BreadcrumbSetters,
102-
SearchStreamingProps,
103-
Pick<SearchContextProps, 'searchContextsEnabled'>,
104-
Pick<StreamingSearchResultsListProps, 'fetchHighlightedFileLineRanges'>,
105-
Pick<CodeIntelligenceProps, 'codeIntelligenceEnabled' | 'useCodeIntel'>,
106-
NotebookProps,
107-
OwnConfigProps {
94+
ModeSpec,
95+
RepoHeaderContributionsLifecycleProps,
96+
SettingsCascadeProps,
97+
PlatformContextProps,
98+
TelemetryProps,
99+
ExtensionsControllerProps,
100+
HoverThresholdProps,
101+
BreadcrumbSetters,
102+
SearchStreamingProps,
103+
Pick<SearchContextProps, 'searchContextsEnabled'>,
104+
Pick<StreamingSearchResultsListProps, 'fetchHighlightedFileLineRanges'>,
105+
Pick<CodeIntelligenceProps, 'codeIntelligenceEnabled' | 'useCodeIntel'>,
106+
NotebookProps,
107+
OwnConfigProps {
108108
authenticatedUser: AuthenticatedUser | null
109109
isMacPlatform: boolean
110110
isSourcegraphDotCom: boolean
111111
repoID?: Scalars['ID']
112112
repoUrl?: string
113113
repoServiceType?: string
114+
handleSidebarToggle: (value: boolean) => void
114115

115116
fetchHighlightedFileLineRanges: (parameters: FetchFileParameters, force?: boolean) => Observable<string[][]>
116117
className?: string
@@ -296,7 +297,7 @@ export const BlobPage: React.FunctionComponent<BlobPageProps> = ({ className, co
296297

297298
const blobInfoOrError = enableLazyBlobSyntaxHighlighting
298299
? // Fallback to formatted blob whilst we do not have the highlighted blob
299-
highlightedBlobInfoOrError || formattedBlobInfoOrError
300+
highlightedBlobInfoOrError || formattedBlobInfoOrError
300301
: highlightedBlobInfoOrError
301302

302303
const onExtendTimeoutClick = useCallback(
@@ -322,9 +323,9 @@ export const BlobPage: React.FunctionComponent<BlobPageProps> = ({ className, co
322323

323324
const isSearchNotebook = Boolean(
324325
blobInfoOrError &&
325-
!isErrorLike(blobInfoOrError) &&
326-
blobInfoOrError.filePath.endsWith(SEARCH_NOTEBOOK_FILE_EXTENSION) &&
327-
props.notebooksEnabled
326+
!isErrorLike(blobInfoOrError) &&
327+
blobInfoOrError.filePath.endsWith(SEARCH_NOTEBOOK_FILE_EXTENSION) &&
328+
props.notebooksEnabled
328329
)
329330

330331
const onCopyNotebook = useCallback(
@@ -454,6 +455,7 @@ export const BlobPage: React.FunctionComponent<BlobPageProps> = ({ className, co
454455
revision={revision}
455456
filePath={filePath}
456457
enableOwnershipPanel={enableOwnershipPanel}
458+
handleSidebarToggle={props.handleSidebarToggle}
457459
/>
458460
)}
459461
</>

client/web/src/repo/blob/own/HistoryAndOwnBar.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback, useEffect } from 'react'
22

3-
import { mdiAccount } from '@mdi/js'
3+
import { mdiAccount, mdiPageLayoutSidebarLeft } from '@mdi/js'
44
import classNames from 'classnames'
55
import { useNavigate } from 'react-router-dom'
66

@@ -23,7 +23,8 @@ export const HistoryAndOwnBar: React.FunctionComponent<{
2323
revision?: string
2424
filePath: string
2525
enableOwnershipPanel: boolean
26-
}> = ({ repoID, revision, filePath, enableOwnershipPanel }) => {
26+
handleSidebarToggle: (value: boolean) => void
27+
}> = ({ repoID, revision, filePath, enableOwnershipPanel, handleSidebarToggle }) => {
2728
const navigate = useNavigate()
2829

2930
const openOwnershipPanel = useCallback(() => {
@@ -86,6 +87,19 @@ export const HistoryAndOwnBar: React.FunctionComponent<{
8687
<div className={styles.wrapper}>
8788
{history && (
8889
<div className={styles.historyPanel}>
90+
<Tooltip content="Hide sidebar" placement="right">
91+
<Button
92+
aria-label="Hide sidebar"
93+
variant="icon"
94+
className={classNames(
95+
'border mr-2',
96+
// styles.toggle
97+
)}
98+
onClick={() => handleSidebarToggle(true)}
99+
>
100+
<Icon aria-hidden={true} svgPath={mdiPageLayoutSidebarLeft} />
101+
</Button>
102+
</Tooltip>
89103
<GitCommitNode
90104
node={history}
91105
extraCompact={true}

0 commit comments

Comments
 (0)