Remove related links in MR widget when empty state

This commit is contained in:
Clement Ho 2017-12-19 17:50:38 +00:00 committed by Jacob Schatz
parent bd875692f0
commit 0a0a62c936
7 changed files with 84 additions and 14 deletions

View file

@ -62,7 +62,7 @@ export default {
return this.mr.hasCI;
},
shouldRenderRelatedLinks() {
return !!this.mr.relatedLinks;
return !!this.mr.relatedLinks && !this.mr.isNothingToMergeState;
},
shouldRenderDeployments() {
return this.mr.deployments.length;

View file

@ -1,30 +1,32 @@
import { stateKey } from './state_maps';
export default function deviseState(data) {
if (data.project_archived) {
return 'archived';
return stateKey.archived;
} else if (data.branch_missing) {
return 'missingBranch';
return stateKey.missingBranch;
} else if (!data.commits_count) {
return 'nothingToMerge';
return stateKey.nothingToMerge;
} else if (this.mergeStatus === 'unchecked') {
return 'checking';
return stateKey.checking;
} else if (data.has_conflicts) {
return 'conflicts';
return stateKey.conflicts;
} else if (data.work_in_progress) {
return 'workInProgress';
return stateKey.workInProgress;
} else if (this.onlyAllowMergeIfPipelineSucceeds && this.isPipelineFailed) {
return 'pipelineFailed';
return stateKey.pipelineFailed;
} else if (this.hasMergeableDiscussionsState) {
return 'unresolvedDiscussions';
return stateKey.unresolvedDiscussions;
} else if (this.isPipelineBlocked) {
return 'pipelineBlocked';
return stateKey.pipelineBlocked;
} else if (this.hasSHAChanged) {
return 'shaMismatch';
return stateKey.shaMismatch;
} else if (this.mergeWhenPipelineSucceeds) {
return this.mergeError ? 'autoMergeFailed' : 'mergeWhenPipelineSucceeds';
return this.mergeError ? stateKey.autoMergeFailed : stateKey.mergeWhenPipelineSucceeds;
} else if (!this.canMerge) {
return 'notAllowedToMerge';
return stateKey.notAllowedToMerge;
} else if (this.canBeMerged) {
return 'readyToMerge';
return stateKey.readyToMerge;
}
return null;
}

View file

@ -1,5 +1,6 @@
import Timeago from 'timeago.js';
import { getStateKey } from '../dependencies';
import { stateKey } from './state_maps';
import { formatDate } from '../../lib/utils/datetime_utility';
export default class MergeRequestStore {
@ -120,6 +121,10 @@ export default class MergeRequestStore {
}
}
get isNothingToMergeState() {
return this.state === stateKey.nothingToMerge;
}
static getEventObject(event) {
return {
author: MergeRequestStore.getAuthorObject(event),

View file

@ -31,6 +31,23 @@ const statesToShowHelpWidget = [
'autoMergeFailed',
];
export const stateKey = {
archived: 'archived',
missingBranch: 'missingBranch',
nothingToMerge: 'nothingToMerge',
checking: 'checking',
conflicts: 'conflicts',
workInProgress: 'workInProgress',
pipelineFailed: 'pipelineFailed',
unresolvedDiscussions: 'unresolvedDiscussions',
pipelineBlocked: 'pipelineBlocked',
shaMismatch: 'shaMismatch',
autoMergeFailed: 'autoMergeFailed',
mergeWhenPipelineSucceeds: 'mergeWhenPipelineSucceeds',
notAllowedToMerge: 'notAllowedToMerge',
readyToMerge: 'readyToMerge',
};
export default {
stateToComponentMap,
statesToShowHelpWidget,

View file

@ -0,0 +1,5 @@
---
title: Remove related links in MR widget when empty state
merge_request:
author:
type: fixed

View file

@ -2,6 +2,7 @@ import Vue from 'vue';
import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options';
import eventHub from '~/vue_merge_request_widget/event_hub';
import notify from '~/lib/utils/notify';
import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
import mockData from './mock_data';
import mountComponent from '../helpers/vue_mount_component_helper';
@ -344,4 +345,31 @@ describe('mrWidgetOptions', () => {
expect(comps['mr-widget-merge-when-pipeline-succeeds']).toBeDefined();
});
});
describe('rendering relatedLinks', () => {
beforeEach((done) => {
vm.mr.relatedLinks = {
assignToMe: null,
closing: `
<a class="close-related-link" href="#'>
Close
</a>
`,
mentioned: '',
};
Vue.nextTick(done);
});
it('renders if there are relatedLinks', () => {
expect(vm.$el.querySelector('.close-related-link')).toBeDefined();
});
it('does not render if state is nothingToMerge', (done) => {
vm.mr.state = stateKey.nothingToMerge;
Vue.nextTick(() => {
expect(vm.$el.querySelector('.close-related-link')).toBeNull();
done();
});
});
});
});

View file

@ -1,4 +1,5 @@
import MergeRequestStore from '~/vue_merge_request_widget/stores/mr_widget_store';
import { stateKey } from '~/vue_merge_request_widget/stores/state_maps';
import mockData from '../mock_data';
describe('MergeRequestStore', () => {
@ -52,5 +53,17 @@ describe('MergeRequestStore', () => {
expect(store.isPipelineSkipped).toBe(false);
});
});
describe('isNothingToMergeState', () => {
it('returns true when nothingToMerge', () => {
store.state = stateKey.nothingToMerge;
expect(store.isNothingToMergeState).toEqual(true);
});
it('returns false when not nothingToMerge', () => {
store.state = 'state';
expect(store.isNothingToMergeState).toEqual(false);
});
});
});
});