/
routes.tsx
229 lines (223 loc) · 7.76 KB
/
routes.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import * as React from 'react'
import { Redirect, RouteComponentProps } from 'react-router'
import { LayoutProps } from './Layout'
import { parseSearchURLQuery } from './search'
import { lazyComponent } from './util/lazyComponent'
import { isErrorLike } from '../../shared/src/util/errors'
import { RepogroupPage } from './repogroups/RepogroupPage'
import { python2To3Metadata } from './repogroups/Python2To3'
import { kubernetes } from './repogroups/Kubernetes'
import { golang } from './repogroups/Golang'
import { reactHooks } from './repogroups/ReactHooks'
import { android } from './repogroups/Android'
import { stanford } from './repogroups/Stanford'
import { BreadcrumbsProps, BreadcrumbSetters } from './components/Breadcrumbs'
import { isUndefined } from 'lodash'
const SearchPage = lazyComponent(() => import('./search/input/SearchPage'), 'SearchPage')
const SearchResults = lazyComponent(() => import('./search/results/SearchResults'), 'SearchResults')
const SiteAdminArea = lazyComponent(() => import('./site-admin/SiteAdminArea'), 'SiteAdminArea')
const ExtensionsArea = lazyComponent(() => import('./extensions/ExtensionsArea'), 'ExtensionsArea')
const SearchConsolePage = lazyComponent(() => import('./search/SearchConsolePage'), 'SearchConsolePage')
interface LayoutRouteComponentProps<Params extends { [K in keyof Params]?: string }>
extends RouteComponentProps<Params>,
Omit<LayoutProps, 'match'>,
BreadcrumbsProps,
BreadcrumbSetters {}
export interface LayoutRouteProps<Params extends { [K in keyof Params]?: string }> {
path: string
exact?: boolean
render: (props: LayoutRouteComponentProps<Params>) => React.ReactNode
/**
* A condition function that needs to return true if the route should be rendered
*
* @default () => true
*/
condition?: (props: LayoutRouteComponentProps<Params>) => boolean
}
// Force a hard reload so that we delegate to the serverside HTTP handler for a route.
function passThroughToServer(): React.ReactNode {
window.location.reload()
return null
}
/**
* Holds all top-level routes for the app because both the navbar and the main content area need to
* switch over matched path.
*
* See https://reacttraining.com/react-router/web/example/sidebar
*/
export const routes: readonly LayoutRouteProps<any>[] = [
{
path: '/',
render: props =>
window.context.sourcegraphDotComMode && !props.authenticatedUser ? (
<Redirect to="https://about.sourcegraph.com" />
) : (
<Redirect to="/search" />
),
exact: true,
},
{
path: '/search',
render: props =>
parseSearchURLQuery(props.location.search) ? (
<SearchResults {...props} deployType={window.context.deployType} />
) : (
<SearchPage {...props} />
),
exact: true,
},
{
path: '/search/query-builder',
render: lazyComponent(() => import('./search/queryBuilder/QueryBuilderPage'), 'QueryBuilderPage'),
exact: true,
},
{
path: '/search/console',
render: props =>
props.showMultilineSearchConsole ? (
<SearchConsolePage
{...props}
allExpanded={false}
showSavedQueryModal={false}
deployType={window.context.deployType}
didSave={false}
/>
) : (
<Redirect to="/search" />
),
exact: true,
},
{
path: '/sign-in',
render: lazyComponent(() => import('./auth/SignInPage'), 'SignInPage'),
exact: true,
},
{
path: '/sign-up',
render: lazyComponent(() => import('./auth/SignUpPage'), 'SignUpPage'),
exact: true,
},
{
path: '/settings',
render: lazyComponent(() => import('./user/settings/RedirectToUserSettings'), 'RedirectToUserSettings'),
},
{
path: '/user',
render: lazyComponent(() => import('./user/settings/RedirectToUserPage'), 'RedirectToUserPage'),
},
{
path: '/organizations',
render: lazyComponent(() => import('./org/OrgsArea'), 'OrgsArea'),
},
{
path: '/search',
render: props => <SearchResults {...props} deployType={window.context.deployType} />,
exact: true,
},
{
path: '/site-admin/init',
exact: true,
render: lazyComponent(() => import('./site-admin/init/SiteInitPage'), 'SiteInitPage'),
},
{
path: '/site-admin',
render: props => (
<SiteAdminArea
{...props}
routes={props.siteAdminAreaRoutes}
sideBarGroups={props.siteAdminSideBarGroups}
overviewComponents={props.siteAdminOverviewComponents}
/>
),
},
{
path: '/password-reset',
render: lazyComponent(() => import('./auth/ResetPasswordPage'), 'ResetPasswordPage'),
exact: true,
},
{
path: '/explore',
render: lazyComponent(() => import('./explore/ExploreArea'), 'ExploreArea'),
exact: true,
},
{
path: '/search/scope/:id',
render: lazyComponent(() => import('./search/ScopePage'), 'ScopePage'),
exact: true,
},
{
path: '/api/console',
render: lazyComponent(() => import('./api/ApiConsole'), 'ApiConsole'),
exact: true,
},
{
path: '/users/:username',
render: lazyComponent(() => import('./user/area/UserArea'), 'UserArea'),
},
{
path: '/survey/:score?',
render: lazyComponent(() => import('./marketing/SurveyPage'), 'SurveyPage'),
},
{
path: '/extensions',
render: props => <ExtensionsArea {...props} routes={props.extensionsAreaRoutes} />,
},
{
path: '/help',
render: passThroughToServer,
},
{
path: '/-/debug/*',
render: passThroughToServer,
},
{
path: '/snippets',
render: lazyComponent(() => import('./snippets/SnippetsPage'), 'SnippetsPage'),
},
{
path: '/insights',
exact: true,
render: lazyComponent(() => import('./insights/InsightsPage'), 'InsightsPage'),
condition: props =>
!isErrorLike(props.settingsCascade.final) &&
!!props.settingsCascade.final?.experimentalFeatures?.codeInsights,
},
{
path: '/views',
render: lazyComponent(() => import('./views/ViewsArea'), 'ViewsArea'),
},
{
path: '/refactor-python2-to-3',
render: props => <RepogroupPage {...props} repogroupMetadata={python2To3Metadata} />,
condition: props => window.context.sourcegraphDotComMode,
},
{
path: '/kubernetes',
render: props => <RepogroupPage {...props} repogroupMetadata={kubernetes} />,
condition: props => window.context.sourcegraphDotComMode,
},
{
path: '/golang',
render: props => <RepogroupPage {...props} repogroupMetadata={golang} />,
condition: props => window.context.sourcegraphDotComMode,
},
{
path: '/react-hooks',
render: props => <RepogroupPage {...props} repogroupMetadata={reactHooks} />,
condition: props => window.context.sourcegraphDotComMode,
},
{
path: '/android',
render: props => <RepogroupPage {...props} repogroupMetadata={android} />,
condition: props => window.context.sourcegraphDotComMode,
},
{
path: '/stanford',
render: props => <RepogroupPage {...props} repogroupMetadata={stanford} />,
condition: props => window.context.sourcegraphDotComMode,
},
{
path: '/:repoRevAndRest+',
render: lazyComponent(() => import('./repo/RepoContainer'), 'RepoContainer'),
},
]