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
|
<script>
import {
GlButtonGroup,
GlButton,
GlBadge,
GlFriendlyWrap,
GlFormCheckbox,
GlTooltipDirective,
} from '@gitlab/ui';
import { numberToHumanSize } from '~/lib/utils/number_utils';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import {
I18N_EXPIRED,
I18N_DOWNLOAD,
I18N_DELETE,
BULK_DELETE_FEATURE_FLAG,
I18N_BULK_DELETE_MAX_SELECTED,
} from '../constants';
export default {
name: 'ArtifactRow',
components: {
GlButtonGroup,
GlButton,
GlBadge,
GlFriendlyWrap,
GlFormCheckbox,
},
directives: {
GlTooltip: GlTooltipDirective,
},
mixins: [glFeatureFlagsMixin()],
inject: ['canDestroyArtifacts'],
props: {
artifact: {
type: Object,
required: true,
},
isSelected: {
type: Boolean,
required: true,
},
isLastRow: {
type: Boolean,
required: true,
},
isSelectedArtifactsLimitReached: {
type: Boolean,
required: true,
},
},
computed: {
isExpired() {
if (!this.artifact.expireAt) {
return false;
}
return Date.now() > new Date(this.artifact.expireAt).getTime();
},
isCheckboxDisabled() {
return this.isSelectedArtifactsLimitReached && !this.isSelected;
},
checkboxTooltip() {
return this.isCheckboxDisabled ? I18N_BULK_DELETE_MAX_SELECTED : '';
},
artifactSize() {
return numberToHumanSize(this.artifact.size);
},
canBulkDestroyArtifacts() {
return this.glFeatures[BULK_DELETE_FEATURE_FLAG] && this.canDestroyArtifacts;
},
},
methods: {
handleInput(checked) {
if (checked === this.isSelected) return;
this.$emit('selectArtifact', this.artifact, checked);
},
},
i18n: {
expired: I18N_EXPIRED,
download: I18N_DOWNLOAD,
delete: I18N_DELETE,
},
};
</script>
<template>
<div
class="gl-py-4"
:class="{ 'gl-border-b-solid gl-border-b-1 gl-border-gray-100': !isLastRow }"
>
<div class="gl-display-inline-flex gl-align-items-center gl-w-full">
<span v-if="canBulkDestroyArtifacts" class="gl-pl-5">
<gl-form-checkbox
v-gl-tooltip.right
:title="checkboxTooltip"
:checked="isSelected"
:disabled="isCheckboxDisabled"
@input="handleInput"
/>
</span>
<span
class="gl-w-half gl-pl-8 gl-display-flex gl-align-items-center"
data-testid="job-artifact-row-name"
>
<gl-friendly-wrap :text="artifact.name" />
<gl-badge size="sm" variant="neutral" class="gl-ml-2">
{{ artifact.fileType.toLowerCase() }}
</gl-badge>
<gl-badge v-if="isExpired" size="sm" variant="warning" icon="expire" class="gl-ml-2">
{{ $options.i18n.expired }}
</gl-badge>
</span>
<span class="gl-w-quarter gl-text-right gl-pr-5" data-testid="job-artifact-row-size">
{{ artifactSize }}
</span>
<span class="gl-w-quarter gl-text-right gl-pr-5">
<gl-button-group>
<gl-button
category="tertiary"
icon="download"
:title="$options.i18n.download"
:aria-label="$options.i18n.download"
:href="artifact.downloadPath"
data-testid="job-artifact-row-download-button"
/>
<gl-button
v-if="canDestroyArtifacts"
category="tertiary"
icon="remove"
:title="$options.i18n.delete"
:aria-label="$options.i18n.delete"
data-testid="job-artifact-row-delete-button"
@click="$emit('delete')"
/>
</gl-button-group>
</span>
</div>
</div>
</template>
|