Commit 5494f09a authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '54206-show-the-activity-filter-dropdown-in-discussion-tab-only' into 'master'

Resolve "Show the activity filter dropdown in discussion tab only, show all discussions always in changes tab"

Closes #54206

See merge request gitlab-org/gitlab-ce!24082
parents 1a83d938 92eff44f
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
import $ from 'jquery'; import $ from 'jquery';
import { mapGetters, mapActions } from 'vuex'; import { mapGetters, mapActions } from 'vuex';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { DISCUSSION_FILTERS_DEFAULT_VALUE, HISTORY_ONLY_FILTER_VALUE } from '../constants'; import {
DISCUSSION_FILTERS_DEFAULT_VALUE,
HISTORY_ONLY_FILTER_VALUE,
DISCUSSION_TAB_LABEL,
} from '../constants';
export default { export default {
components: { components: {
...@@ -23,6 +27,7 @@ export default { ...@@ -23,6 +27,7 @@ export default {
return { return {
currentValue: this.selectedValue, currentValue: this.selectedValue,
defaultValue: DISCUSSION_FILTERS_DEFAULT_VALUE, defaultValue: DISCUSSION_FILTERS_DEFAULT_VALUE,
displayFilters: true,
}; };
}, },
computed: { computed: {
...@@ -32,6 +37,14 @@ export default { ...@@ -32,6 +37,14 @@ export default {
return this.filters.find(filter => filter.value === this.currentValue); return this.filters.find(filter => filter.value === this.currentValue);
}, },
}, },
created() {
if (window.mrTabs) {
const { eventHub, currentTab } = window.mrTabs;
eventHub.$on('MergeRequestTabChange', this.toggleFilters);
this.toggleFilters(currentTab);
}
},
mounted() { mounted() {
this.toggleCommentsForm(); this.toggleCommentsForm();
}, },
...@@ -51,12 +64,15 @@ export default { ...@@ -51,12 +64,15 @@ export default {
toggleCommentsForm() { toggleCommentsForm() {
this.setCommentsDisabled(this.currentValue === HISTORY_ONLY_FILTER_VALUE); this.setCommentsDisabled(this.currentValue === HISTORY_ONLY_FILTER_VALUE);
}, },
toggleFilters(tab) {
this.displayFilters = tab === DISCUSSION_TAB_LABEL;
},
}, },
}; };
</script> </script>
<template> <template>
<div class="discussion-filter-container d-inline-block align-bottom"> <div v-if="displayFilters" class="discussion-filter-container d-inline-block align-bottom">
<button <button
id="discussion-filter-dropdown" id="discussion-filter-dropdown"
ref="dropdownToggle" ref="dropdownToggle"
......
...@@ -17,6 +17,7 @@ export const RESOLVE_NOTE_METHOD_NAME = 'post'; ...@@ -17,6 +17,7 @@ export const RESOLVE_NOTE_METHOD_NAME = 'post';
export const DESCRIPTION_TYPE = 'changed the description'; export const DESCRIPTION_TYPE = 'changed the description';
export const HISTORY_ONLY_FILTER_VALUE = 2; export const HISTORY_ONLY_FILTER_VALUE = 2;
export const DISCUSSION_FILTERS_DEFAULT_VALUE = 0; export const DISCUSSION_FILTERS_DEFAULT_VALUE = 0;
export const DISCUSSION_TAB_LABEL = 'show';
export const NOTEABLE_TYPE_MAPPING = { export const NOTEABLE_TYPE_MAPPING = {
Issue: ISSUE_NOTEABLE_TYPE, Issue: ISSUE_NOTEABLE_TYPE,
......
---
title: Discussion filter only displayed in discussions tab for merge requests
merge_request: 24082
author:
type: changed
...@@ -7,8 +7,9 @@ import { discussionFiltersMock, discussionMock } from '../mock_data'; ...@@ -7,8 +7,9 @@ import { discussionFiltersMock, discussionMock } from '../mock_data';
describe('DiscussionFilter component', () => { describe('DiscussionFilter component', () => {
let vm; let vm;
let store; let store;
let eventHub;
beforeEach(() => { const mountComponent = () => {
store = createStore(); store = createStore();
const discussions = [ const discussions = [
...@@ -22,7 +23,7 @@ describe('DiscussionFilter component', () => { ...@@ -22,7 +23,7 @@ describe('DiscussionFilter component', () => {
const selectedValue = discussionFiltersMock[0].value; const selectedValue = discussionFiltersMock[0].value;
store.state.discussions = discussions; store.state.discussions = discussions;
vm = mountComponentWithStore(Component, { return mountComponentWithStore(Component, {
el: null, el: null,
store, store,
props: { props: {
...@@ -30,6 +31,11 @@ describe('DiscussionFilter component', () => { ...@@ -30,6 +31,11 @@ describe('DiscussionFilter component', () => {
selectedValue, selectedValue,
}, },
}); });
};
beforeEach(() => {
window.mrTabs = undefined;
vm = mountComponent();
}); });
afterEach(() => { afterEach(() => {
...@@ -83,4 +89,30 @@ describe('DiscussionFilter component', () => { ...@@ -83,4 +89,30 @@ describe('DiscussionFilter component', () => {
expect(defaultFilter.lastChild.classList).toContain('dropdown-divider'); expect(defaultFilter.lastChild.classList).toContain('dropdown-divider');
}); });
describe('Merge request tabs', () => {
eventHub = new Vue();
beforeEach(() => {
window.mrTabs = {
eventHub,
currentTab: 'show',
};
vm = mountComponent();
});
afterEach(() => {
window.mrTabs = undefined;
});
it('only renders when discussion tab is active', done => {
eventHub.$emit('MergeRequestTabChange', 'commit');
vm.$nextTick(() => {
expect(vm.$el.querySelector).toBeUndefined();
done();
});
});
});
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment