debian-mirror-gitlab/app/assets/javascripts/notes/components/timeline_toggle.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.7 KiB
Vue
Raw Normal View History

2021-01-03 14:25:43 +05:30
<script>
import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import { mapActions, mapGetters } from 'vuex';
import { s__ } from '~/locale';
2021-03-11 19:13:27 +05:30
import TrackEventDirective from '~/vue_shared/directives/track_event';
2021-01-03 14:25:43 +05:30
import { COMMENTS_ONLY_FILTER_VALUE, DESC } from '../constants';
import notesEventHub from '../event_hub';
import { trackToggleTimelineView } from '../utils';
2022-06-21 17:19:12 +05:30
export const timelineEnabledTooltip = s__('Timeline|Turn recent updates view off');
export const timelineDisabledTooltip = s__('Timeline|Turn recent updates view on');
2021-01-03 14:25:43 +05:30
export default {
components: {
GlButton,
},
directives: {
GlTooltip: GlTooltipDirective,
TrackEvent: TrackEventDirective,
},
computed: {
...mapGetters(['timelineEnabled', 'sortDirection']),
tooltip() {
return this.timelineEnabled ? timelineEnabledTooltip : timelineDisabledTooltip;
},
},
methods: {
...mapActions(['setTimelineView', 'setDiscussionSortDirection']),
trackToggleTimelineView,
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
v-track-event="trackToggleTimelineView(timelineEnabled)"
2022-06-21 17:19:12 +05:30
icon="history"
2021-01-03 14:25:43 +05:30
:selected="timelineEnabled"
:title="tooltip"
:aria-label="tooltip"
@click="toggleTimeline"
/>
</template>