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

Implemented logic for storing and applying multiple field mappings(#2hran7u) #84

Merged
merged 32 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
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 Nov 1, 2022
ae4e4cb
Improved code(#2hran7u)
disha1202 Nov 1, 2022
42b8699
Updated markup(#2hran7u)
disha1202 Nov 1, 2022
94e490c
Improved code(#2hran7u)
disha1202 Nov 1, 2022
6cdc753
Fixed: typo and unwanted mutation of mappings(#2hran7u)
disha1202 Nov 1, 2022
737b818
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 Nov 1, 2022
39a275d
Reverted unwanted changes(#2hran7u)
disha1202 Nov 1, 2022
d0b73a3
Merge branch 'main' into #2hran7u-updated
adityasharma7 Nov 3, 2022
c6ce6d2
Improved code and variable name(#2hran7u)
disha1202 Nov 4, 2022
5a00df2
Merge branch '#2hran7u-updated' of https://github.com/disha1202/impor…
disha1202 Nov 4, 2022
8e3c6bb
Updated code to display toast if mapped fields are not found in the c…
disha1202 Nov 4, 2022
5a2f32c
Improved logic to verify whether all the mapped fields are present in…
disha1202 Nov 4, 2022
3eb3ff1
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 Nov 16, 2022
630e83b
Removed unwanted code(#2hran7u)
disha1202 Nov 18, 2022
3585673
Merge branch 'main' into #2hran7u-updated
adityasharma7 Nov 18, 2022
27cc673
Merge branch 'main' into #2hran7u-updated
adityasharma7 Nov 18, 2022
6ceb077
Implemented logic to store mappings corresponding to a unique mapping…
disha1202 Nov 18, 2022
84d8b94
Merge branch '#2hran7u-updated' of https://github.com/disha1202/impor…
disha1202 Nov 18, 2022
42171a2
Removed unwanted code and implemented logic to generate unique mappin…
disha1202 Nov 21, 2022
59c1734
Fixed: code to generate unique mappingPrefId(#2hran7u)
disha1202 Nov 21, 2022
3efaddd
Removed unwanted code (#2hran7u)
disha1202 Nov 21, 2022
fe85692
Updated method name(#2hran7u)
disha1202 Nov 21, 2022
8afb009
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 Nov 21, 2022
25679b6
Resolved merge conflicts(#2hran7u)
disha1202 Nov 21, 2022
2872014
Fixed: wrong variable name(#2hran7u)
disha1202 Nov 21, 2022
360a5c0
Updated code to block user navigation if the csv does not contain the…
disha1202 Nov 21, 2022
13c0adc
Improved code and added comments(#2hran7u)
disha1202 Nov 21, 2022
8501490
Merge branch 'main' into #2hran7u-updated
adityasharma7 Nov 21, 2022
e364e3c
Updated toast message(#2hran7u)
disha1202 Nov 21, 2022
4af7188
Merge branch 'main' of https://github.com/hotwax/import into #2hran7u…
disha1202 Nov 21, 2022
bf71aba
Merge branch '#2hran7u-updated' of https://github.com/disha1202/impor…
disha1202 Nov 21, 2022
71c23cd
Added missing import(#2hran7u)
disha1202 Nov 21, 2022
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
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"Confirm": "Confirm",
"Date Format": "Date Format",
"Dismiss": "Dismiss",
"Enter mapping name": "Enter mapping name",
"Enter a custom date time format that you want to use when uploading documents to HotWax Commerce.": "Enter a custom date time format that you want to use when uploading documents to HotWax Commerce.",
"Facility": "Facility",
"Facility ID": "Facility ID",
Expand All @@ -29,6 +30,7 @@
"Leave page": "Leave page",
"Login": "Login",
"Logout": "Logout",
"Mapping name": "Mapping name",
"Luxon date time formats can be found": "Luxon date time formats can be found",
"Missing SKUs": "Missing SKUs",
"No time zone found": "No time zone found",
Expand All @@ -49,11 +51,13 @@
"Reset": "Reset",
"Reset password": "Reset password",
"Safety stock": "Safety stock",
"Save mapping": "Save mapping",
"Sample": "Sample",
"Save": "Save",
"Search products": "Search products",
"Search time zones": "Search time zones",
"Select": "Select",
"Select mapping": "Select mapping",
"Select time zone": "Select time zone",
"Select the column index for the following information in the uploaded CSV.": "Select the column index for the following information in the uploaded CSV.",
"Something went wrong": "Something went wrong",
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/user/UserState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default interface UserState {
current: object | null;
currentFacility: object;
instanceUrl: string;
fieldMappings: any;
preferredDateTimeFormat: string;
}
4 changes: 4 additions & 0 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ const actions: ActionTree<UserState, RootState> = {
*/
setUserInstanceUrl ({ commit }, payload){
commit(types.USER_INSTANCE_URL_UPDATED, payload)
},

updateFieldMappings({ commit }, payload){
commit(types.USER_FIELD_MAPPINGS_UPDATED, payload);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/store/modules/user/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const getters: GetterTree <UserState, RootState> = {
},
getInstanceUrl (state) {
const baseUrl = process.env.VUE_APP_BASE_URL;
return baseUrl ? baseUrl : state.instanceUrl;
return baseUrl ? baseUrl : state.instanceUrl;
},
getFieldMappings(state) {
return state.fieldMappings;
},
getDateTimeFormat (state) {
return state.preferredDateTimeFormat;
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const userModule: Module<UserState, RootState> = {
current: null,
currentFacility: {},
instanceUrl: '',
fieldMappings: {},
preferredDateTimeFormat: ''
},
getters,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/user/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const USER_END_SESSION = SN_USER + '/END_SESSION'
export const USER_INFO_UPDATED = SN_USER + '/INFO_UPDATED'
export const USER_CURRENT_FACILITY_UPDATED = SN_USER + '/CURRENT_FACILITY_UPDATED'
export const USER_INSTANCE_URL_UPDATED = SN_USER + '/INSTANCE_URL_UPDATED'
export const USER_DATETIME_FORMAT_UPDATED = SN_USER + '/DATETIME_FORMAT_UPDATED'
export const USER_FIELD_MAPPINGS_UPDATED = SN_USER + '/FIELD_MAPPINGS_UPDATED'
export const USER_DATETIME_FORMAT_UPDATED = SN_USER + '/DATETIME_FORMAT_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/user/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const mutations: MutationTree <UserState> = {
[types.USER_INSTANCE_URL_UPDATED] (state, payload) {
state.instanceUrl = payload;
},
[types.USER_FIELD_MAPPINGS_UPDATED] (state, payload) {
state.fieldMappings[payload.mappingPrefId] = payload;
},
[types.USER_DATETIME_FORMAT_UPDATED] (state, payload) {
state.preferredDateTimeFormat = payload;
}
Expand Down
85 changes: 63 additions & 22 deletions src/views/PurchaseOrder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -80,6 +94,7 @@ export default defineComponent({
IonTitle,
IonContent,
IonItem,
IonInput,
IonLabel,
IonButton,
IonMenuButton,
Expand All @@ -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) {
Copy link
Contributor

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

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){
Expand All @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could check if mapping fields exist in csv

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made the requested change.
Also displayed a toast if any of the fields is missing.

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();
Expand Down