Skip to content

Commit

Permalink
feat(issue): Disable merge button if not possible (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinesedfan authored and Houssein Djirdeh committed Oct 8, 2017
1 parent 554e1cc commit 310ecdd
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 97 deletions.
113 changes: 62 additions & 51 deletions src/components/issue-description.component.js
Expand Up @@ -73,6 +73,7 @@ export class IssueDescription extends Component {
props: {
issue: Object,
diff: string,
isMergeable: boolean,
isMerged: boolean,
isPendingDiff: boolean,
isPendingCheckMerge: boolean,
Expand All @@ -92,6 +93,7 @@ export class IssueDescription extends Component {
const {
diff,
issue,
isMergeable,
isMerged,
isPendingDiff,
isPendingCheckMerge,
Expand All @@ -113,7 +115,7 @@ export class IssueDescription extends Component {

return (
<View style={(styles.container, styles.borderBottom)}>
{issue.repository_url &&
{issue.repository_url && (
<ListItem
title={issue.repository_url.replace(`${v3.root}/repos/`, '')}
titleStyle={styles.titleSmall}
Expand All @@ -125,7 +127,8 @@ export class IssueDescription extends Component {
}}
onPress={() => onRepositoryPress(issue.repository_url)}
hideChevron
/>}
/>
)}

<View style={styles.headerContainer}>
<ListItem
Expand All @@ -144,67 +147,75 @@ export class IssueDescription extends Component {

{!issue.pull_request ||
(issue.pull_request &&
!isPendingCheckMerge &&
<StateBadge
style={styles.badge}
issue={issue}
isMerged={isMerged && issue.pull_request}
language={language}
/>)}
!isPendingCheckMerge && (
<StateBadge
style={styles.badge}
issue={issue}
isMerged={isMerged && issue.pull_request}
language={language}
/>
))}
</View>

{issue.pull_request &&
{issue.pull_request && (
<View style={styles.diffBlocksContainer}>
{isPendingDiff &&
<ActivityIndicator animating={isPendingDiff} size="small" />}
{isPendingDiff && (
<ActivityIndicator animating={isPendingDiff} size="small" />
)}

{!isPendingDiff &&
(lineAdditions !== 0 || lineDeletions !== 0) &&
<DiffBlocks
additions={lineAdditions}
deletions={lineDeletions}
showNumbers
onPress={() =>
navigation.navigate('PullDiff', {
title: translate('repository.pullDiff.title', language),
language,
diff,
})}
/>}
</View>}
(lineAdditions !== 0 || lineDeletions !== 0) && (
<DiffBlocks
additions={lineAdditions}
deletions={lineDeletions}
showNumbers
onPress={() =>
navigation.navigate('PullDiff', {
title: translate('repository.pullDiff.title', language),
language,
diff,
})}
/>
)}
</View>
)}

{issue.labels &&
issue.labels.length > 0 &&
<View style={styles.labelButtonGroup}>
{this.renderLabelButtons(issue.labels)}
</View>}
issue.labels.length > 0 && (
<View style={styles.labelButtonGroup}>
{this.renderLabelButtons(issue.labels)}
</View>
)}
{issue.assignees &&
issue.assignees.length > 0 &&
<View style={styles.assigneesSection}>
<MembersList
title={translate('issue.main.assignees', language)}
members={issue.assignees}
containerStyle={{ marginTop: 0, paddingTop: 0, paddingLeft: 0 }}
smallTitle
navigation={navigation}
/>
</View>}
issue.assignees.length > 0 && (
<View style={styles.assigneesSection}>
<MembersList
title={translate('issue.main.assignees', language)}
members={issue.assignees}
containerStyle={{ marginTop: 0, paddingTop: 0, paddingLeft: 0 }}
smallTitle
navigation={navigation}
/>
</View>
)}

{issue.pull_request &&
!isMerged &&
issue.state === 'open' &&
userHasPushPermission &&
<View style={styles.mergeButtonContainer}>
<Button
type="success"
icon={{ name: 'git-merge', type: 'octicon' }}
onPress={() =>
navigation.navigate('PullMerge', {
title: translate('issue.pullMerge.title', language),
})}
title={translate('issue.main.mergeButton', language)}
/>
</View>}
userHasPushPermission && (
<View style={styles.mergeButtonContainer}>
<Button
type={isMergeable ? 'success' : 'default'}
icon={{ name: 'git-merge', type: 'octicon' }}
disabled={!isMergeable}
onPress={() =>
navigation.navigate('PullMerge', {
title: translate('issue.pullMerge.title', language),
})}
title={translate('issue.main.mergeButton', language)}
/>
</View>
)}
</View>
);
}
Expand Down
25 changes: 25 additions & 0 deletions src/issue/issue.action.js
Expand Up @@ -17,6 +17,7 @@ import {
CHANGE_LOCK_STATUS,
GET_ISSUE_DIFF,
GET_ISSUE_MERGE_STATUS,
GET_PULL_REQUEST_FROM_URL,
MERGE_PULL_REQUEST,
GET_ISSUE_FROM_URL,
SUBMIT_NEW_ISSUE,
Expand Down Expand Up @@ -69,10 +70,34 @@ const getMergeStatus = (repo, issueNum) => {
};
};

