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

index.vue « skeleton « components « observability « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d3c6892df508256abe1204e0442ed8d0e426d60b (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!-- eslint-disable vue/multi-word-component-names -->
<script>
import { GlSkeletonLoader, GlAlert, GlLoadingIcon } from '@gitlab/ui';

import {
  SKELETON_VARIANTS_BY_ROUTE,
  SKELETON_STATE,
  DEFAULT_TIMERS,
  OBSERVABILITY_ROUTES,
  TIMEOUT_ERROR_LABEL,
  TIMEOUT_ERROR_MESSAGE,
  SKELETON_VARIANT_EMBED,
  SKELETON_SPINNER_VARIANT,
} from '../../constants';
import DashboardsSkeleton from './dashboards.vue';
import ExploreSkeleton from './explore.vue';
import ManageSkeleton from './manage.vue';
import EmbedSkeleton from './embed.vue';

export default {
  components: {
    GlSkeletonLoader,
    DashboardsSkeleton,
    ExploreSkeleton,
    ManageSkeleton,
    EmbedSkeleton,
    GlAlert,
    GlLoadingIcon,
  },
  SKELETON_VARIANTS_BY_ROUTE,
  SKELETON_STATE,
  OBSERVABILITY_ROUTES,
  SKELETON_VARIANT_EMBED,
  i18n: {
    TIMEOUT_ERROR_LABEL,
    TIMEOUT_ERROR_MESSAGE,
  },
  props: {
    variant: {
      type: String,
      required: false,
      default: '',
    },
  },
  data() {
    return {
      state: null,
      loadingTimeout: null,
      errorTimeout: null,
    };
  },
  computed: {
    skeletonVisible() {
      return this.state === SKELETON_STATE.VISIBLE;
    },
    skeletonHidden() {
      return this.state === SKELETON_STATE.HIDDEN;
    },
    errorVisible() {
      return this.state === SKELETON_STATE.ERROR;
    },
    spinnerVariant() {
      return this.variant === SKELETON_SPINNER_VARIANT;
    },
    embedVariant() {
      return this.variant === SKELETON_VARIANT_EMBED;
    },
  },
  mounted() {
    this.setLoadingTimeout();
    this.setErrorTimeout();
  },
  destroyed() {
    clearTimeout(this.loadingTimeout);
    clearTimeout(this.errorTimeout);
  },
  methods: {
    onContentLoaded() {
      clearTimeout(this.errorTimeout);
      clearTimeout(this.loadingTimeout);

      this.hideSkeleton();
    },
    onError() {
      clearTimeout(this.errorTimeout);
      clearTimeout(this.loadingTimeout);

      this.showError();
    },
    setLoadingTimeout() {
      this.loadingTimeout = setTimeout(() => {
        /**
         *  If content is not loaded within CONTENT_WAIT_MS,
         *  show the skeleton
         */
        if (this.state !== SKELETON_STATE.HIDDEN) {
          this.showSkeleton();
        }
      }, DEFAULT_TIMERS.CONTENT_WAIT_MS);
    },
    setErrorTimeout() {
      this.errorTimeout = setTimeout(() => {
        /**
         *  If content is not loaded within TIMEOUT_MS,
         *  show the error dialog
         */
        if (this.state !== SKELETON_STATE.HIDDEN) {
          this.showError();
        }
      }, DEFAULT_TIMERS.TIMEOUT_MS);
    },
    hideSkeleton() {
      this.state = SKELETON_STATE.HIDDEN;
    },
    showSkeleton() {
      this.state = SKELETON_STATE.VISIBLE;
    },
    showError() {
      this.state = SKELETON_STATE.ERROR;
    },
    isVariantByRoute(route) {
      return this.variant === SKELETON_VARIANTS_BY_ROUTE[route];
    },
  },
};
</script>
<template>
  <div class="gl-flex-grow-1 gl-display-flex gl-flex-direction-column gl-flex-align-items-stretch">
    <transition name="fade">
      <div v-if="skeletonVisible" class="gl-px-5 gl-my-5">
        <dashboards-skeleton v-if="isVariantByRoute($options.OBSERVABILITY_ROUTES.DASHBOARDS)" />
        <explore-skeleton v-else-if="isVariantByRoute($options.OBSERVABILITY_ROUTES.EXPLORE)" />
        <manage-skeleton v-else-if="isVariantByRoute($options.OBSERVABILITY_ROUTES.MANAGE)" />
        <embed-skeleton v-else-if="embedVariant" />
        <gl-loading-icon v-else-if="spinnerVariant" size="lg" />

        <gl-skeleton-loader v-else>
          <rect y="2" width="10" height="8" />
          <rect y="2" x="15" width="15" height="8" />
          <rect y="2" x="35" width="15" height="8" />
          <rect y="15" width="400" height="30" />
        </gl-skeleton-loader>
      </div>

      <!-- The double condition is only here temporarily for back-compatibility reasons. Will be removed in next iteration https://gitlab.com/gitlab-org/opstrace/opstrace/-/issues/2275 -->
      <div
        v-else-if="spinnerVariant && skeletonHidden"
        data-testid="content-wrapper"
        class="gl-flex-grow-1 gl-display-flex gl-flex-direction-column gl-flex-align-items-stretch"
      >
        <slot></slot>
      </div>
    </transition>

    <gl-alert
      v-if="errorVisible"
      :title="$options.i18n.TIMEOUT_ERROR_LABEL"
      variant="danger"
      :dismissible="false"
      class="gl-m-5"
    >
      {{ $options.i18n.TIMEOUT_ERROR_MESSAGE }}
    </gl-alert>

    <!-- This is only kept temporarily for back-compatibility reasons. Will be removed in next iteration https://gitlab.com/gitlab-org/opstrace/opstrace/-/issues/2275 -->
    <transition v-if="!spinnerVariant">
      <div
        v-show="skeletonHidden"
        data-testid="content-wrapper"
        class="gl-flex-grow-1 gl-display-flex gl-flex-direction-column gl-flex-align-items-stretch"
      >
        <slot></slot>
      </div>
    </transition>
  </div>
</template>