forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge-conflict-list-item-view.js
80 lines (71 loc) · 2.8 KB
/
merge-conflict-list-item-view.js
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
import React from 'react';
import PropTypes from 'prop-types';
import {CompositeDisposable} from 'event-kit';
import {classNameForStatus} from '../helpers';
import {MergeConflictItemPropType} from '../prop-types';
import RefHolder from '../models/ref-holder';
export default class MergeConflictListItemView extends React.Component {
static propTypes = {
mergeConflict: MergeConflictItemPropType.isRequired,
selected: PropTypes.bool.isRequired,
remainingConflicts: PropTypes.number,
registerItemElement: PropTypes.func.isRequired,
};
constructor(props) {
super(props);
this.refItem = new RefHolder();
this.subs = new CompositeDisposable(
this.refItem.observe(item => this.props.registerItemElement(this.props.mergeConflict, item)),
);
}
render() {
const {mergeConflict, selected, ...others} = this.props;
delete others.remainingConflicts;
delete others.registerItemElement;
const fileStatus = classNameForStatus[mergeConflict.status.file];
const oursStatus = classNameForStatus[mergeConflict.status.ours];
const theirsStatus = classNameForStatus[mergeConflict.status.theirs];
const className = selected ? 'is-selected' : '';
return (
<div
ref={this.refItem.setter}
{...others}
className={`github-MergeConflictListView-item is-${fileStatus} ${className}`}>
<div className="github-FilePatchListView-item github-FilePatchListView-pathItem">
<span className={`github-FilePatchListView-icon icon icon-diff-${fileStatus} status-${fileStatus}`} />
<span className="github-FilePatchListView-path">{mergeConflict.filePath}</span>
<span className={'github-FilePatchListView ours-theirs-info'}>
<span className={`github-FilePatchListView-icon icon icon-diff-${oursStatus}`} />
<span className={`github-FilePatchListView-icon icon icon-diff-${theirsStatus}`} />
</span>
</div>
<div className="github-FilePatchListView-item github-FilePatchListView-resolutionItem">
{this.renderRemainingConflicts()}
</div>
</div>
);
}
renderRemainingConflicts() {
if (this.props.remainingConflicts === 0) {
return (
<span className="icon icon-check github-RemainingConflicts text-success">
ready
</span>
);
} else if (this.props.remainingConflicts !== undefined) {
const pluralConflicts = this.props.remainingConflicts === 1 ? '' : 's';
return (
<span className="github-RemainingConflicts text-warning">
{this.props.remainingConflicts} conflict{pluralConflicts} remaining
</span>
);
} else {
return (
<span className="github-RemainingConflicts text-subtle">calculating</span>
);
}
}
componentWillUnmount() {
this.subs.dispose();
}
}