Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Replace remoteOperationObserver with a Refresher
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Nov 8, 2019
1 parent ac0db9c commit be9284c
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 163 deletions.
15 changes: 2 additions & 13 deletions lib/containers/current-pull-request-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {QueryRenderer, graphql} from 'react-relay';
import {Disposable} from 'event-kit';

import {autobind, CHECK_SUITE_PAGE_SIZE, CHECK_RUN_PAGE_SIZE} from '../helpers';
import {
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
} from '../prop-types';
import {RemotePropType, RemoteSetPropType, BranchSetPropType, EndpointPropType} from '../prop-types';
import IssueishListController, {BareIssueishListController} from '../controllers/issueish-list-controller';
import CreatePullRequestTile from '../views/create-pull-request-tile';
import RelayNetworkLayerManager from '../relay-network-layer-manager';
Expand All @@ -30,7 +28,6 @@ export default class CurrentPullRequestContainer extends React.Component {
limit: PropTypes.number,

// Repository model attributes
remoteOperationObserver: OperationStateObserverPropType.isRequired,
remote: RemotePropType.isRequired,
remotes: RemoteSetPropType.isRequired,
branches: BranchSetPropType.isRequired,
Expand Down Expand Up @@ -120,18 +117,10 @@ export default class CurrentPullRequestContainer extends React.Component {
}

renderEmptyResult() {
this.sub.dispose();
this.sub = this.props.remoteOperationObserver.onDidComplete(() => this.forceUpdate());

return <BareIssueishListController isLoading={false} {...this.controllerProps()} />;
}

renderQueryResult({error, props, retry}) {
if (retry) {
this.sub.dispose();
this.sub = this.props.remoteOperationObserver.onDidComplete(retry);
}

renderQueryResult({error, props}) {
if (error) {
return (
<BareIssueishListController
Expand Down
5 changes: 1 addition & 4 deletions lib/containers/github-tab-container.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';
import {CompositeDisposable, Disposable} from 'event-kit';
import {Disposable} from 'event-kit';

import {GithubLoginModelPropType, RefHolderPropType} from '../prop-types';
import OperationStateObserver, {PUSH, PULL, FETCH} from '../models/operation-state-observer';
Expand Down Expand Up @@ -91,7 +91,6 @@ export default class GitHubTabContainer extends React.Component {
<GitHubTabController
{...this.props}
refresher={this.state.refresher}
remoteOperationObserver={this.state.remoteOperationObserver}

allRemotes={new RemoteSet()}
branches={new BranchSet()}
Expand All @@ -107,7 +106,6 @@ export default class GitHubTabContainer extends React.Component {
<GitHubTabController
{...this.props}
refresher={this.state.refresher}
remoteOperationObserver={this.state.remoteOperationObserver}

allRemotes={new RemoteSet()}
branches={new BranchSet()}
Expand All @@ -123,7 +121,6 @@ export default class GitHubTabContainer extends React.Component {
{...data}
{...this.props}
refresher={this.state.refresher}
remoteOperationObserver={this.state.remoteOperationObserver}
isLoading={false}
/>
);
Expand Down
10 changes: 2 additions & 8 deletions lib/containers/issueish-search-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {QueryRenderer, graphql} from 'react-relay';
import {Disposable} from 'event-kit';

import {autobind, CHECK_SUITE_PAGE_SIZE, CHECK_RUN_PAGE_SIZE} from '../helpers';
import {SearchPropType, OperationStateObserverPropType, EndpointPropType} from '../prop-types';
import {SearchPropType, EndpointPropType} from '../prop-types';
import IssueishListController, {BareIssueishListController} from '../controllers/issueish-list-controller';
import RelayNetworkLayerManager from '../relay-network-layer-manager';

Expand All @@ -17,7 +17,6 @@ export default class IssueishSearchContainer extends React.Component {
// Search model
limit: PropTypes.number,
search: SearchPropType.isRequired,
remoteOperationObserver: OperationStateObserverPropType.isRequired,

// Action methods
onOpenIssueish: PropTypes.func.isRequired,
Expand Down Expand Up @@ -89,12 +88,7 @@ export default class IssueishSearchContainer extends React.Component {
);
}

renderQueryResult({error, props, retry}) {
if (retry) {
this.sub.dispose();
this.sub = this.props.remoteOperationObserver.onDidComplete(retry);
}

renderQueryResult({error, props}) {
if (error) {
return (
<BareIssueishListController
Expand Down
9 changes: 4 additions & 5 deletions lib/containers/remote-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import PropTypes from 'prop-types';
import {QueryRenderer, graphql} from 'react-relay';

import {incrementCounter} from '../reporter-proxy';
import {
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
} from '../prop-types';
import {RemotePropType, RemoteSetPropType, BranchSetPropType, RefresherPropType, EndpointPropType} from '../prop-types';
import RelayNetworkLayerManager from '../relay-network-layer-manager';
import {UNAUTHENTICATED, INSUFFICIENT} from '../shared/keytar-strategy';
import RemoteController from '../controllers/remote-controller';
Expand All @@ -21,7 +19,7 @@ export default class RemoteContainer extends React.Component {
endpoint: EndpointPropType.isRequired,

// Repository attributes
remoteOperationObserver: OperationStateObserverPropType.isRequired,
refresher: RefresherPropType.isRequired,
pushInProgress: PropTypes.bool.isRequired,
workingDirectory: PropTypes.string,
workspace: PropTypes.object.isRequired,
Expand Down Expand Up @@ -104,6 +102,8 @@ export default class RemoteContainer extends React.Component {
}

renderWithResult({error, props, retry}, token) {
this.props.refresher.setRetryCallback(this, retry);

if (error) {
return (
<QueryErrorView
Expand All @@ -126,7 +126,6 @@ export default class RemoteContainer extends React.Component {

repository={props.repository}

remoteOperationObserver={this.props.remoteOperationObserver}
workingDirectory={this.props.workingDirectory}
workspace={this.props.workspace}
remote={this.props.remote}
Expand Down
6 changes: 3 additions & 3 deletions lib/controllers/github-tab-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from 'react';
import PropTypes from 'prop-types';

import {
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType,
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, BranchSetPropType, RefresherPropType,
} from '../prop-types';
import GitHubTabView from '../views/github-tab-view';

export default class GitHubTabController extends React.Component {
static propTypes = {
workspace: PropTypes.object.isRequired,
remoteOperationObserver: OperationStateObserverPropType.isRequired,
refresher: RefresherPropType.isRequired,
loginModel: GithubLoginModelPropType.isRequired,
rootHolder: RefHolderPropType.isRequired,

Expand Down Expand Up @@ -47,7 +47,7 @@ export default class GitHubTabController extends React.Component {
return (
<GitHubTabView
workspace={this.props.workspace}
remoteOperationObserver={this.props.remoteOperationObserver}
refresher={this.props.refresher}
loginModel={this.props.loginModel}
rootHolder={this.props.rootHolder}

Expand Down
7 changes: 1 addition & 6 deletions lib/controllers/issueish-searches-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import {shell} from 'electron';

import {
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
} from '../prop-types';
import {RemotePropType, RemoteSetPropType, BranchSetPropType, EndpointPropType} from '../prop-types';
import Search from '../models/search';
import IssueishSearchContainer from '../containers/issueish-search-container';
import CurrentPullRequestContainer from '../containers/current-pull-request-container';
Expand All @@ -31,7 +29,6 @@ export default class IssueishSearchesController extends React.Component {
workspace: PropTypes.object.isRequired,

// Repository model attributes
remoteOperationObserver: OperationStateObserverPropType.isRequired,
workingDirectory: PropTypes.string,
remote: RemotePropType.isRequired,
remotes: RemoteSetPropType.isRequired,
Expand Down Expand Up @@ -60,7 +57,6 @@ export default class IssueishSearchesController extends React.Component {
repository={this.props.repository}
token={this.props.token}
endpoint={this.props.endpoint}
remoteOperationObserver={this.props.remoteOperationObserver}
remote={this.props.remote}
remotes={this.props.remotes}
branches={this.props.branches}
Expand All @@ -79,7 +75,6 @@ export default class IssueishSearchesController extends React.Component {
token={this.props.token}
endpoint={this.props.endpoint}
search={search}
remoteOperationObserver={this.props.remoteOperationObserver}

onOpenIssueish={this.onOpenIssueish}
onOpenSearch={this.onOpenSearch}
Expand Down
6 changes: 1 addition & 5 deletions lib/controllers/remote-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import {shell} from 'electron';

import {autobind} from '../helpers';
import {incrementCounter} from '../reporter-proxy';
import {
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
} from '../prop-types';
import {RemotePropType, RemoteSetPropType, BranchSetPropType, EndpointPropType} from '../prop-types';
import IssueishSearchesController from './issueish-searches-controller';

export default class RemoteController extends React.Component {
Expand All @@ -25,7 +23,6 @@ export default class RemoteController extends React.Component {
token: PropTypes.string.isRequired,

// Repository derived attributes
remoteOperationObserver: OperationStateObserverPropType.isRequired,
workingDirectory: PropTypes.string,
workspace: PropTypes.object.isRequired,
remote: RemotePropType.isRequired,
Expand All @@ -49,7 +46,6 @@ export default class RemoteController extends React.Component {
endpoint={this.props.endpoint}
token={this.props.token}

remoteOperationObserver={this.props.remoteOperationObserver}
workingDirectory={this.props.workingDirectory}
repository={this.props.repository}

Expand Down
6 changes: 6 additions & 0 deletions lib/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export const OperationStateObserverPropType = PropTypes.shape({
dispose: PropTypes.func.isRequired,
});

export const RefresherPropType = PropTypes.shape({
setRetryCallback: PropTypes.func.isRequired,
trigger: PropTypes.func.isRequired,
deregister: PropTypes.func.isRequired,
});

export const IssueishPropType = PropTypes.shape({
getNumber: PropTypes.func.isRequired,
getTitle: PropTypes.func.isRequired,
Expand Down
6 changes: 3 additions & 3 deletions lib/views/github-tab-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';

import {
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, RemotePropType, BranchSetPropType, BranchPropType,
OperationStateObserverPropType,
RefresherPropType,
} from '../prop-types';
import LoadingView from './loading-view';
import RemoteSelectorView from './remote-selector-view';
Expand All @@ -16,7 +16,7 @@ import RemoteContainer from '../containers/remote-container';
export default class GitHubTabView extends React.Component {
static propTypes = {
workspace: PropTypes.object.isRequired,
remoteOperationObserver: OperationStateObserverPropType.isRequired,
refresher: RefresherPropType.isRequired,
loginModel: GithubLoginModelPropType.isRequired,
rootHolder: RefHolderPropType.isRequired,

Expand Down Expand Up @@ -83,7 +83,7 @@ export default class GitHubTabView extends React.Component {
loginModel={this.props.loginModel}
endpoint={this.props.currentRemote.getEndpoint()}

remoteOperationObserver={this.props.remoteOperationObserver}
refresher={this.props.refresher}
pushInProgress={this.props.pushInProgress}
workingDirectory={this.props.workingDirectory}
workspace={this.props.workspace}
Expand Down
19 changes: 0 additions & 19 deletions test/containers/current-pull-request-container.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {shallow} from 'enzyme';
import {QueryRenderer} from 'react-relay';

import CurrentPullRequestContainer from '../../lib/containers/current-pull-request-container';
import {ManualStateObserver} from '../helpers';
import {queryBuilder} from '../builder/graphql/query';
import Remote from '../../lib/models/remote';
import RemoteSet from '../../lib/models/remote-set';
Expand All @@ -15,12 +14,6 @@ import repositoryQuery from '../../lib/containers/__generated__/remoteContainerQ
import currentQuery from '../../lib/containers/__generated__/currentPullRequestContainerQuery.graphql.js';

describe('CurrentPullRequestContainer', function() {
let observer;

beforeEach(function() {
observer = new ManualStateObserver();
});

function buildApp(overrideProps = {}) {
const origin = new Remote('origin', '[email protected]:atom/github.git');
const upstreamBranch = Branch.createRemoteTracking('refs/remotes/origin/master', 'origin', 'refs/heads/master');
Expand All @@ -37,7 +30,6 @@ describe('CurrentPullRequestContainer', function() {

token="1234"
endpoint={origin.getEndpoint()}
remoteOperationObserver={observer}
remote={origin}
remotes={remotes}
branches={branches}
Expand Down Expand Up @@ -209,15 +201,4 @@ describe('CurrentPullRequestContainer', function() {
assert.isTrue(filterFn({getHeadRepositoryID: () => '100'}));
assert.isFalse(filterFn({getHeadRepositoryID: () => '12'}));
});

it('performs the query again when a remote operation completes', function() {
const wrapper = shallow(buildApp());

const props = queryBuilder(currentQuery).build();
const retry = sinon.spy();
wrapper.find(QueryRenderer).renderProp('render')({error: null, props, retry});

observer.trigger();
assert.isTrue(retry.called);
});
});
Loading

0 comments on commit be9284c

Please sign in to comment.