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
|
<script>
import { GlAlert } from '@gitlab/ui';
import * as Sentry from '~/sentry/sentry_browser_wrapper';
import { s__ } from '~/locale';
import Composer from '~/packages_and_registries/package_registry/components/details/metadata/composer.vue';
import Conan from '~/packages_and_registries/package_registry/components/details/metadata/conan.vue';
import Maven from '~/packages_and_registries/package_registry/components/details/metadata/maven.vue';
import Nuget from '~/packages_and_registries/package_registry/components/details/metadata/nuget.vue';
import Pypi from '~/packages_and_registries/package_registry/components/details/metadata/pypi.vue';
import {
FETCH_PACKAGE_METADATA_ERROR_MESSAGE,
PACKAGE_TYPE_COMPOSER,
PACKAGE_TYPE_CONAN,
PACKAGE_TYPE_MAVEN,
PACKAGE_TYPE_NUGET,
PACKAGE_TYPE_PYPI,
} from '~/packages_and_registries/package_registry/constants';
import getPackageMetadataQuery from '../../graphql/queries/get_package_metadata.query.graphql';
import AdditionalMetadataLoader from './additional_metadata_loader.vue';
export default {
components: {
Composer,
Conan,
GlAlert,
Maven,
Nuget,
Pypi,
AdditionalMetadataLoader,
},
props: {
packageId: {
type: String,
required: true,
},
packageType: {
type: String,
required: true,
},
},
apollo: {
packageMetadata: {
query: getPackageMetadataQuery,
variables() {
return {
id: this.packageId,
};
},
update(data) {
return data.package?.metadata || null;
},
error(error) {
this.fetchPackageMetadataError = true;
Sentry.captureException(error);
},
},
},
data() {
return {
packageMetadata: null,
fetchPackageMetadataError: false,
};
},
computed: {
metadataComponent() {
return {
[PACKAGE_TYPE_COMPOSER]: Composer,
[PACKAGE_TYPE_CONAN]: Conan,
[PACKAGE_TYPE_MAVEN]: Maven,
[PACKAGE_TYPE_NUGET]: Nuget,
[PACKAGE_TYPE_PYPI]: Pypi,
}[this.packageType];
},
showMetadata() {
return this.metadataComponent && this.packageMetadata;
},
isLoading() {
return this.$apollo.queries.packageMetadata.loading;
},
},
i18n: {
componentTitle: s__('PackageRegistry|Additional metadata'),
fetchPackageMetadataErrorMessage: FETCH_PACKAGE_METADATA_ERROR_MESSAGE,
},
};
</script>
<template>
<div>
<h3 v-if="isLoading || showMetadata" class="gl-font-lg" data-testid="title">
{{ $options.i18n.componentTitle }}
</h3>
<gl-alert
v-if="fetchPackageMetadataError"
variant="danger"
@dismiss="fetchPackageMetadataError = false"
>
{{ $options.i18n.fetchPackageMetadataErrorMessage }}
</gl-alert>
<additional-metadata-loader v-if="isLoading" />
<div
v-if="showMetadata"
class="gl-bg-gray-50 gl-inset-border-1-gray-100 gl-rounded-base"
data-testid="main"
>
<component
:is="metadataComponent"
:package-metadata="packageMetadata"
data-testid="component-is"
/>
</div>
</div>
</template>
|