2018-06-15 08:27:11 +00:00
|
|
|
<script>
|
2020-08-26 09:10:16 +00:00
|
|
|
/* eslint-disable vue/no-v-html */
|
2018-06-15 08:27:11 +00:00
|
|
|
import { mapActions } from 'vuex';
|
2020-02-13 21:08:59 +00:00
|
|
|
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
|
2018-06-15 08:27:11 +00:00
|
|
|
|
|
|
|
export default {
|
2018-11-07 10:06:15 +00:00
|
|
|
components: {
|
2020-02-13 21:08:59 +00:00
|
|
|
GlAlert,
|
2018-11-07 10:06:15 +00:00
|
|
|
GlLoadingIcon,
|
|
|
|
},
|
2018-06-15 08:27:11 +00:00
|
|
|
props: {
|
|
|
|
message: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
|
|
|
};
|
|
|
|
},
|
2020-02-13 21:08:59 +00:00
|
|
|
computed: {
|
|
|
|
canDismiss() {
|
|
|
|
return !this.message.action;
|
|
|
|
},
|
|
|
|
},
|
2018-06-15 08:27:11 +00:00
|
|
|
methods: {
|
|
|
|
...mapActions(['setErrorMessage']),
|
2020-02-13 21:08:59 +00:00
|
|
|
doAction() {
|
2018-06-15 08:27:11 +00:00
|
|
|
if (this.isLoading) return;
|
|
|
|
|
|
|
|
this.isLoading = true;
|
|
|
|
|
2018-06-28 11:15:07 +00:00
|
|
|
this.message
|
|
|
|
.action(this.message.actionPayload)
|
2018-06-15 08:27:11 +00:00
|
|
|
.then(() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
});
|
|
|
|
},
|
2020-02-13 21:08:59 +00:00
|
|
|
dismiss() {
|
|
|
|
this.setErrorMessage(null);
|
2018-06-15 08:27:11 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2020-02-13 21:08:59 +00:00
|
|
|
<gl-alert
|
|
|
|
data-qa-selector="flash_alert"
|
|
|
|
variant="danger"
|
|
|
|
:dismissible="canDismiss"
|
|
|
|
:primary-button-text="message.actionText"
|
|
|
|
@dismiss="dismiss"
|
|
|
|
@primaryAction="doAction"
|
|
|
|
>
|
|
|
|
<span v-html="message.text"></span>
|
|
|
|
<gl-loading-icon v-show="isLoading" inline class="vertical-align-middle ml-1" />
|
|
|
|
</gl-alert>
|
2018-06-15 08:27:11 +00:00
|
|
|
</template>
|