Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/containers/pr-list-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class PrList extends React.Component {

render() {
const repo = this.props.query.repository;
if (!repo.pullRequests.edges.length) {
if (!repo || !repo.pullRequests.edges.length) {
return null; // TODO: no PRs
}
const pr = repo.pullRequests.edges[0].node;
Expand Down
42 changes: 32 additions & 10 deletions lib/controllers/pr-info-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import Relay from 'react-relay';
import {RemotePropType} from '../prop-types';
import RelayRootContainer from '../containers/relay-root-container';
import PrListContainer from '../containers/pr-list-container';
import GithubLoginView from '../views/github-login-view';

const environmentByGithubInstance = new Map();
const relayConfigByGithubInstance = new Map();

const getEnvironmentForInstance = (instance, endpoint, token) => {
let environment = environmentByGithubInstance.get(instance);
const config = relayConfigByGithubInstance.get(instance) || {};
let {environment, networkLayer} = config;
if (!environment) {
environment = new Relay.Environment();
environment.injectNetworkLayer(
new Relay.DefaultNetworkLayer(`${endpoint}/graphql`, {
headers: {
Authorization: `bearer ${token}`,
},
}),
);
environmentByGithubInstance.set(instance, environment);
networkLayer = new Relay.DefaultNetworkLayer(`${endpoint}/graphql`, {
headers: {
Authorization: `bearer ${token}`,
},
});
environment.injectNetworkLayer(networkLayer);
relayConfigByGithubInstance.set(instance, {environment, networkLayer});
} else {
networkLayer._init.headers = {
Authorization: `bearer ${token}`,
};
}
return environment;
};
Expand Down Expand Up @@ -49,6 +54,8 @@ export default class PrInfoController extends React.Component {
token: React.PropTypes.string.isRequired,
instance: React.PropTypes.string.isRequired,
currentBranch: React.PropTypes.string.isRequired,
loginModel: React.PropTypes.object.isRequired,
onLogin: React.PropTypes.func.isRequired,
remote: RemotePropType.isRequired,
}

Expand All @@ -68,6 +75,21 @@ export default class PrInfoController extends React.Component {
Component={PrListContainer}
route={route}
environment={environment}
renderLoading={() => {
return <div>Loading...</div>;
}}
renderFailure={(err, retry) => {
if (err.response && err.response.status === 401) {
return (
<div>
The API endpoint returned a unauthorized error. Please try to re-authenticate with the endpoint.
<GithubLoginView onLogin={this.props.onLogin} />
</div>
);
} else {
return <div>An unknown error occurred.</div>;
}
}}
/>
);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/controllers/remote-pr-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,14 @@ export default class RemotePrController extends React.Component {
}

render() {
const {instance, endpoint, remote, currentBranch, token} = this.props;
const {instance, endpoint, remote, currentBranch, token, loginModel} = this.props;
return (
<div className="github-RemotePrController">
{token && <PrInfoController {...{instance, endpoint, remote, currentBranch, token}} />}
{token && <PrInfoController
{...{instance, endpoint, remote, currentBranch, token, loginModel}}
onLogin={this.handleLogin}
/>
}
{!token && <GithubLoginView onLogin={this.handleLogin} />}
</div>
);
Expand Down