2020-10-27 12:08:33 +00:00
|
|
|
<script>
|
2021-10-01 09:11:45 +00:00
|
|
|
import {
|
|
|
|
GlButton,
|
|
|
|
GlLoadingIcon,
|
|
|
|
GlLink,
|
|
|
|
GlBadge,
|
|
|
|
GlSafeHtmlDirective,
|
|
|
|
GlTooltipDirective,
|
2021-10-12 15:12:08 +00:00
|
|
|
GlIntersectionObserver,
|
2021-10-01 09:11:45 +00:00
|
|
|
} from '@gitlab/ui';
|
2021-10-26 18:09:19 +00:00
|
|
|
import { once } from 'lodash';
|
2021-11-24 12:10:21 +00:00
|
|
|
import * as Sentry from '@sentry/browser';
|
2021-10-26 18:09:19 +00:00
|
|
|
import api from '~/api';
|
2021-10-08 15:12:51 +00:00
|
|
|
import { sprintf, s__, __ } from '~/locale';
|
2020-10-27 12:08:33 +00:00
|
|
|
import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue';
|
2022-01-11 18:16:38 +00:00
|
|
|
import Poll from '~/lib/utils/poll';
|
2021-11-24 12:10:21 +00:00
|
|
|
import { EXTENSION_ICON_CLASS, EXTENSION_ICONS } from '../../constants';
|
2021-09-29 12:11:22 +00:00
|
|
|
import StatusIcon from './status_icon.vue';
|
2021-10-06 15:11:48 +00:00
|
|
|
import Actions from './actions.vue';
|
2021-12-13 15:12:59 +00:00
|
|
|
import { generateText } from './utils';
|
2020-10-27 12:08:33 +00:00
|
|
|
|
|
|
|
export const LOADING_STATES = {
|
|
|
|
collapsedLoading: 'collapsedLoading',
|
|
|
|
collapsedError: 'collapsedError',
|
|
|
|
expandedLoading: 'expandedLoading',
|
2021-11-24 12:10:21 +00:00
|
|
|
expandedError: 'expandedError',
|
2020-10-27 12:08:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlButton,
|
|
|
|
GlLoadingIcon,
|
|
|
|
GlLink,
|
|
|
|
GlBadge,
|
2021-10-12 15:12:08 +00:00
|
|
|
GlIntersectionObserver,
|
2020-10-27 12:08:33 +00:00
|
|
|
SmartVirtualList,
|
|
|
|
StatusIcon,
|
2021-10-06 15:11:48 +00:00
|
|
|
Actions,
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
SafeHtml: GlSafeHtmlDirective,
|
2021-10-01 09:11:45 +00:00
|
|
|
GlTooltip: GlTooltipDirective,
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loadingState: LOADING_STATES.collapsedLoading,
|
2021-11-24 12:10:21 +00:00
|
|
|
collapsedData: {},
|
|
|
|
fullData: [],
|
2020-10-27 12:08:33 +00:00
|
|
|
isCollapsed: true,
|
2021-10-12 15:12:08 +00:00
|
|
|
showFade: false,
|
2020-10-27 12:08:33 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2021-10-08 15:12:51 +00:00
|
|
|
widgetLabel() {
|
|
|
|
return this.$options.i18n?.label || this.$options.name;
|
|
|
|
},
|
|
|
|
widgetLoadingText() {
|
|
|
|
return this.$options.i18n?.loading || __('Loading...');
|
|
|
|
},
|
2021-11-24 12:10:21 +00:00
|
|
|
widgetErrorText() {
|
|
|
|
return this.$options.i18n?.error || __('Failed to load');
|
|
|
|
},
|
2020-10-27 12:08:33 +00:00
|
|
|
isLoadingSummary() {
|
|
|
|
return this.loadingState === LOADING_STATES.collapsedLoading;
|
|
|
|
},
|
|
|
|
isLoadingExpanded() {
|
|
|
|
return this.loadingState === LOADING_STATES.expandedLoading;
|
|
|
|
},
|
|
|
|
isCollapsible() {
|
2021-11-24 12:10:21 +00:00
|
|
|
return !this.isLoadingSummary && this.loadingState !== LOADING_STATES.collapsedError;
|
|
|
|
},
|
|
|
|
hasFullData() {
|
|
|
|
return this.fullData.length > 0;
|
|
|
|
},
|
|
|
|
hasFetchError() {
|
|
|
|
return (
|
|
|
|
this.loadingState === LOADING_STATES.collapsedError ||
|
|
|
|
this.loadingState === LOADING_STATES.expandedError
|
|
|
|
);
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
2021-10-01 09:11:45 +00:00
|
|
|
collapseButtonLabel() {
|
|
|
|
return sprintf(
|
|
|
|
this.isCollapsed
|
|
|
|
? s__('mrWidget|Show %{widget} details')
|
|
|
|
: s__('mrWidget|Hide %{widget} details'),
|
2021-10-08 15:12:51 +00:00
|
|
|
{ widget: this.widgetLabel },
|
2021-10-01 09:11:45 +00:00
|
|
|
);
|
|
|
|
},
|
2020-10-27 12:08:33 +00:00
|
|
|
statusIconName() {
|
2021-11-24 12:10:21 +00:00
|
|
|
if (this.hasFetchError) return EXTENSION_ICONS.error;
|
2021-09-29 15:11:47 +00:00
|
|
|
if (this.isLoadingSummary) return null;
|
|
|
|
|
2020-10-27 12:08:33 +00:00
|
|
|
return this.statusIcon(this.collapsedData);
|
|
|
|
},
|
2021-10-06 15:11:48 +00:00
|
|
|
tertiaryActionsButtons() {
|
|
|
|
return this.tertiaryButtons ? this.tertiaryButtons() : undefined;
|
|
|
|
},
|
2021-12-17 15:13:39 +00:00
|
|
|
hydratedSummary() {
|
|
|
|
const structuredOutput = this.summary(this.collapsedData);
|
|
|
|
const summary = {
|
|
|
|
subject: generateText(
|
|
|
|
typeof structuredOutput === 'string' ? structuredOutput : structuredOutput.subject,
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
if (structuredOutput.meta) {
|
|
|
|
summary.meta = generateText(structuredOutput.meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
return summary;
|
|
|
|
},
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
isCollapsed(newVal) {
|
|
|
|
if (!newVal) {
|
|
|
|
this.loadAllData();
|
|
|
|
} else {
|
|
|
|
this.loadingState = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-11-25 18:14:13 +00:00
|
|
|
this.loadCollapsedData();
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2021-10-26 18:09:19 +00:00
|
|
|
triggerRedisTracking: once(function triggerRedisTracking() {
|
|
|
|
if (this.$options.expandEvent) {
|
|
|
|
api.trackRedisHllUserEvent(this.$options.expandEvent);
|
|
|
|
}
|
|
|
|
}),
|
2020-10-27 12:08:33 +00:00
|
|
|
toggleCollapsed() {
|
|
|
|
this.isCollapsed = !this.isCollapsed;
|
2021-10-26 18:09:19 +00:00
|
|
|
|
|
|
|
this.triggerRedisTracking();
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
2022-01-11 18:16:38 +00:00
|
|
|
initExtensionPolling() {
|
|
|
|
const poll = new Poll({
|
|
|
|
resource: {
|
|
|
|
fetchData: () => this.fetchCollapsedData(this.$props),
|
|
|
|
},
|
|
|
|
method: 'fetchData',
|
2022-01-21 12:16:22 +00:00
|
|
|
successCallback: ({ data }) => {
|
2022-01-11 18:16:38 +00:00
|
|
|
if (Object.keys(data).length > 0) {
|
|
|
|
poll.stop();
|
|
|
|
this.setCollapsedData(data);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
errorCallback: (e) => {
|
|
|
|
poll.stop();
|
|
|
|
|
|
|
|
this.setCollapsedError(e);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
poll.makeRequest();
|
|
|
|
},
|
2021-11-25 18:14:13 +00:00
|
|
|
loadCollapsedData() {
|
|
|
|
this.loadingState = LOADING_STATES.collapsedLoading;
|
|
|
|
|
2022-01-11 18:16:38 +00:00
|
|
|
if (this.$options.enablePolling) {
|
|
|
|
this.initExtensionPolling();
|
|
|
|
} else {
|
|
|
|
this.fetchCollapsedData(this.$props)
|
|
|
|
.then((data) => {
|
|
|
|
this.setCollapsedData(data);
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
this.setCollapsedError(e);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setCollapsedData(data) {
|
|
|
|
this.collapsedData = data;
|
|
|
|
this.loadingState = null;
|
|
|
|
},
|
|
|
|
setCollapsedError(e) {
|
|
|
|
this.loadingState = LOADING_STATES.collapsedError;
|
2021-11-25 18:14:13 +00:00
|
|
|
|
2022-01-11 18:16:38 +00:00
|
|
|
Sentry.captureException(e);
|
2021-11-25 18:14:13 +00:00
|
|
|
},
|
2020-10-27 12:08:33 +00:00
|
|
|
loadAllData() {
|
2021-11-24 12:10:21 +00:00
|
|
|
if (this.hasFullData) return;
|
2020-10-27 12:08:33 +00:00
|
|
|
|
|
|
|
this.loadingState = LOADING_STATES.expandedLoading;
|
|
|
|
|
|
|
|
this.fetchFullData(this.$props)
|
2020-12-23 21:10:24 +00:00
|
|
|
.then((data) => {
|
2020-10-27 12:08:33 +00:00
|
|
|
this.loadingState = null;
|
|
|
|
this.fullData = data;
|
|
|
|
})
|
2020-12-23 21:10:24 +00:00
|
|
|
.catch((e) => {
|
2021-11-24 12:10:21 +00:00
|
|
|
this.loadingState = LOADING_STATES.expandedError;
|
|
|
|
|
|
|
|
Sentry.captureException(e);
|
2020-10-27 12:08:33 +00:00
|
|
|
});
|
|
|
|
},
|
2021-12-13 15:12:59 +00:00
|
|
|
isArray(arr) {
|
|
|
|
return Array.isArray(arr);
|
|
|
|
},
|
2021-10-12 15:12:08 +00:00
|
|
|
appear(index) {
|
|
|
|
if (index === this.fullData.length - 1) {
|
|
|
|
this.showFade = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disappear(index) {
|
|
|
|
if (index === this.fullData.length - 1) {
|
|
|
|
this.showFade = true;
|
|
|
|
}
|
|
|
|
},
|
2021-12-13 15:12:59 +00:00
|
|
|
generateText,
|
2020-10-27 12:08:33 +00:00
|
|
|
},
|
2021-09-29 12:11:22 +00:00
|
|
|
EXTENSION_ICON_CLASS,
|
2020-10-27 12:08:33 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2021-10-07 12:12:09 +00:00
|
|
|
<section class="media-section" data-testid="widget-extension">
|
2020-10-27 12:08:33 +00:00
|
|
|
<div class="media gl-p-5">
|
2021-10-14 15:14:02 +00:00
|
|
|
<status-icon
|
|
|
|
:name="$options.label || $options.name"
|
|
|
|
:is-loading="isLoadingSummary"
|
|
|
|
:icon-name="statusIconName"
|
|
|
|
/>
|
2021-10-22 12:09:12 +00:00
|
|
|
<div
|
2021-12-01 21:13:44 +00:00
|
|
|
class="media-body gl-display-flex gl-flex-direction-row! gl-align-self-center"
|
2021-10-22 12:09:12 +00:00
|
|
|
data-testid="widget-extension-top-level"
|
|
|
|
>
|
2021-10-06 15:11:48 +00:00
|
|
|
<div class="gl-flex-grow-1">
|
2021-10-08 15:12:51 +00:00
|
|
|
<template v-if="isLoadingSummary">{{ widgetLoadingText }}</template>
|
2021-11-24 12:10:21 +00:00
|
|
|
<template v-else-if="hasFetchError">{{ widgetErrorText }}</template>
|
2021-12-17 15:13:39 +00:00
|
|
|
<div v-else>
|
|
|
|
<span v-safe-html="hydratedSummary.subject"></span>
|
|
|
|
<template v-if="hydratedSummary.meta">
|
|
|
|
<br />
|
|
|
|
<span v-safe-html="hydratedSummary.meta" class="gl-font-sm"></span>
|
|
|
|
</template>
|
|
|
|
</div>
|
2020-10-27 12:08:33 +00:00
|
|
|
</div>
|
2021-10-14 15:14:02 +00:00
|
|
|
<actions
|
|
|
|
:widget="$options.label || $options.name"
|
|
|
|
:tertiary-buttons="tertiaryActionsButtons"
|
|
|
|
/>
|
2021-11-24 18:14:31 +00:00
|
|
|
<div
|
|
|
|
v-if="isCollapsible"
|
|
|
|
class="gl-border-l-1 gl-border-l-solid gl-border-gray-100 gl-ml-3 gl-pl-3 gl-h-6"
|
|
|
|
>
|
2021-10-01 09:11:45 +00:00
|
|
|
<gl-button
|
|
|
|
v-gl-tooltip
|
|
|
|
:title="collapseButtonLabel"
|
|
|
|
:aria-expanded="`${!isCollapsed}`"
|
|
|
|
:aria-label="collapseButtonLabel"
|
|
|
|
:icon="isCollapsed ? 'chevron-lg-down' : 'chevron-lg-up'"
|
|
|
|
category="tertiary"
|
|
|
|
data-testid="toggle-button"
|
2021-10-06 15:11:48 +00:00
|
|
|
size="small"
|
2021-10-01 09:11:45 +00:00
|
|
|
@click="toggleCollapsed"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-10-27 12:08:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-29 12:11:22 +00:00
|
|
|
<div
|
|
|
|
v-if="!isCollapsed"
|
2021-10-12 15:12:08 +00:00
|
|
|
class="mr-widget-grouped-section gl-relative"
|
2021-09-29 12:11:22 +00:00
|
|
|
data-testid="widget-extension-collapsed-section"
|
|
|
|
>
|
2020-10-27 12:08:33 +00:00
|
|
|
<div v-if="isLoadingExpanded" class="report-block-container">
|
2021-07-07 09:08:35 +00:00
|
|
|
<gl-loading-icon size="sm" inline /> {{ __('Loading...') }}
|
2020-10-27 12:08:33 +00:00
|
|
|
</div>
|
|
|
|
<smart-virtual-list
|
2021-11-24 12:10:21 +00:00
|
|
|
v-else-if="hasFullData"
|
2020-10-27 12:08:33 +00:00
|
|
|
:length="fullData.length"
|
|
|
|
:remain="20"
|
|
|
|
:size="32"
|
|
|
|
wtag="ul"
|
|
|
|
wclass="report-block-list"
|
2021-10-12 15:12:08 +00:00
|
|
|
class="report-block-container gl-px-5 gl-py-0"
|
2020-10-27 12:08:33 +00:00
|
|
|
>
|
2021-10-06 12:11:40 +00:00
|
|
|
<li
|
2021-10-12 15:12:08 +00:00
|
|
|
v-for="(data, index) in fullData"
|
2021-10-06 12:11:40 +00:00
|
|
|
:key="data.id"
|
2021-10-12 15:12:08 +00:00
|
|
|
:class="{
|
|
|
|
'gl-border-b-solid gl-border-b-1 gl-border-gray-100': index !== fullData.length - 1,
|
|
|
|
}"
|
2021-12-13 15:12:59 +00:00
|
|
|
class="gl-py-3 gl-pl-7"
|
2021-10-06 12:11:40 +00:00
|
|
|
data-testid="extension-list-item"
|
|
|
|
>
|
2021-12-13 15:12:59 +00:00
|
|
|
<div class="gl-w-full">
|
|
|
|
<div v-if="data.header" class="gl-mb-2">
|
|
|
|
<template v-if="isArray(data.header)">
|
|
|
|
<component
|
|
|
|
:is="headerI === 0 ? 'strong' : 'span'"
|
|
|
|
v-for="(header, headerI) in data.header"
|
|
|
|
:key="headerI"
|
|
|
|
v-safe-html="generateText(header)"
|
|
|
|
class="gl-display-block"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<strong v-else v-safe-html="generateText(data.header)"></strong>
|
|
|
|
</div>
|
|
|
|
<div class="gl-display-flex">
|
|
|
|
<status-icon
|
|
|
|
v-if="data.icon"
|
|
|
|
:icon-name="data.icon.name"
|
|
|
|
:size="12"
|
|
|
|
class="gl-pl-0"
|
|
|
|
/>
|
|
|
|
<gl-intersection-observer
|
|
|
|
:options="{ rootMargin: '100px', thresholds: 0.1 }"
|
|
|
|
class="gl-w-full"
|
|
|
|
@appear="appear(index)"
|
|
|
|
@disappear="disappear(index)"
|
|
|
|
>
|
|
|
|
<div class="gl-flex-wrap gl-display-flex gl-w-full">
|
|
|
|
<div class="gl-mr-4 gl-display-flex gl-align-items-center">
|
|
|
|
<p v-safe-html="generateText(data.text)" class="gl-m-0"></p>
|
|
|
|
</div>
|
|
|
|
<div v-if="data.link">
|
|
|
|
<gl-link :href="data.link.href">{{ data.link.text }}</gl-link>
|
|
|
|
</div>
|
2022-01-21 12:16:22 +00:00
|
|
|
<div v-if="data.supportingText">
|
|
|
|
<p v-safe-html="generateText(data.supportingText)" class="gl-m-0"></p>
|
|
|
|
</div>
|
2021-12-13 15:12:59 +00:00
|
|
|
<gl-badge v-if="data.badge" :variant="data.badge.variant || 'info'">
|
|
|
|
{{ data.badge.text }}
|
|
|
|
</gl-badge>
|
2022-01-21 12:16:22 +00:00
|
|
|
|
2021-12-13 15:12:59 +00:00
|
|
|
<actions
|
|
|
|
:widget="$options.label || $options.name"
|
|
|
|
:tertiary-buttons="data.actions"
|
|
|
|
class="gl-ml-auto"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<p
|
|
|
|
v-if="data.subtext"
|
|
|
|
v-safe-html="generateText(data.subtext)"
|
|
|
|
class="gl-m-0 gl-font-sm"
|
|
|
|
></p>
|
|
|
|
</gl-intersection-observer>
|
2020-10-27 12:08:33 +00:00
|
|
|
</div>
|
2021-12-13 15:12:59 +00:00
|
|
|
</div>
|
2020-10-27 12:08:33 +00:00
|
|
|
</li>
|
|
|
|
</smart-virtual-list>
|
2021-10-12 15:12:08 +00:00
|
|
|
<div
|
|
|
|
:class="{ show: showFade }"
|
2021-12-08 18:12:44 +00:00
|
|
|
class="fade mr-extenson-scrim gl-absolute gl-left-0 gl-bottom-0 gl-w-full gl-h-7 gl-pointer-events-none"
|
2021-10-12 15:12:08 +00:00
|
|
|
></div>
|
2020-10-27 12:08:33 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|