Welcome to mirror list, hosted at ThFree Co, Russian Federation.

app.vue « components « subscriptions « jira_connect « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 224228721834584fc8e85c1915561199cffe8a73 (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
131
132
133
134
135
136
137
138
139
140
141
<script>
import { GlAlert, GlLink, GlSprintf } from '@gitlab/ui';
import { isEmpty } from 'lodash';
import { mapState, mapMutations, mapActions } from 'vuex';
import { retrieveAlert } from '~/jira_connect/subscriptions/utils';
import AccessorUtilities from '~/lib/utils/accessor';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE } from '../constants';
import { SET_ALERT } from '../store/mutation_types';
import SignInPage from '../pages/sign_in/sign_in_page.vue';
import SubscriptionsPage from '../pages/subscriptions_page.vue';
import UserLink from './user_link.vue';
import CompatibilityAlert from './compatibility_alert.vue';
import BrowserSupportAlert from './browser_support_alert.vue';

export default {
  name: 'JiraConnectApp',
  components: {
    GlAlert,
    GlLink,
    GlSprintf,
    UserLink,
    CompatibilityAlert,
    BrowserSupportAlert,
    SignInPage,
    SubscriptionsPage,
  },
  mixins: [glFeatureFlagMixin()],
  inject: {
    usersPath: {
      default: '',
    },
    subscriptionsPath: {
      default: '',
    },
  },
  computed: {
    ...mapState(['currentUser']),
    ...mapState(['alert', 'subscriptions']),
    shouldShowAlert() {
      return Boolean(this.alert?.message);
    },
    hasSubscriptions() {
      return !isEmpty(this.subscriptions);
    },
    userSignedIn() {
      if (this.isOauthEnabled) {
        return Boolean(this.currentUser);
      }

      return Boolean(!this.usersPath);
    },
    isOauthEnabled() {
      return this.glFeatures.jiraConnectOauth;
    },
    /**
     * Returns false if the GitLab for Jira app doesn't support the user's browser.
     * Any web API that the GitLab for Jira app depends on should be checked here.
     */
    isBrowserSupported() {
      return !this.isOauthEnabled || AccessorUtilities.canUseCrypto();
    },
  },
  created() {
    this.setInitialAlert();
  },
  mounted() {
    this.fetchSubscriptionsOauth();
  },
  methods: {
    ...mapMutations({
      setAlert: SET_ALERT,
    }),
    ...mapActions(['fetchSubscriptions']),
    /**
     * Fetch subscriptions from the REST API,
     * if the jiraConnectOauth flag is enabled.
     */
    fetchSubscriptionsOauth() {
      if (!this.isOauthEnabled) return;

      this.fetchSubscriptions(this.subscriptionsPath);
    },
    setInitialAlert() {
      const { linkUrl, title, message, variant } = retrieveAlert() || {};
      this.setAlert({ linkUrl, title, message, variant });
    },
    onSignInOauth() {
      this.fetchSubscriptionsOauth();
    },
    onSignInError() {
      this.setAlert({
        message: I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE,
        variant: 'danger',
      });
    },
  },
};
</script>

<template>
  <browser-support-alert v-if="!isBrowserSupported" class="gl-mb-7" />
  <div v-else data-testid="jira-connect-app">
    <compatibility-alert class="gl-mb-7" />

    <gl-alert
      v-if="shouldShowAlert"
      :variant="alert.variant"
      :title="alert.title"
      class="gl-mb-5"
      data-testid="jira-connect-persisted-alert"
      @dismiss="setAlert"
    >
      <gl-sprintf v-if="alert.linkUrl" :message="alert.message">
        <template #link="{ content }">
          <gl-link :href="alert.linkUrl" target="_blank">{{ content }}</gl-link>
        </template>
      </gl-sprintf>

      <template v-else>
        {{ alert.message }}
      </template>
    </gl-alert>

    <user-link
      :user-signed-in="userSignedIn"
      :has-subscriptions="hasSubscriptions"
      :user="currentUser"
    />

    <div class="gl-layout-w-limited gl-mx-auto gl-px-5 gl-mb-7">
      <sign-in-page
        v-if="!userSignedIn"
        :has-subscriptions="hasSubscriptions"
        @sign-in-oauth="onSignInOauth"
        @error="onSignInError"
      />
      <subscriptions-page v-else :has-subscriptions="hasSubscriptions" />
    </div>
  </div>
</template>