Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error modal for importer view and show error modal when CSV column cannot be detected #237

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/ImporterView/ImporterMainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
@close="abortCurrentJob"
@execute="executeCurrentJob"
/>
<importer-view-error-modal
ref="errorModal"
:error-message="errorMessage"
/>
</div>
</template>

Expand All @@ -111,6 +115,7 @@ import ImporterViewProcessingModal from './ImporterViewProcessingModal.vue';
import ImporterViewCsvFormatModal from './ImporterViewCsvFormatModal.vue';
import ImporterViewPreview from './ImporterViewPreview.vue';
import ImporterViewValidationModal from './ImporterViewValidationModal.vue';
import ImporterViewErrorModal from './ImporterViewErrorModal.vue';

export default {
name: "ImporterMainView",
Expand All @@ -123,6 +128,7 @@ export default {
ImporterViewCsvFormatModal,
ImporterViewPreview,
ImporterViewValidationModal,
ImporterViewErrorModal,
},
props: {
schema: {
Expand All @@ -139,6 +145,7 @@ export default {
files: {},
processingFiles: [],
currentJob: null,
errorMessage: "",
}),
computed: {
isSchemaEmpty() {
Expand Down Expand Up @@ -377,7 +384,14 @@ export default {
const parallelism = format.parallelism;
const ignoreErrors = format.ignoreErrors;

const columns = await DuckDB.getCsvHeaderWithCustomSettings(key, delimiter, quote, escape, hasHeader);
let columns;
try {
columns = await DuckDB.getCsvHeaderWithCustomSettings(key, delimiter, quote, escape, hasHeader);
} catch (error) {
this.errorMessage = `Could not detect the columns with the given CSV format settings for file ${file.file.name}. Please check the settings and try again.`;
this.$refs.errorModal.showModal();
return;
}
columns.forEach((c, i) => {
c.type = DuckDB.convertDuckDBTypeToKuzuType(c.type);
c.name = hasHeader ? c.name : `column${i}`;
Expand Down
60 changes: 60 additions & 0 deletions src/components/ImporterView/ImporterViewErrorModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<div
ref="modal"
class="modal"
tabindex="-1"
>
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-body">
<div>
<p class="text-danger">
<i class="fas fa-exclamation-triangle" />
{{ errorMessage }}
</p>
</div>
</div>
<div class="modal-footer">
<span>
<button
type="button"
class="btn btn-danger"
@click="hideModal"
>
Close
</button>
</span>
</div>
</div>
</div>
</div>
</template>

<script lang="js">
import { Modal } from 'bootstrap';
export default {
name: "ImporterViewErrorModal",
props: {
errorMessage: {
type: String,
required: true,
},
},
mounted() {
this.modal = new Modal(this.$refs.modal);
},
beforeUnmount() {
this.modal.dispose();
},
methods: {
showModal() {
this.modal.show();
},
hideModal() {
this.modal.hide();
},
},
};
</script>

<style lang="scss" scoped></style>