debian-mirror-gitlab/app/assets/javascripts/jira_connect/subscriptions/components/app.vue

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

160 lines
4.5 KiB
Vue
Raw Normal View History

2021-01-29 00:20:46 +05:30
<script>
2022-04-04 11:22:00 +05:30
import { GlAlert, GlLink, GlSprintf } from '@gitlab/ui';
2021-12-11 22:18:48 +05:30
import { isEmpty } from 'lodash';
2022-07-16 23:28:13 +05:30
import { mapState, mapMutations, mapActions } from 'vuex';
2021-12-11 22:18:48 +05:30
import { retrieveAlert } from '~/jira_connect/subscriptions/utils';
2022-06-21 17:19:12 +05:30
import AccessorUtilities from '~/lib/utils/accessor';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2022-05-07 20:08:51 +05:30
import { I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE } from '../constants';
2021-04-17 20:07:23 +05:30
import { SET_ALERT } from '../store/mutation_types';
2022-07-16 23:28:13 +05:30
import SignInPage from '../pages/sign_in/sign_in_page.vue';
import SubscriptionsPage from '../pages/subscriptions_page.vue';
2022-01-26 12:08:38 +05:30
import UserLink from './user_link.vue';
2022-06-21 17:19:12 +05:30
import BrowserSupportAlert from './browser_support_alert.vue';
2021-03-08 18:12:59 +05:30
2021-02-22 17:27:13 +05:30
export default {
name: 'JiraConnectApp',
2021-03-08 18:12:59 +05:30
components: {
GlAlert,
2021-04-17 20:07:23 +05:30
GlLink,
GlSprintf,
2022-06-21 17:19:12 +05:30
BrowserSupportAlert,
2022-04-04 11:22:00 +05:30
SignInPage,
SubscriptionsPage,
2023-03-17 16:20:25 +05:30
UserLink,
2021-03-08 18:12:59 +05:30
},
2022-06-21 17:19:12 +05:30
mixins: [glFeatureFlagMixin()],
2021-03-11 19:13:27 +05:30
inject: {
usersPath: {
default: '',
},
2022-07-16 23:28:13 +05:30
subscriptionsPath: {
default: '',
2021-12-11 22:18:48 +05:30
},
2023-04-23 21:23:45 +05:30
publicKeyStorageEnabled: {
default: false,
},
2021-03-11 19:13:27 +05:30
},
2021-02-22 17:27:13 +05:30
computed: {
2022-07-16 23:28:13 +05:30
...mapState(['currentUser']),
...mapState(['alert', 'subscriptions']),
2021-04-17 20:07:23 +05:30
shouldShowAlert() {
return Boolean(this.alert?.message);
},
2021-12-11 22:18:48 +05:30
hasSubscriptions() {
return !isEmpty(this.subscriptions);
},
userSignedIn() {
2022-07-16 23:28:13 +05:30
if (this.isOauthEnabled) {
return Boolean(this.currentUser);
}
return Boolean(!this.usersPath);
2021-02-22 17:27:13 +05:30
},
2022-06-21 17:19:12 +05:30
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();
},
2022-07-23 23:45:48 +05:30
gitlabUrl() {
return gon.gitlab_url;
},
gitlabLogo() {
return gon.gitlab_logo;
},
2021-02-22 17:27:13 +05:30
},
2021-03-11 19:13:27 +05:30
created() {
2021-04-17 20:07:23 +05:30
this.setInitialAlert();
2021-03-11 19:13:27 +05:30
},
2022-07-16 23:28:13 +05:30
mounted() {
this.fetchSubscriptionsOauth();
},
2021-03-11 19:13:27 +05:30
methods: {
2021-04-17 20:07:23 +05:30
...mapMutations({
setAlert: SET_ALERT,
}),
2022-07-16 23:28:13 +05:30
...mapActions(['fetchSubscriptions']),
/**
* Fetch subscriptions from the REST API,
* if the jiraConnectOauth flag is enabled.
*/
fetchSubscriptionsOauth() {
2022-10-11 01:57:18 +05:30
if (!this.isOauthEnabled || !this.userSignedIn) return;
2022-07-16 23:28:13 +05:30
this.fetchSubscriptions(this.subscriptionsPath);
},
2021-04-17 20:07:23 +05:30
setInitialAlert() {
const { linkUrl, title, message, variant } = retrieveAlert() || {};
this.setAlert({ linkUrl, title, message, variant });
},
2022-07-16 23:28:13 +05:30
onSignInOauth() {
this.fetchSubscriptionsOauth();
2022-05-07 20:08:51 +05:30
},
onSignInError() {
this.setAlert({
message: I18N_DEFAULT_SIGN_IN_ERROR_MESSAGE,
variant: 'danger',
});
},
2021-03-11 19:13:27 +05:30
},
2021-02-22 17:27:13 +05:30
};
2021-01-29 00:20:46 +05:30
</script>
2021-03-08 18:12:59 +05:30
2021-01-29 00:20:46 +05:30
<template>
2022-07-23 23:45:48 +05:30
<div>
<header
class="jira-connect-header gl-display-flex gl-align-items-center gl-justify-content-center gl-px-5 gl-border-b-solid gl-border-b-gray-100 gl-border-b-1 gl-bg-white"
2021-04-17 20:07:23 +05:30
>
2022-07-23 23:45:48 +05:30
<gl-link :href="gitlabUrl" target="_blank">
<img :src="gitlabLogo" class="gl-h-6" :alt="__('GitLab')" />
</gl-link>
<user-link
:user-signed-in="userSignedIn"
:has-subscriptions="hasSubscriptions"
:user="currentUser"
class="gl-fixed gl-right-4"
/>
</header>
2021-04-17 20:07:23 +05:30
2022-07-23 23:45:48 +05:30
<main class="jira-connect-app gl-px-5 gl-pt-7 gl-mx-auto">
<browser-support-alert v-if="!isBrowserSupported" class="gl-mb-7" />
<div v-else data-testid="jira-connect-app">
<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>
2022-01-26 12:08:38 +05:30
2022-07-23 23:45:48 +05:30
<template v-else>
{{ alert.message }}
</template>
</gl-alert>
<div class="gl-layout-w-limited gl-mx-auto gl-px-5 gl-mb-7">
<sign-in-page
2022-10-11 01:57:18 +05:30
v-show="!userSignedIn"
2022-07-23 23:45:48 +05:30
:has-subscriptions="hasSubscriptions"
2023-04-23 21:23:45 +05:30
:public-key-storage-enabled="publicKeyStorageEnabled"
2022-07-23 23:45:48 +05:30
@sign-in-oauth="onSignInOauth"
@error="onSignInError"
/>
2022-10-11 01:57:18 +05:30
<subscriptions-page v-if="userSignedIn" :has-subscriptions="hasSubscriptions" />
2022-07-23 23:45:48 +05:30
</div>
</div>
</main>
2021-03-08 18:12:59 +05:30
</div>
2021-01-29 00:20:46 +05:30
</template>