forked from sourcegraph/sourcegraph-public-snapshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepositoryNotFoundPage.tsx
136 lines (123 loc) · 5.88 KB
/
RepositoryNotFoundPage.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
import MapSearchIcon from 'mdi-react/MapSearchIcon'
import * as React from 'react'
import { merge, of, Subject, Subscription } from 'rxjs'
import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
import { asError, ErrorLike, isErrorLike } from '../../../shared/src/util/errors'
import { HeroPage } from '../components/HeroPage'
import { checkMirrorRepositoryConnection } from '../site-admin/backend'
import { eventLogger } from '../tracking/eventLogger'
interface Props {
/** The name of the repository. */
repo: string
/** Whether the viewer is a site admin. */
viewerCanAdminister: boolean
}
interface State {
/**
* Whether the option to add the repository should be shown.
*/
showAdd: boolean
/**
* Whether the site admin can add this repository. undefined while loading.
*/
canAddOrError?: boolean | ErrorLike
}
/**
* A page informing the user that an error occurred while trying to display the repository. It
* attempts to present the user with actions to solve the problem.
*/
export class RepositoryNotFoundPage extends React.PureComponent<Props, State> {
public state: State = {
showAdd: false,
}
private componentUpdates = new Subject<Props>()
private subscriptions = new Subscription()
public componentDidMount(): void {
eventLogger.logViewEvent('RepositoryError')
// Show/hide add.
this.subscriptions.add(
this.componentUpdates
.pipe(
distinctUntilChanged(
(a, b) => a.repo === b.repo && a.viewerCanAdminister === b.viewerCanAdminister
),
switchMap(({ repo, viewerCanAdminister }) => {
type PartialStateUpdate = Pick<State, 'showAdd' | 'canAddOrError'>
if (!viewerCanAdminister) {
return of({ showAdd: false, canAddOrError: undefined })
}
return merge<PartialStateUpdate>(
of({ showAdd: true, canAddOrError: undefined }),
checkMirrorRepositoryConnection({ name: repo }).pipe(
map(c => c.error === null),
catchError(error => [asError(error)]),
map((c): PartialStateUpdate => ({ showAdd: true, canAddOrError: c }))
)
)
})
)
.subscribe(
stateUpdate => this.setState(stateUpdate),
error => console.error(error)
)
)
this.componentUpdates.next(this.props)
}
public componentDidUpdate(): void {
this.componentUpdates.next(this.props)
}
public componentWillUnmount(): void {
this.subscriptions.unsubscribe()
}
public render(): JSX.Element | null {
return (
<HeroPage
icon={MapSearchIcon}
title="Repository not found"
subtitle={
<div className="repository-not-found-page">
{this.state.showAdd && (
<div className="repository-not-found-page__section mt-3">
<div className="repository-not-found-page__section-inner">
<div className="repository-not-found-page__section-description">
{this.state.canAddOrError === undefined && (
<>Checking whether this repository can be added...</>
)}
{(this.state.canAddOrError === false ||
isErrorLike(this.state.canAddOrError)) && (
<>
<p>
If this is a private repository, check that this site is configured
with a token that has access to this repository.
</p>
<p>
If this is a public repository, check that this repository is
explicitly listed in an{' '}
<a href="/site-admin/external-services">
external service configuration
</a>
.
</p>
</>
)}
{this.state.canAddOrError === true && (
<>
As a site admin, you can add this repository to Sourcegraph to allow
users to search and view it by{' '}
<a href="/site-admin/external-services">
connecting an external service
</a>
.
</>
)}
</div>
</div>
</div>
)}
{!this.state.showAdd && <p>To access this repository, contact the Sourcegraph admin.</p>}
</div>
}
/>
)
}
}