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
|
<script>
import { GlAlert, GlLoadingIcon, GlTable } from '@gitlab/ui';
import Papa from 'papaparse';
export default {
components: {
GlTable,
GlAlert,
GlLoadingIcon,
},
props: {
csv: {
type: String,
required: true,
},
},
data() {
return {
items: [],
errorMessage: null,
loading: true,
};
},
mounted() {
const parsed = Papa.parse(this.csv, { skipEmptyLines: true });
this.items = parsed.data;
if (parsed.errors.length) {
this.errorMessage = parsed.errors.map((e) => e.message).join('. ');
}
this.loading = false;
},
};
</script>
<template>
<div class="container-fluid md gl-mt-3 gl-mb-3">
<div v-if="loading" class="gl-text-center loading">
<gl-loading-icon class="gl-mt-5" size="lg" />
</div>
<div v-else>
<gl-alert v-if="errorMessage" variant="danger" :dismissible="false">
{{ errorMessage }}
</gl-alert>
<gl-table
:empty-text="__('No CSV data to display.')"
:items="items"
:fields="$options.fields"
show-empty
thead-class="gl-display-none"
/>
</div>
</div>
</template>
|