This repository was archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathopen-commit-dialog.js
More file actions
112 lines (94 loc) · 2.79 KB
/
open-commit-dialog.js
File metadata and controls
112 lines (94 loc) · 2.79 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
import React from 'react';
import PropTypes from 'prop-types';
import {TextBuffer} from 'atom';
import CommitDetailItem from '../items/commit-detail-item';
import {GitError} from '../git-shell-out-strategy';
import DialogView from './dialog-view';
import TabGroup from '../tab-group';
import {TabbableTextEditor} from './tabbable';
import {addEvent} from '../reporter-proxy';
export default class OpenCommitDialog extends React.Component {
static propTypes = {
// Model
request: PropTypes.shape({
getParams: PropTypes.func.isRequired,
accept: PropTypes.func.isRequired,
cancel: PropTypes.func.isRequired,
}).isRequired,
inProgress: PropTypes.bool,
error: PropTypes.instanceOf(Error),
// Atom environment
workspace: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
}
constructor(props) {
super(props);
this.ref = new TextBuffer();
this.sub = this.ref.onDidChange(this.didChangeRef);
this.state = {
acceptEnabled: false,
};
this.tabGroup = new TabGroup();
}
render() {
return (
<DialogView
acceptEnabled={this.state.acceptEnabled}
acceptClassName="icon icon-commit"
acceptText="Open commit"
accept={this.accept}
cancel={this.props.request.cancel}
tabGroup={this.tabGroup}
inProgress={this.props.inProgress}
error={this.props.error}
workspace={this.props.workspace}
commands={this.props.commands}>
<label className="github-DialogLabel github-CommitRef">
Commit sha or ref:
<TabbableTextEditor
tabGroup={this.tabGroup}
commands={this.props.commands}
autofocus
mini
buffer={this.ref}
/>
</label>
</DialogView>
);
}
componentDidMount() {
this.tabGroup.autofocus();
}
componentWillUnmount() {
this.sub.dispose();
}
accept = () => {
const ref = this.ref.getText();
if (ref.length === 0) {
return Promise.resolve();
}
return this.props.request.accept(ref);
}
didChangeRef = () => {
const enabled = !this.ref.isEmpty();
if (this.state.acceptEnabled !== enabled) {
this.setState({acceptEnabled: enabled});
}
}
}
export async function openCommitDetailItem(ref, {workspace, repository}) {
try {
await repository.getCommit(ref);
} catch (error) {
if (error instanceof GitError && error.code === 128) {
error.userMessage = 'There is no commit associated with that reference.';
}
throw error;
}
const item = await workspace.open(
CommitDetailItem.buildURI(repository.getWorkingDirectoryPath(), ref),
{searchAllPanes: true},
);
addEvent('open-commit-in-pane', {package: 'github', from: OpenCommitDialog.name});
return item;
}