diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-18 15:13:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-18 15:13:19 +0300 |
commit | 14f554f0e991000bf291969673ae2f2d0a7670b6 (patch) | |
tree | c578029665b0bab96dc8740be6bb30710a7677b6 /app/assets/javascripts/vue_alerts.js | |
parent | 581a24da7e744ad5e7af9519e3b1c05344ead93c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/vue_alerts.js')
-rw-r--r-- | app/assets/javascripts/vue_alerts.js | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/app/assets/javascripts/vue_alerts.js b/app/assets/javascripts/vue_alerts.js index abc1dd75645..b44f787cf30 100644 --- a/app/assets/javascripts/vue_alerts.js +++ b/app/assets/javascripts/vue_alerts.js @@ -1,7 +1,17 @@ import Vue from 'vue'; +import Cookies from 'js-cookie'; import { parseBoolean } from '~/lib/utils/common_utils'; import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue'; +const getCookieExpirationPeriod = (expirationPeriod) => { + const defaultExpirationPeriod = 30; + const alertExpirationPeriod = Number(expirationPeriod); + + return !expirationPeriod || Number.isNaN(alertExpirationPeriod) + ? defaultExpirationPeriod + : alertExpirationPeriod; +}; + const mountVueAlert = (el) => { const props = { html: el.innerHTML, @@ -10,11 +20,25 @@ const mountVueAlert = (el) => { ...el.dataset, dismissible: parseBoolean(el.dataset.dismissible), }; + const { dismissCookieName, dismissCookieExpire } = el.dataset; return new Vue({ el, - render(h) { - return h(DismissibleAlert, { props, attrs }); + render(createElement) { + return createElement(DismissibleAlert, { + props, + attrs, + on: { + alertDismissed() { + if (!dismissCookieName) { + return; + } + Cookies.set(dismissCookieName, true, { + expires: getCookieExpirationPeriod(dismissCookieExpire), + }); + }, + }, + }); }, }); }; |