|
| 1 | +<script> |
| 2 | +import { GlBadge, GlPopover, GlLink, GlToggle } from '@gitlab/ui'; |
| 3 | +import { uniqueId } from 'lodash'; |
| 4 | +import { createAlert } from '~/alert'; |
| 5 | +import { __ } from '~/locale'; |
| 6 | +import * as Sentry from '~/sentry/sentry_browser_wrapper'; |
| 7 | +import getUserPreferences from '../graphql/user_preferences.query.graphql'; |
| 8 | +import setUseWorkItemsView from '../graphql/set_use_work_items_view.mutation.graphql'; |
| 9 | +
|
| 10 | +export default { |
| 11 | + name: 'WorkItemToggle', |
| 12 | + components: { |
| 13 | + GlBadge, |
| 14 | + GlPopover, |
| 15 | + GlLink, |
| 16 | + GlToggle, |
| 17 | + }, |
| 18 | + data() { |
| 19 | + return { |
| 20 | + currentUser: { |
| 21 | + userPreferences: {}, |
| 22 | + }, |
| 23 | + feedbackIssue: 'https://gitlab.com/gitlab-org/gitlab/-/issues/463598', |
| 24 | + }; |
| 25 | + }, |
| 26 | + apollo: { |
| 27 | + currentUser: { |
| 28 | + query: getUserPreferences, |
| 29 | + }, |
| 30 | + }, |
| 31 | + computed: { |
| 32 | + onOff() { |
| 33 | + return this.currentUser.userPreferences.useWorkItemsView ? __('On') : __('Off'); |
| 34 | + }, |
| 35 | + }, |
| 36 | + methods: { |
| 37 | + setWorkItemsView(val) { |
| 38 | + this.$apollo |
| 39 | + .mutate({ |
| 40 | + mutation: setUseWorkItemsView, |
| 41 | + variables: { |
| 42 | + useWorkItemsView: val, |
| 43 | + }, |
| 44 | + update: (cache, { data: { userPreferencesUpdate } }) => { |
| 45 | + cache.modify({ |
| 46 | + id: cache.identify(this.currentUser), |
| 47 | + fields: { |
| 48 | + userPreferences(existingPreferences = {}) { |
| 49 | + return { |
| 50 | + ...existingPreferences, |
| 51 | + ...userPreferencesUpdate.userPreferences, |
| 52 | + }; |
| 53 | + }, |
| 54 | + }, |
| 55 | + }); |
| 56 | +
|
| 57 | + window.location.reload(); |
| 58 | + }, |
| 59 | + }) |
| 60 | + .catch((error) => { |
| 61 | + createAlert({ |
| 62 | + message: __('Something went wrong. Please try again.'), |
| 63 | + }); |
| 64 | + Sentry.captureException(error); |
| 65 | + }); |
| 66 | + }, |
| 67 | + }, |
| 68 | + badgeId: uniqueId(), |
| 69 | + i18n: { |
| 70 | + previewWorkItems: __( |
| 71 | + 'Preview the new issues experience, with real time updates and refreshed design. Some features are not yet supported, see feedback issue for details.', |
| 72 | + ), |
| 73 | + leaveFeedback: __('Leave feedback'), |
| 74 | + newIssueLook: __('New issue look'), |
| 75 | + }, |
| 76 | +}; |
| 77 | +</script> |
| 78 | + |
| 79 | +<template> |
| 80 | + <div class="gl-flex gl-content-center"> |
| 81 | + <gl-badge :id="$options.badgeId" variant="info" icon="information-o" href="#" |
| 82 | + >{{ $options.i18n.newIssueLook }}: {{ onOff }}</gl-badge |
| 83 | + > |
| 84 | + <gl-popover |
| 85 | + :target="$options.badgeId" |
| 86 | + data-testid="work-item-feedback-popover" |
| 87 | + triggers="focus click manual blur" |
| 88 | + placement="bottom" |
| 89 | + show-close-button |
| 90 | + :title="$options.i18n.newIssueLook" |
| 91 | + > |
| 92 | + <gl-toggle |
| 93 | + :value="currentUser.userPreferences.useWorkItemsView" |
| 94 | + :label="onOff" |
| 95 | + label-position="left" |
| 96 | + @change="setWorkItemsView" |
| 97 | + /> |
| 98 | + <div class="gl-pt-2"> |
| 99 | + {{ $options.i18n.previewWorkItems }} |
| 100 | + </div> |
| 101 | + <gl-link target="_blank" :href="feedbackIssue">{{ $options.i18n.leaveFeedback }}</gl-link> |
| 102 | + </gl-popover> |
| 103 | + </div> |
| 104 | +</template> |
0 commit comments