const getPullRequest = url => {
return (dispatch, getState) => {
const accessToken = getState().auth.accessToken;

dispatch({ type: GET_PULL_REQUEST_FROM_URL.PENDING });

return v3
.getJson(url, accessToken)
.then(pr => {
dispatch({
type: GET_PULL_REQUEST_FROM_URL.SUCCESS,
payload: pr,
});
})
.catch(error => {
dispatch({
type: GET_PULL_REQUEST_FROM_URL.ERROR,
payload: error,
});
});
};
};

const getPullRequestDetails = issue => {
return (dispatch, getState) => {
const repoFullName = getState().repository.repository.full_name;

dispatch(getPullRequest(issue.pull_request.url));
dispatch(getDiff(issue.pull_request.url));
dispatch(getMergeStatus(repoFullName, issue.number));
};
Expand Down
19 changes: 19 additions & 0 deletions src/issue/issue.reducer.js
Expand Up @@ -8,6 +8,7 @@ import {
CHANGE_LOCK_STATUS,
GET_ISSUE_DIFF,
GET_ISSUE_MERGE_STATUS,
GET_PULL_REQUEST_FROM_URL,
MERGE_PULL_REQUEST,
GET_ISSUE_FROM_URL,
SUBMIT_NEW_ISSUE,
Expand All @@ -16,6 +17,7 @@ import {
const initialState = {
issue: {},
comments: [],
pr: {},
diff: '',
isMerged: false,
isPendingComments: false,
Expand Down Expand Up @@ -222,6 +224,23 @@ export const issueReducer = (state = initialState, action = {}) => {
error: action.payload,
isPendingMerging: false,
};
case GET_PULL_REQUEST_FROM_URL.PENDING:
return {
...state,
isPendingPR: true,
};
case GET_PULL_REQUEST_FROM_URL.SUCCESS:
return {
...state,
pr: action.payload,
isPendingPR: false,
};
case GET_PULL_REQUEST_FROM_URL.ERROR:
return {
...state,
error: action.payload,
isPendingPR: false,
};
case GET_ISSUE_FROM_URL.PENDING:
return {
...state,
Expand Down
3 changes: 3 additions & 0 deletions src/issue/issue.type.js
Expand Up @@ -9,6 +9,9 @@ export const EDIT_ISSUE_BODY = createActionSet('EDIT_ISSUE_BODY');
export const CHANGE_LOCK_STATUS = createActionSet('CHANGE_LOCK_STATUS');
export const GET_ISSUE_DIFF = createActionSet('GET_ISSUE_DIFF');
export const GET_ISSUE_MERGE_STATUS = createActionSet('GET_ISSUE_MERGE_STATUS');
export const GET_PULL_REQUEST_FROM_URL = createActionSet(
'GET_PULL_REQUEST_FROM_URL'
);
export const MERGE_PULL_REQUEST = createActionSet('MERGE_PULL_REQUEST');
export const GET_ISSUE_FROM_URL = createActionSet('GET_ISSUE_FROM_URL');
export const SUBMIT_NEW_ISSUE = createActionSet('SUBMIT_NEW_ISSUE');
95 changes: 49 additions & 46 deletions src/issue/screens/issue.screen.js
Expand Up @@ -36,6 +36,7 @@ const mapStateToProps = state => ({
contributors: state.repository.contributors,
issue: state.issue.issue,
diff: state.issue.diff,
pr: state.issue.pr,
isMerged: state.issue.isMerged,
comments: state.issue.comments,
isPendingDiff: state.issue.isPendingDiff,
Expand Down Expand Up @@ -94,6 +95,7 @@ class Issue extends Component {
deleteIssueComment: Function,
diff: string,
issue: Object,
pr: Object,
isMerged: boolean,
authUser: Object,
repository: Object,
Expand Down Expand Up @@ -158,22 +160,19 @@ class Issue extends Component {
getIssueFromUrl,
} = this.props;

const issueParam = navigation.state.params.issue;
const issueURLParam = navigation.state.params.issueURL;
const issueCommentsURL = `${navigation.state.params.issueURL}/comments`;
const params = navigation.state.params;
const issueURL = params.issueURL || params.issue.url;
const issueRepository = issueURL
.replace(`${v3.root}/repos/`, '')
.replace(/([^/]+\/[^/]+)\/issues\/\d+$/, '$1');

Promise.all([
getIssueFromUrl(issueURLParam || issueParam.url),
getIssueComments(
issueURLParam ? issueCommentsURL : issueParam.comments_url
),
getIssueFromUrl(issueURL),
getIssueComments(`${issueURL}/comments`),
]).then(() => {
const issue = this.props.issue;

if (
repository.full_name !==
issue.repository_url.replace(`${v3.root}/repos/`, '')
) {
if (repository.full_name !== issueRepository) {
Promise.all([
getRepository(issue.repository_url),
getContributors(this.getContributorsLink(issue.repository_url)),
Expand Down Expand Up @@ -236,6 +235,7 @@ class Issue extends Component {
renderHeader = () => {
const {
issue,
pr,
diff,
isMerged,
isPendingDiff,
Expand All @@ -248,6 +248,7 @@ class Issue extends Component {
<IssueDescription
issue={issue}
diff={diff}
isMergeable={pr.mergeable}
isMerged={isMerged}
isPendingDiff={isPendingDiff}
isPendingCheckMerge={isPendingCheckMerge}
Expand Down Expand Up @@ -308,44 +309,46 @@ class Issue extends Component {

return (
<ViewContainer>
{isShowLoadingContainer &&
<LoadingContainer animating={isShowLoadingContainer} center />}
{isShowLoadingContainer && (
<LoadingContainer animating={isShowLoadingContainer} center />
)}

{!isPendingComments &&
!isPendingIssue &&
issue &&
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={'padding'}
keyboardVerticalOffset={Platform.select({
ios: 65,
android: -200,
})}
>
<FlatList
ref={ref => {
this.commentsList = ref;
}}
refreshing={isLoadingData}
onRefresh={this.getIssueInformation}
contentContainerStyle={{ flexGrow: 1 }}
ListHeaderComponent={this.renderHeader}
removeClippedSubviews={false}
data={fullComments}
keyExtractor={this.keyExtractor}
renderItem={this.renderItem}
/>

<CommentInput
users={fullUsers}
userHasPushPermission={
navigation.state.params.userHasPushPermission
}
issueLocked={issue.locked}
language={language}
onSubmit={this.postComment}
/>
</KeyboardAvoidingView>}
issue && (
<KeyboardAvoidingView
style={{ flex: 1 }}
behavior={'padding'}
keyboardVerticalOffset={Platform.select({
ios: 65,
android: -200,
})}
>
<FlatList
ref={ref => {
this.commentsList = ref;
}}
refreshing={isLoadingData}
onRefresh={this.getIssueInformation}
contentContainerStyle={{ flexGrow: 1 }}
ListHeaderComponent={this.renderHeader}
removeClippedSubviews={false}
data={fullComments}
keyExtractor={this.keyExtractor}
renderItem={this.renderItem}
/>

<CommentInput
users={fullUsers}
userHasPushPermission={
navigation.state.params.userHasPushPermission
}
issueLocked={issue.locked}
language={language}
onSubmit={this.postComment}
/>
</KeyboardAvoidingView>
)}
</ViewContainer>
);
}
Expand Down

0 comments on commit 310ecdd

Please sign in to comment.