2021-09-30 23:02:18 +05:30
|
|
|
<script>
|
2021-10-27 15:23:28 +05:30
|
|
|
import { GlLoadingIcon, GlTable } from '@gitlab/ui';
|
2021-09-30 23:02:18 +05:30
|
|
|
import Papa from 'papaparse';
|
2021-10-27 15:23:28 +05:30
|
|
|
import PapaParseAlert from '~/vue_shared/components/papa_parse_alert.vue';
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2021-10-27 15:23:28 +05:30
|
|
|
PapaParseAlert,
|
2021-09-30 23:02:18 +05:30
|
|
|
GlTable,
|
|
|
|
GlLoadingIcon,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
csv: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
items: [],
|
2021-10-27 15:23:28 +05:30
|
|
|
papaParseErrors: [],
|
2021-09-30 23:02:18 +05:30
|
|
|
loading: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
const parsed = Papa.parse(this.csv, { skipEmptyLines: true });
|
|
|
|
this.items = parsed.data;
|
|
|
|
|
|
|
|
if (parsed.errors.length) {
|
2021-10-27 15:23:28 +05:30
|
|
|
this.papaParseErrors = parsed.errors;
|
2021-09-30 23:02:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
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>
|
2021-10-27 15:23:28 +05:30
|
|
|
<papa-parse-alert v-if="papaParseErrors.length" :papa-parse-errors="papaParseErrors" />
|
2021-09-30 23:02:18 +05:30
|
|
|
<gl-table
|
|
|
|
:empty-text="__('No CSV data to display.')"
|
|
|
|
:items="items"
|
|
|
|
:fields="$options.fields"
|
|
|
|
show-empty
|
|
|
|
thead-class="gl-display-none"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|