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

Commit

Permalink
Merge 682867c into 555c144
Browse files Browse the repository at this point in the history
  • Loading branch information
smashwilson committed Nov 1, 2018
2 parents 555c144 + 682867c commit 5fd2952
Show file tree
Hide file tree
Showing 53 changed files with 1,938 additions and 300 deletions.
2 changes: 1 addition & 1 deletion docs/react-component-classification.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a high-level summary of the organization and implementation of our React

**Items** are intended to be used as top-level components within subtrees that are rendered into some [Portal](https://reactjs.org/docs/portals.html) and passed to the Atom API, like pane items, dock items, or tooltips. They are mostly responsible for implementing the [Atom "item" contract](https://github.com/atom/atom/blob/a3631f0dafac146185289ac5e37eaff17b8b0209/src/workspace.js#L29-L174).

These live within [`lib/items/`](/lib/items), are tested within [`test/items/`](/test/items), and are named with an `Item` suffix. Examples: `PullRequestDetailItem`, `FilePatchItem`.
These live within [`lib/items/`](/lib/items), are tested within [`test/items/`](/test/items), and are named with an `Item` suffix. Examples: `PullRequestDetailItem`, `ChangedFileItem`.

## Containers

Expand Down
5 changes: 5 additions & 0 deletions keymaps/git.cson
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
'shift-tab': 'core:focus-previous'
'o': 'github:open-file'
'left': 'core:move-left'
'cmd-left': 'core:move-left'

'.github-CommitView button':
'tab': 'core:focus-next'
'shift-tab': 'core:focus-previous'

'.github-StagingView.unstaged-changes-focused':
'cmd-backspace': 'github:discard-changes-in-selected-files'
Expand Down
2 changes: 1 addition & 1 deletion lib/atom/uri-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function dashEscape(raw) {
* Reverse the escaping performed by `dashEscape` by un-doubling `-` characters.
*/
function dashUnescape(escaped) {
return escaped.replace('--', '-');
return escaped.replace(/--/g, '-');
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import yubikiri from 'yubikiri';
import {autobind} from '../helpers';
import ObserveModel from '../views/observe-model';
import LoadingView from '../views/loading-view';
import FilePatchController from '../controllers/file-patch-controller';
import MultiFilePatchController from '../controllers/multi-file-patch-controller';

export default class FilePatchContainer extends React.Component {
export default class ChangedFileContainer extends React.Component {
static propTypes = {
repository: PropTypes.object.isRequired,
stagingStatus: PropTypes.oneOf(['staged', 'unstaged']),
Expand All @@ -30,8 +30,10 @@ export default class FilePatchContainer extends React.Component {
}

fetchData(repository) {
const staged = this.props.stagingStatus === 'staged';

return yubikiri({
filePatch: repository.getFilePatchForPath(this.props.relPath, {staged: this.props.stagingStatus === 'staged'}),
multiFilePatch: repository.getChangedFilePatch(this.props.relPath, {staged}),
isPartiallyStaged: repository.isPartiallyStaged(this.props.relPath),
hasUndoHistory: repository.hasDiscardHistory(this.props.relPath),
});
Expand All @@ -51,10 +53,11 @@ export default class FilePatchContainer extends React.Component {
}

return (
<FilePatchController
filePatch={data.filePatch}
<MultiFilePatchController
multiFilePatch={data.multiFilePatch}
isPartiallyStaged={data.isPartiallyStaged}
hasUndoHistory={data.hasUndoHistory}
useEditorAutoHeight={false}
{...this.props}
/>
);
Expand Down
41 changes: 41 additions & 0 deletions lib/containers/commit-preview-container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import PropTypes from 'prop-types';
import yubikiri from 'yubikiri';

import ObserveModel from '../views/observe-model';
import LoadingView from '../views/loading-view';
import MultiFilePatchController from '../controllers/multi-file-patch-controller';

export default class CommitPreviewContainer extends React.Component {
static propTypes = {
repository: PropTypes.object.isRequired,
}

fetchData = repository => {
return yubikiri({
multiFilePatch: repository.getStagedChangesPatch(),
});
}

render() {
return (
<ObserveModel model={this.props.repository} fetchData={this.fetchData}>
{this.renderResult}
</ObserveModel>
);
}

renderResult = data => {
if (this.props.repository.isLoading() || data === null) {
return <LoadingView />;
}

return (
<MultiFilePatchController
useEditorAutoHeight={true}
{...data}
{...this.props}
/>
);
}
}
40 changes: 35 additions & 5 deletions lib/controllers/commit-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import fs from 'fs-extra';

import CommitView from '../views/commit-view';
import RefHolder from '../models/ref-holder';
import CommitPreviewItem from '../items/commit-preview-item';
import {AuthorPropType, UserStorePropType} from '../prop-types';
import {watchWorkspaceItem} from '../watch-workspace-item';
import {autobind} from '../helpers';
import {addEvent} from '../reporter-proxy';

Expand Down Expand Up @@ -43,7 +45,8 @@ export default class CommitController extends React.Component {

constructor(props, context) {
super(props, context);
autobind(this, 'commit', 'handleMessageChange', 'toggleExpandedCommitMessageEditor', 'grammarAdded');
autobind(this, 'commit', 'handleMessageChange', 'toggleExpandedCommitMessageEditor', 'grammarAdded',
'toggleCommitPreview');

this.subscriptions = new CompositeDisposable();
this.refCommitView = new RefHolder();
Expand All @@ -52,6 +55,14 @@ export default class CommitController extends React.Component {
this.subscriptions.add(
this.commitMessageBuffer.onDidChange(this.handleMessageChange),
);

this.previewWatcher = watchWorkspaceItem(
this.props.workspace,
CommitPreviewItem.buildURI(this.props.repository.getWorkingDirectoryPath()),
this,
'commitPreviewOpen',
);
this.subscriptions.add(this.previewWatcher);
}

componentDidMount() {
Expand Down Expand Up @@ -110,6 +121,8 @@ export default class CommitController extends React.Component {
userStore={this.props.userStore}
selectedCoAuthors={this.props.selectedCoAuthors}
updateSelectedCoAuthors={this.props.updateSelectedCoAuthors}
toggleCommitPreview={this.toggleCommitPreview}
commitPreviewOpen={this.state.commitPreviewOpen}
/>
);
}
Expand All @@ -120,6 +133,12 @@ export default class CommitController extends React.Component {
} else {
this.commitMessageBuffer.setTextViaDiff(this.getCommitMessage());
}

if (prevProps.repository !== this.props.repository) {
this.previewWatcher.setPattern(
CommitPreviewItem.buildURI(this.props.repository.getWorkingDirectoryPath()),
);
}
}

componentWillUnmount() {
Expand Down Expand Up @@ -249,12 +268,23 @@ export default class CommitController extends React.Component {
return this.refCommitView.map(view => view.setFocus(focus)).getOr(false);
}

hasFocus() {
return this.refCommitView.map(view => view.hasFocus()).getOr(false);
advanceFocus(...args) {
return this.refCommitView.map(view => view.advanceFocus(...args)).getOr(false);
}

hasFocusEditor() {
return this.refCommitView.map(view => view.hasFocusEditor()).getOr(false);
retreatFocus(...args) {
return this.refCommitView.map(view => view.retreatFocus(...args)).getOr(false);
}

hasFocusAtBeginning() {
return this.refCommitView.map(view => view.hasFocusAtBeginning()).getOr(false);
}

toggleCommitPreview() {
addEvent('toggle-commit-preview', {package: 'github'});
return this.props.workspace.toggle(
CommitPreviewItem.buildURI(this.props.repository.getWorkingDirectoryPath()),
);
}
}

Expand Down
14 changes: 8 additions & 6 deletions lib/controllers/file-patch-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from 'path';

import {autobind, equalSets} from '../helpers';
import {addEvent} from '../reporter-proxy';
import FilePatchItem from '../items/file-patch-item';
import ChangedFileItem from '../items/changed-file-item';
import FilePatchView from '../views/file-patch-view';

export default class FilePatchController extends React.Component {
Expand All @@ -13,7 +13,7 @@ export default class FilePatchController extends React.Component {
stagingStatus: PropTypes.oneOf(['staged', 'unstaged']),
relPath: PropTypes.string.isRequired,
filePatch: PropTypes.object.isRequired,
hasUndoHistory: PropTypes.bool.isRequired,
hasUndoHistory: PropTypes.bool,

workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
Expand All @@ -22,9 +22,11 @@ export default class FilePatchController extends React.Component {
config: PropTypes.object.isRequired,

destroy: PropTypes.func.isRequired,
discardLines: PropTypes.func.isRequired,
undoLastDiscard: PropTypes.func.isRequired,
surfaceFileAtPath: PropTypes.func.isRequired,
discardLines: PropTypes.func,
undoLastDiscard: PropTypes.func,
surfaceFileAtPath: PropTypes.func,
handleClick: PropTypes.func,
isActive: PropTypes.bool,
}

constructor(props) {
Expand Down Expand Up @@ -96,7 +98,7 @@ export default class FilePatchController extends React.Component {
diveIntoMirrorPatch() {
const mirrorStatus = this.withStagingStatus({staged: 'unstaged', unstaged: 'staged'});
const workingDirectory = this.props.repository.getWorkingDirectoryPath();
const uri = FilePatchItem.buildURI(this.props.relPath, workingDirectory, mirrorStatus);
const uri = ChangedFileItem.buildURI(this.props.relPath, workingDirectory, mirrorStatus);

this.props.destroy();
return this.props.workspace.open(uri);
Expand Down
2 changes: 1 addition & 1 deletion lib/controllers/github-tab-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class GitHubTabController extends React.Component {
allRemotes: RemoteSetPropType.isRequired,
branches: BranchSetPropType.isRequired,
selectedRemoteName: PropTypes.string,
aheadCount: PropTypes.number.isRequired,
aheadCount: PropTypes.number,
pushInProgress: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
}
Expand Down
52 changes: 52 additions & 0 deletions lib/controllers/multi-file-patch-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, {Fragment} from 'react';

import {MultiFilePatchPropType, RefHolderPropType} from '../prop-types';
import FilePatchController from '../controllers/file-patch-controller';
import {autobind} from '../helpers';

export default class MultiFilePatchController extends React.Component {
static propTypes = {
multiFilePatch: MultiFilePatchPropType.isRequired,
refInitialFocus: RefHolderPropType,
}

constructor(props) {
super(props);
autobind(this, 'handleMouseDown');
const firstFilePatch = this.props.multiFilePatch.getFilePatches()[0];

this.state = {activeFilePatch: firstFilePatch ? firstFilePatch.getPath() : null};
}

handleMouseDown(relPath) {
this.setState({activeFilePatch: relPath});
}

render() {
return (
<Fragment>
{this.props.multiFilePatch.getFilePatches().map(filePatch => {
const relPath = filePatch.getPath();
const isActive = this.state.activeFilePatch === relPath;
let props = this.props;
if (!isActive) {
props = {...props};
delete props.refInitialFocus;
}

return (
<FilePatchController
key={relPath}
relPath={relPath}
stagingStatus={'staged'}
{...props}
filePatch={filePatch}
handleMouseDown={this.handleMouseDown}
isActive={isActive}
/>
);
})}
</Fragment>
);
}
}
49 changes: 40 additions & 9 deletions lib/controllers/root-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import InitDialog from '../views/init-dialog';
import CredentialDialog from '../views/credential-dialog';
import Commands, {Command} from '../atom/commands';
import GitTimingsView from '../views/git-timings-view';
import FilePatchItem from '../items/file-patch-item';
import ChangedFileItem from '../items/changed-file-item';
import IssueishDetailItem from '../items/issueish-detail-item';
import CommitPreviewItem from '../items/commit-preview-item';
import GitTabItem from '../items/git-tab-item';
import GitHubTabItem from '../items/github-tab-item';
import StatusBarTileController from './status-bar-tile-controller';
Expand Down Expand Up @@ -128,6 +129,15 @@ export default class RootController extends React.Component {
return (
<Commands registry={this.props.commandRegistry} target="atom-workspace">
{devMode && <Command command="github:install-react-dev-tools" callback={this.installReactDevTools} />}
{devMode && (
<Command
command="github:toggle-commit-preview"
callback={() => {
const workdir = this.props.repository.getWorkingDirectoryPath();
this.props.workspace.toggle(CommitPreviewItem.buildURI(workdir));
}}
/>
)}
<Command command="github:logout" callback={this.clearGithubToken} />
<Command command="github:show-waterfall-diagnostics" callback={this.showWaterfallDiagnostics} />
<Command command="github:show-cache-diagnostics" callback={this.showCacheDiagnostics} />
Expand Down Expand Up @@ -316,9 +326,9 @@ export default class RootController extends React.Component {
</PaneItem>
<PaneItem
workspace={this.props.workspace}
uriPattern={FilePatchItem.uriPattern}>
uriPattern={ChangedFileItem.uriPattern}>
{({itemHolder, params}) => (
<FilePatchItem
<ChangedFileItem
ref={itemHolder.setter}

workdirContextPool={this.props.workdirContextPool}
Expand All @@ -338,6 +348,27 @@ export default class RootController extends React.Component {
/>
)}
</PaneItem>
<PaneItem
workspace={this.props.workspace}
uriPattern={CommitPreviewItem.uriPattern}
className="github-CommitPreview-root">
{({itemHolder, params}) => (
<CommitPreviewItem
ref={itemHolder.setter}

workdirContextPool={this.props.workdirContextPool}
workingDirectory={params.workingDirectory}
workspace={this.props.workspace}
commands={this.props.commandRegistry}
keymaps={this.props.keymaps}
tooltips={this.props.tooltips}
config={this.props.config}
discardLines={this.discardLines}
undoLastDiscard={this.undoLastDiscard}
surfaceFileAtPath={this.surfaceFromFileAtPath}
/>
)}
</PaneItem>
<PaneItem workspace={this.props.workspace} uriPattern={IssueishDetailItem.uriPattern}>
{({itemHolder, params}) => (
<IssueishDetailItem
Expand Down Expand Up @@ -580,14 +611,14 @@ export default class RootController extends React.Component {
pane.splitDown();
}
const lineNum = editor.getCursorBufferPosition().row + 1;
const filePatchItem = await this.props.workspace.open(
FilePatchItem.buildURI(filePath, repoPath, stagingStatus),
const item = await this.props.workspace.open(
ChangedFileItem.buildURI(filePath, repoPath, stagingStatus),
{pending: true, activatePane: true, activateItem: true},
);
await filePatchItem.getRealItemPromise();
await filePatchItem.getFilePatchLoadedPromise();
filePatchItem.goToDiffLine(lineNum);
filePatchItem.focus();
await item.getRealItemPromise();
await item.getFilePatchLoadedPromise();
item.goToDiffLine(lineNum);
item.focus();
} else {
throw new Error(`${absFilePath} does not belong to repo ${repoPath}`);
}
Expand Down
Loading

0 comments on commit 5fd2952

Please sign in to comment.