This repository was archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathroutes.tsx
More file actions
154 lines (142 loc) · 5.73 KB
/
routes.tsx
File metadata and controls
154 lines (142 loc) · 5.73 KB
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
import type { FC } from 'react'
import { Navigate } from 'react-router-dom'
import type { PlatformContextProps } from '@sourcegraph/shared/src/platform/context'
import type { SettingsCascadeProps } from '@sourcegraph/shared/src/settings/settings'
import type { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService'
import { useIsLightTheme } from '@sourcegraph/shared/src/theme'
import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent'
import { Text } from '@sourcegraph/wildcard'
import type { AuthenticatedUser } from '../../auth'
import { canWriteBatchChanges } from '../../batches/utils'
import type { ExecutorsUserAreaProps } from '../../enterprise/executors/ExecutorsUserArea'
import type { UserEventLogsPageProps } from '../../enterprise/user/settings/UserEventLogsPage'
import type { UserSettingsAreaUserFields } from '../../graphql-operations'
import { SiteAdminAlert } from '../../site-admin/SiteAdminAlert'
import type { UserSettingsAreaRoute, UserSettingsAreaRouteContext } from './UserSettingsArea'
const ExecutorsUserArea = lazyComponent<ExecutorsUserAreaProps, 'ExecutorsUserArea'>(
() => import('../../enterprise/executors/ExecutorsUserArea'),
'ExecutorsUserArea'
)
const SettingsArea = lazyComponent(() => import('../../settings/SettingsArea'), 'SettingsArea')
const UserSettingsSecurityPage = lazyComponent(
() => import('./auth/UserSettingsSecurityPage'),
'UserSettingsSecurityPage'
)
const shouldRenderBatchChangesPage = ({
batchChangesEnabled,
user: { viewerCanAdminister },
authenticatedUser,
}: UserSettingsAreaRouteContext): boolean =>
batchChangesEnabled && viewerCanAdminister && canWriteBatchChanges(authenticatedUser)
export const userSettingsAreaRoutes: readonly UserSettingsAreaRoute[] = [
{
path: '',
render: props => <UserSettingAreaIndexPage {...props} />,
},
{
path: 'profile',
render: lazyComponent(() => import('./profile/UserSettingsProfilePage'), 'UserSettingsProfilePage'),
},
{
path: 'password',
render: () => <Navigate to="../security" replace={true} />,
},
{
path: 'quota',
render: lazyComponent(() => import('./quota/UserQuotaProfilePage'), 'UserQuotaProfilePage'),
condition: ({ authenticatedUser }) => authenticatedUser.siteAdmin,
},
{
path: 'emails',
render: lazyComponent(() => import('./emails/UserSettingsEmailsPage'), 'UserSettingsEmailsPage'),
},
{
path: 'tokens/*',
render: lazyComponent(() => import('./accessTokens/UserSettingsTokensArea'), 'UserSettingsTokensArea'),
condition: () => window.context.accessTokensAllow !== 'none',
},
// future GA Cloud routes
{
path: 'security',
render: props => <UserSettingsSecurityPage {...props} context={window.context} />,
},
{
path: 'product-research',
render: lazyComponent(() => import('./research/ProductResearch'), 'ProductResearchPage'),
condition: () => window.context.productResearchPageEnabled,
},
{
path: 'permissions',
render: lazyComponent(
() => import('../../enterprise/user/settings/auth/UserSettingsPermissionsPage'),
'UserSettingsPermissionsPage'
),
},
{
path: 'event-log',
render: lazyComponent<UserEventLogsPageProps, 'UserEventLogsPage'>(
() => import('../../enterprise/user/settings/UserEventLogsPage'),
'UserEventLogsPage'
),
},
{
path: 'executors/*',
render: props => (
<ExecutorsUserArea
{...props}
telemetryRecorder={props.platformContext.telemetryRecorder}
namespaceID={props.user.id}
/>
),
condition: shouldRenderBatchChangesPage,
},
{
path: 'batch-changes',
render: lazyComponent(
() => import('../../enterprise/batches/settings/BatchChangesSettingsArea'),
'BatchChangesSettingsArea'
),
condition: shouldRenderBatchChangesPage,
},
{
path: 'github-apps/*',
render: lazyComponent(() => import('./UserGitHubAppsArea'), 'UserGitHubAppsArea'),
// GitHub Apps are currently only relevant for users who use them with batch changes. If they are used for other things too, you can remove this condition.
condition: shouldRenderBatchChangesPage,
},
]
interface UserSettingAreaIndexPageProps extends PlatformContextProps, SettingsCascadeProps, TelemetryProps {
isSourcegraphDotCom: boolean
authenticatedUser: AuthenticatedUser
user: UserSettingsAreaUserFields
extraHeader?: JSX.Element
className?: string
}
const UserSettingAreaIndexPage: FC<UserSettingAreaIndexPageProps> = props => {
const { isSourcegraphDotCom, authenticatedUser, user } = props
const isLightTheme = useIsLightTheme()
if (isSourcegraphDotCom && authenticatedUser && user.id !== authenticatedUser.id) {
return (
<SiteAdminAlert className="sidebar__alert" variant="danger">
Only the user may access their individual settings.
</SiteAdminAlert>
)
}
return (
<SettingsArea
{...props}
subject={props.user}
isLightTheme={isLightTheme}
extraHeader={
<>
{authenticatedUser && user.id !== authenticatedUser.id && (
<SiteAdminAlert className="sidebar__alert">
Viewing settings for <strong>{user.username}</strong>
</SiteAdminAlert>
)}
<Text>User settings override global and organization settings.</Text>
</>
}
/>
)
}