Skip to content
Closed
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
5 changes: 4 additions & 1 deletion src/components/PurchaseOrderDetail.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<template>
<div v-for="(poItems, index) in itemsByPoId" :key="index">
<div v-if="!itemsByPoId || Object.keys(itemsByPoId).length === 0" class="empty-state ion-margin-top">
{{ translate("No purchase orders found") }}
</div>
<div v-else v-for="(poItems, index) in itemsByPoId" :key="index">
<ion-item lines="none">
<h3>{{ index }}</h3>
</ion-item>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"No logs found": "No logs found",
"No product found": "No product found",
"No products found": "No products found",
"No purchase orders found": "No purchase orders found",
"No results found": "No results found",
"No time zone found": "No time zone found",
"No shop selected": "No shop selected",
Expand Down
6 changes: 6 additions & 0 deletions src/views/PurchaseOrder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export default defineComponent({
try {
if (file) {
this.file = file;
this.selectedMappingId = "";
this.fieldMapping = Object.keys(this.fields).reduce((map, field) => {
map[field] = "";
return map;
}, {});
Comment on lines +116 to +120

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to reset the mapping state is also present in the ionViewDidEnter lifecycle hook (lines 103-107). To improve maintainability and adhere to the Don't Repeat Yourself (DRY) principle, consider extracting this block of code into a separate method and calling it from both parse and ionViewDidEnter.

For example, you could create a resetMappingState method:

resetMappingState() {
  this.selectedMappingId = "";
  this.fieldMapping = Object.keys(this.fields).reduce((map, field) => {
    map[field] = "";
    return map;
  }, {});
}

Then you can simply call this.resetMappingState(); here and in other places where this logic is needed, like the catch block.

this.content = await this.parseCsv(this.file);
this.fileColumns = Object.keys(this.content[0]);
showToast(translate("File uploaded successfully"));
Expand All @@ -121,6 +126,7 @@ export default defineComponent({
}
} catch {
this.content = []
this.selectedMappingId = "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In case of an error during file parsing, it's good practice to reset the entire mapping state for consistency, not just selectedMappingId. This should include resetting fieldMapping as well, similar to the logic in the try block. This ensures the UI is in a clean and predictable state after an error. This also reinforces the benefit of extracting this logic to a shared method.

          this.selectedMappingId = "";
          this.fieldMapping = Object.keys(this.fields).reduce((map, field) => {
            map[field] = "";
            return map;
          }, {});

showToast(translate("Please upload a valid purchase order csv to continue"));
}
},
Expand Down
Loading