summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/confidential/confidential_issue_sidebar.vue
blob: 0987603cafde4e4942800a45f64d962ca2263773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<script>
import { mapState, mapActions } from 'vuex';
import { __ } from '~/locale';
import Flash from '~/flash';
import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue';
import eventHub from '~/sidebar/event_hub';
import EditForm from './edit_form.vue';
import recaptchaModalImplementor from '~/vue_shared/mixins/recaptcha_modal_implementor';

export default {
  components: {
    EditForm,
    Icon,
  },
  directives: {
    tooltip,
  },
  mixins: [recaptchaModalImplementor],
  props: {
    fullPath: {
      required: true,
      type: String,
    },
    isEditable: {
      required: true,
      type: Boolean,
    },
    service: {
      required: true,
      type: Object,
    },
  },
  data() {
    return {
      edit: false,
    };
  },
  computed: {
    ...mapState({ confidential: ({ noteableData }) => noteableData.confidential }),
    confidentialityIcon() {
      return this.confidential ? 'eye-slash' : 'eye';
    },
    tooltipLabel() {
      return this.confidential ? __('Confidential') : __('Not confidential');
    },
  },
  created() {
    eventHub.$on('updateConfidentialAttribute', this.updateConfidentialAttribute);
    eventHub.$on('closeConfidentialityForm', this.toggleForm);
  },
  beforeDestroy() {
    eventHub.$off('updateConfidentialAttribute', this.updateConfidentialAttribute);
    eventHub.$off('closeConfidentialityForm', this.toggleForm);
  },
  methods: {
    ...mapActions(['setConfidentiality']),
    toggleForm() {
      this.edit = !this.edit;
    },
    closeForm() {
      this.edit = false;
    },
    updateConfidentialAttribute() {
      // TODO: rm when FF is defaulted to on.
      const confidential = !this.confidential;
      this.service
        .update('issue', { confidential })
        .then(({ data }) => this.checkForSpam(data))
        .then(() => window.location.reload())
        .catch(error => {
          if (error.name === 'SpamError') {
            this.openRecaptcha();
          } else {
            Flash(__('Something went wrong trying to change the confidentiality of this issue'));
          }
        });
    },
  },
};
</script>

<template>
  <div class="block issuable-sidebar-item confidentiality">
    <div
      ref="collapseIcon"
      v-tooltip
      :title="tooltipLabel"
      class="sidebar-collapsed-icon"
      data-container="body"
      data-placement="left"
      data-boundary="viewport"
      @click="toggleForm"
    >
      <icon :name="confidentialityIcon" aria-hidden="true" />
    </div>
    <div class="title hide-collapsed">
      {{ __('Confidentiality') }}
      <a
        v-if="isEditable"
        ref="editLink"
        class="float-right confidential-edit"
        href="#"
        data-track-event="click_edit_button"
        data-track-label="right_sidebar"
        data-track-property="confidentiality"
        @click.prevent="toggleForm"
        >{{ __('Edit') }}</a
      >
    </div>
    <div class="value sidebar-item-value hide-collapsed">
      <edit-form v-if="edit" :is-confidential="confidential" :full-path="fullPath" />
      <div v-if="!confidential" class="no-value sidebar-item-value" data-testid="not-confidential">
        <icon :size="16" name="eye" aria-hidden="true" class="sidebar-item-icon inline" />
        {{ __('Not confidential') }}
      </div>
      <div v-else class="value sidebar-item-value hide-collapsed">
        <icon
          :size="16"
          name="eye-slash"
          aria-hidden="true"
          class="sidebar-item-icon inline is-active"
        />
        {{ __('This issue is confidential') }}
      </div>
    </div>

    <recaptcha-modal v-if="showRecaptcha" :html="recaptchaHTML" @close="closeRecaptcha" />
  </div>
</template>