2020-10-05 11:08:56 -04:00
|
|
|
<script>
|
|
|
|
import { GlButton, GlTooltipDirective } from '@gitlab/ui';
|
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
|
|
|
import { s__ } from '~/locale';
|
2021-02-01 10:08:56 -05:00
|
|
|
import TrackEventDirective from '~/vue_shared/directives/track_event';
|
2020-10-05 11:08:56 -04:00
|
|
|
import { COMMENTS_ONLY_FILTER_VALUE, DESC } from '../constants';
|
|
|
|
import notesEventHub from '../event_hub';
|
2020-10-08 05:08:40 -04:00
|
|
|
import { trackToggleTimelineView } from '../utils';
|
2020-10-05 11:08:56 -04:00
|
|
|
|
|
|
|
export const timelineEnabledTooltip = s__('Timeline|Turn timeline view off');
|
|
|
|
export const timelineDisabledTooltip = s__('Timeline|Turn timeline view on');
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlButton,
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
2020-10-08 05:08:40 -04:00
|
|
|
TrackEvent: TrackEventDirective,
|
2020-10-05 11:08:56 -04:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters(['timelineEnabled', 'sortDirection']),
|
|
|
|
tooltip() {
|
|
|
|
return this.timelineEnabled ? timelineEnabledTooltip : timelineDisabledTooltip;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
...mapActions(['setTimelineView', 'setDiscussionSortDirection']),
|
2020-10-08 05:08:40 -04:00
|
|
|
trackToggleTimelineView,
|
2020-10-05 11:08:56 -04:00
|
|
|
setSort() {
|
|
|
|
if (this.timelineEnabled && this.sortDirection !== DESC) {
|
|
|
|
this.setDiscussionSortDirection({ direction: DESC, persist: false });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setFilter() {
|
|
|
|
notesEventHub.$emit('dropdownSelect', COMMENTS_ONLY_FILTER_VALUE, false);
|
|
|
|
},
|
|
|
|
toggleTimeline(event) {
|
|
|
|
event.currentTarget.blur();
|
|
|
|
this.setTimelineView(!this.timelineEnabled);
|
|
|
|
this.setSort();
|
|
|
|
this.setFilter();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-button
|
|
|
|
v-gl-tooltip
|
2020-10-08 05:08:40 -04:00
|
|
|
v-track-event="trackToggleTimelineView(timelineEnabled)"
|
2020-10-05 11:08:56 -04:00
|
|
|
icon="comments"
|
|
|
|
:selected="timelineEnabled"
|
|
|
|
:title="tooltip"
|
|
|
|
:aria-label="tooltip"
|
|
|
|
class="gl-mr-3"
|
|
|
|
@click="toggleTimeline"
|
|
|
|
/>
|
|
|
|
</template>
|