generated from hotwax/dxp-components
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Implemented logic for storing and applying multiple field mappings(#2hran7u) #84
Merged
Merged
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
4df3d0c
Implemented logic for storing and applying multiple field mappings(#2…
disha1202 ae4e4cb
Improved code(#2hran7u)
disha1202 42b8699
Updated markup(#2hran7u)
disha1202 94e490c
Improved code(#2hran7u)
disha1202 6cdc753
Fixed: typo and unwanted mutation of mappings(#2hran7u)
disha1202 737b818
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 39a275d
Reverted unwanted changes(#2hran7u)
disha1202 d0b73a3
Merge branch 'main' into #2hran7u-updated
adityasharma7 c6ce6d2
Improved code and variable name(#2hran7u)
disha1202 5a00df2
Merge branch '#2hran7u-updated' of https://github.com/disha1202/impor…
disha1202 8e3c6bb
Updated code to display toast if mapped fields are not found in the c…
disha1202 5a2f32c
Improved logic to verify whether all the mapped fields are present in…
disha1202 3eb3ff1
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 630e83b
Removed unwanted code(#2hran7u)
disha1202 3585673
Merge branch 'main' into #2hran7u-updated
adityasharma7 27cc673
Merge branch 'main' into #2hran7u-updated
adityasharma7 6ceb077
Implemented logic to store mappings corresponding to a unique mapping…
disha1202 84d8b94
Merge branch '#2hran7u-updated' of https://github.com/disha1202/impor…
disha1202 42171a2
Removed unwanted code and implemented logic to generate unique mappin…
disha1202 59c1734
Fixed: code to generate unique mappingPrefId(#2hran7u)
disha1202 3efaddd
Removed unwanted code (#2hran7u)
disha1202 fe85692
Updated method name(#2hran7u)
disha1202 8afb009
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 25679b6
Resolved merge conflicts(#2hran7u)
disha1202 2872014
Fixed: wrong variable name(#2hran7u)
disha1202 360a5c0
Updated code to block user navigation if the csv does not contain the…
disha1202 13c0adc
Improved code and added comments(#2hran7u)
disha1202 8501490
Merge branch 'main' into #2hran7u-updated
adityasharma7 e364e3c
Updated toast message(#2hran7u)
disha1202 4af7188
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 bf71aba
Merge branch '#2hran7u-updated' of https://github.com/disha1202/impor…
disha1202 71c23cd
Added missing import(#2hran7u)
disha1202 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,56 +13,70 @@ | |
<ion-label>{{ file.name ? $t("Purchase order ") + file.name : $t('Purchase order') }}</ion-label> | ||
<input @change="getFile" ref="file" class="ion-hide" type="file" id="inputFile"/> | ||
<label for="inputFile">{{ $t("Upload") }}</label> | ||
</ion-item> | ||
</ion-item> | ||
<ion-item lines="none"> | ||
<ion-label>{{ $t("Select mapping") }}</ion-label> | ||
<ion-select :disabled="!Object.keys(fieldMappings).length" interface="popover" @ionChange="mapFields"> | ||
<ion-select-option v-for="mapping in fieldMappings" :value="mapping" :key="mapping?.mappingPrefId">{{ mapping?.mappingPrefName }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
|
||
<ion-list> | ||
<ion-list-header>{{ $t("Select the column index for the following information in the uploaded CSV.") }}</ion-list-header> | ||
|
||
<ion-item> | ||
<ion-label>{{ $t("Order ID") }}</ion-label> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="orderIdField"> | ||
<ion-select-option :key="index" v-for="(prop, index) in Object.keys(content[0])">{{ prop }}</ion-select-option> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="fieldMapping.orderId"> | ||
<ion-select-option :key="index" v-for="(prop, index) in Object.keys(content[0])">{{ prop }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
|
||
<ion-item> | ||
<ion-label>{{ $t("Shopify product SKU") }}</ion-label> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="productSkuField"> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="fieldMapping.productSku"> | ||
<ion-select-option :key="index" v-for="(prop, index) in Object.keys(content[0])">{{ prop }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
|
||
<ion-item> | ||
<ion-label>{{ $t("Arrival date") }}</ion-label> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="dateField"> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="fieldMapping.orderDate"> | ||
<ion-select-option :key="index" v-for="(prop, index) in Object.keys(content[0])">{{ prop }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
|
||
<ion-item> | ||
<ion-label>{{ $t("Ordered quantity") }}</ion-label> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="quantityField"> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="fieldMapping.quantity"> | ||
<ion-select-option :key="index" v-for="(prop, index) in Object.keys(content[0])">{{ prop }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
|
||
<ion-item> | ||
<ion-label>{{ $t("Facility ID") }}</ion-label> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="facilityField"> | ||
<ion-select interface="popover" v-if="content.length" :placeholder = "$t('Select')" v-model="fieldMapping.facility"> | ||
<ion-select-option :key="index" v-for="(prop, index) in Object.keys(content[0])">{{ prop }}</ion-select-option> | ||
</ion-select> | ||
</ion-item> | ||
</ion-list> | ||
|
||
<ion-button color="medium" @click="mapFields" expand="block"> | ||
<ion-button color="medium" @click="review" expand="block"> | ||
{{ $t("Review") }} | ||
<ion-icon slot="end" :icon="arrowForwardOutline" /> | ||
</ion-button> | ||
|
||
<ion-item> | ||
<ion-label>{{ $t("Mapping name") }}</ion-label> | ||
<ion-input v-model="mappingName" /> | ||
</ion-item> | ||
<ion-button @click="saveMapping">{{ $t("Save mapping") }}</ion-button> | ||
|
||
</main> | ||
</ion-content> | ||
</ion-page> | ||
</template> | ||
<script> | ||
import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonItem, IonLabel, IonList, IonListHeader, IonMenuButton, IonButton, IonSelect, IonSelectOption, IonIcon } from "@ionic/vue"; | ||
import { IonPage, IonHeader, IonToolbar, IonTitle, IonContent, IonItem, IonInput, IonLabel, IonList, IonListHeader, IonMenuButton, IonButton, IonSelect, IonSelectOption, IonIcon } from "@ionic/vue"; | ||
import { defineComponent } from "vue"; | ||
import { useRouter } from 'vue-router'; | ||
import { useStore, mapGetters } from "vuex"; | ||
|
@@ -80,6 +94,7 @@ export default defineComponent({ | |
IonTitle, | ||
IonContent, | ||
IonItem, | ||
IonInput, | ||
IonLabel, | ||
IonButton, | ||
IonMenuButton, | ||
|
@@ -92,21 +107,42 @@ export default defineComponent({ | |
computed: { | ||
...mapGetters({ | ||
dateTimeFormat : 'user/getDateTimeFormat', | ||
fieldMappings: 'user/getFieldMappings' | ||
}) | ||
}, | ||
mounted(){ | ||
console.log(this.fieldMappings, "abc"); | ||
}, | ||
data() { | ||
return { | ||
file: "", | ||
content: [], | ||
orderIdField: "", | ||
productSkuField: "", | ||
dateField: "", | ||
quantityField: "", | ||
facilityField: "", | ||
fieldMapping: { | ||
orderId: "", | ||
productSku: "", | ||
orderDate: "", | ||
quantity: "", | ||
facility: "", | ||
}, | ||
mappingName: "", | ||
orderItemsList: [], | ||
} | ||
}, | ||
methods: { | ||
generateUniqueId(id) { | ||
if (!this.fieldMappings[id]) { | ||
return id; | ||
} | ||
return this.generateUniqueId(Math.floor(Math.random() * 1000)); | ||
}, | ||
saveMapping() { | ||
if (this.mappingName) { | ||
const mappingPrefId = this.generateUniqueId(Math.floor(Math.random() * 1000)); | ||
this.store.dispatch('user/updateFieldMappings', { mappingPrefId, mappingPrefName: this.mappingName, mappingPrefValue: JSON.parse(JSON.stringify(this.fieldMapping)) }) | ||
} else { | ||
showToast(translate("Enter mapping name")); | ||
} | ||
}, | ||
getFile(event) { | ||
this.file = event.target.files[0]; | ||
if(this.file){ | ||
|
@@ -118,29 +154,34 @@ export default defineComponent({ | |
showToast(translate("Something went wrong, Please try again")); | ||
} | ||
}, | ||
|
||
async parseFile(){ | ||
await parseCsv(this.file).then(res => { | ||
this.content = res; | ||
}) | ||
}, | ||
mapFields() { | ||
review() { | ||
this.orderItemsList = this.content.map(item => { | ||
return { | ||
orderId: item[this.orderIdField], | ||
shopifyProductSKU: item[this.productSkuField], | ||
shopifyProductUPC: item[this.productUpcField], | ||
arrivalDate: DateTime.fromFormat(item[this.dateField], this.dateTimeFormat).toFormat(this.dateTimeFormat), //This is to verify whether the date format is correct. | ||
quantityOrdered: item[this.quantityField], | ||
orderId: item[this.fieldMapping.orderId], | ||
shopifyProductSKU: item[this.fieldMapping.productSku], | ||
arrivalDate: DateTime.fromFormat(item[this.fieldMapping.orderDate], this.dateTimeFormat).toFormat(this.dateTimeFormat), //This is to verify whether the date format is correct. | ||
quantityOrdered: item[this.fieldMapping.quantity], | ||
facilityId: '', | ||
externalFacilityId: item[this.facilityField] | ||
externalFacilityId: item[this.fieldMapping.facility] | ||
} | ||
}) | ||
this.store.dispatch('order/updatedOrderList', this.orderItemsList); | ||
this.router.push({ | ||
name:'PurchaseOrderDetail' | ||
}) | ||
}, | ||
mapFields(event) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could check if mapping fields exist in csv There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made the requested change. |
||
if(event && event.detail.value) { | ||
const fieldMapping = JSON.parse(JSON.stringify(event.detail.value)); | ||
this.fieldMapping = fieldMapping.mappingPrefValue; | ||
this.mappingName = fieldMapping.mappingPrefName; | ||
} | ||
}, | ||
}, | ||
setup() { | ||
const router = useRouter(); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve method name, this is not generic method to generate id for any use case