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
|
<script>
import { GlSprintf, GlBadge, GlResizeObserverDirective } from '@gitlab/ui';
import { GlBreakpointInstance } from '@gitlab/ui/dist/utils';
import { __, s__, sprintf } from '~/locale';
import { formatDate } from '~/lib/utils/datetime_utility';
import PackageTags from '~/packages_and_registries/shared/components/package_tags.vue';
import { PACKAGE_TYPE_NUGET } from '~/packages_and_registries/package_registry/constants';
import { getPackageTypeLabel } from '~/packages_and_registries/package_registry/utils';
import MetadataItem from '~/vue_shared/components/registry/metadata_item.vue';
import TitleArea from '~/vue_shared/components/registry/title_area.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
export default {
name: 'PackageTitle',
components: {
TitleArea,
GlSprintf,
PackageTags,
MetadataItem,
GlBadge,
TimeAgoTooltip,
},
directives: {
GlResizeObserver: GlResizeObserverDirective,
},
inject: ['isGroupPage'],
i18n: {
lastDownloadedAt: s__('PackageRegistry|Last downloaded %{dateTime}'),
packageInfo: __('v%{version} published %{timeAgo}'),
},
props: {
packageEntity: {
type: Object,
required: true,
},
},
data() {
return {
isDesktop: true,
};
},
computed: {
packageLastDownloadedAtDisplay() {
return sprintf(this.$options.i18n.lastDownloadedAt, {
dateTime: formatDate(this.packageEntity.lastDownloadedAt, 'mmm d, yyyy'),
});
},
packageTypeDisplay() {
return getPackageTypeLabel(this.packageEntity.packageType);
},
packagePipeline() {
return this.packageEntity.pipelines?.nodes[0];
},
packageIcon() {
if (this.packageEntity.packageType === PACKAGE_TYPE_NUGET) {
return this.packageEntity.metadata?.iconUrl || null;
}
return null;
},
hasTagsToDisplay() {
return Boolean(this.packageEntity.tags?.nodes && this.packageEntity.tags?.nodes.length);
},
},
mounted() {
this.checkBreakpoints();
},
methods: {
checkBreakpoints() {
this.isDesktop = GlBreakpointInstance.isDesktop();
},
},
};
</script>
<template>
<title-area
v-gl-resize-observer="checkBreakpoints"
:title="packageEntity.name"
:avatar="packageIcon"
data-qa-selector="package_title"
>
<template #sub-header>
<div data-testid="sub-header" class="gl-display-flex gl-gap-3">
<gl-sprintf :message="$options.i18n.packageInfo">
<template #version>
{{ packageEntity.version }}
</template>
<template #timeAgo>
<time-ago-tooltip v-if="packageEntity.createdAt" :time="packageEntity.createdAt" />
</template>
</gl-sprintf>
<package-tags
v-if="isDesktop && hasTagsToDisplay"
:tag-display-limit="2"
:tags="packageEntity.tags.nodes"
hide-label
/>
<!-- we need to duplicate the package tags on mobile to ensure proper styling inside the flex wrap -->
<template v-else-if="hasTagsToDisplay">
<gl-badge
v-for="(tag, index) in packageEntity.tags.nodes"
:key="index"
class="gl-my-1"
data-testid="tag-badge"
variant="info"
size="sm"
>
{{ tag.name }}
</gl-badge>
</template>
</div>
</template>
<template v-if="packageTypeDisplay" #metadata-type>
<metadata-item data-testid="package-type" icon="package" :text="packageTypeDisplay" />
</template>
<template v-if="isGroupPage && packagePipeline" #metadata-pipeline>
<metadata-item
data-testid="pipeline-project"
icon="review-list"
:text="packagePipeline.project.name"
:link="packagePipeline.project.webUrl"
/>
</template>
<template v-if="packagePipeline && packagePipeline.ref" #metadata-ref>
<metadata-item data-testid="package-ref" icon="branch" :text="packagePipeline.ref" />
</template>
<template v-if="packageEntity.lastDownloadedAt" #metadata-last-downloaded-at>
<metadata-item
data-testid="package-last-downloaded-at"
icon="download"
:text="packageLastDownloadedAtDisplay"
size="m"
/>
</template>
<template #right-actions>
<slot name="delete-button"></slot>
</template>
</title-area>
</template>
|