summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/gitlab_version_check/index.js
blob: 203ce10ef578e3daa3286386ef8d6e83207e0c39 (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
import Vue from 'vue';
import * as Sentry from '@sentry/browser';
import { parseBoolean } from '~/lib/utils/common_utils';
import axios from '~/lib/utils/axios_utils';
import { joinPaths } from '~/lib/utils/url_utility';
import GitlabVersionCheckBadge from './components/gitlab_version_check_badge.vue';

const mountGitlabVersionCheckBadge = ({ el, status }) => {
  const { size } = el.dataset;
  const actionable = parseBoolean(el.dataset.actionable);

  return new Vue({
    el,
    render(createElement) {
      return createElement(GitlabVersionCheckBadge, {
        props: {
          size,
          actionable,
          status,
        },
      });
    },
  });
};

export default async () => {
  const versionCheckBadges = [...document.querySelectorAll('.js-gitlab-version-check-badge')];

  // If there are no version check elements, exit out
  if (versionCheckBadges?.length <= 0) {
    return null;
  }

  const status = await axios
    .get(joinPaths('/', gon.relative_url_root, '/admin/version_check.json'))
    .then((res) => {
      return res.data?.severity;
    })
    .catch((e) => {
      Sentry.captureException(e);
      return null;
    });

  // If we don't have a status there is nothing to render
  if (status) {
    return versionCheckBadges.map((el) => mountGitlabVersionCheckBadge({ el, status }));
  }

  return null;
};