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,
|
|
|
|
},
|
2022-05-07 20:08:51 +05:30
|
|
|
remoteFile: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-09-30 23:02:18 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
items: [],
|
2021-10-27 15:23:28 +05:30
|
|
|
papaParseErrors: [],
|
2021-09-30 23:02:18 +05:30
|
|
|
loading: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2022-05-07 20:08:51 +05:30
|
|
|
if (!this.remoteFile) {
|
|
|
|
const parsed = Papa.parse(this.csv, { skipEmptyLines: true });
|
|
|
|
this.handleParsedData(parsed);
|
|
|
|
} else {
|
|
|
|
Papa.parse(this.csv, {
|
|
|
|
download: true,
|
|
|
|
skipEmptyLines: true,
|
|
|
|
complete: (parsed) => {
|
|
|
|
this.handleParsedData(parsed);
|
|
|
|
},
|
|
|
|
});
|
2021-09-30 23:02:18 +05:30
|
|
|
}
|
2022-05-07 20:08:51 +05:30
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleParsedData(parsed) {
|
|
|
|
this.items = parsed.data;
|
2021-09-30 23:02:18 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
if (parsed.errors.length) {
|
|
|
|
this.papaParseErrors = parsed.errors;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.loading = false;
|
|
|
|
},
|
2021-09-30 23:02:18 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</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>
|