-
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
Conversation
src/store/modules/user/mutations.ts
Outdated
@@ -19,6 +19,14 @@ const mutations: MutationTree <UserState> = { | |||
}, | |||
[types.USER_INSTANCE_URL_UPDATED] (state, payload) { | |||
state.instanceUrl = payload; | |||
}, | |||
[types.USER_FIELD_MAPPINGS_UPDATED] (state, payload) { | |||
const mapping = state.fieldMappings.find((mapping: any) => mapping.name === payload.name ); |
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.
I think this should be part of action
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.
Updated the code.
src/views/PurchaseOrder.vue
Outdated
fields: { | ||
orderId: "", | ||
productSku: "", | ||
date: "", |
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.
date: "", | |
orderDate: "", |
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.
Updated the variable name
src/store/modules/user/index.ts
Outdated
@@ -12,6 +12,7 @@ const userModule: Module<UserState, RootState> = { | |||
current: null, | |||
currentFacility: {}, | |||
instanceUrl: '', | |||
fieldMappings: [] |
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.
We could have it as object with key as mappingPrefId and value as object having mappingPrefId, mappingPrefName, mappingPrefTypeEnumId and mappingPrefValue
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.
Created it as an object with key as mapping name and value as mapping fields.
src/views/PurchaseOrder.vue
Outdated
dateField: "", | ||
quantityField: "", | ||
facilityField: "", | ||
fields: { |
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.
Why not fieldMapping?
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.
Updated the variable name
src/views/PurchaseOrder.vue
Outdated
const mapping = JSON.parse(JSON.stringify(event.detail.value)); | ||
this.fields = mapping.fieldMapping; | ||
this.mappingName = mapping.name; | ||
} | ||
this.orderItemsList = this.content.map(item => { |
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.
I think this should be done with review only
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.
Made the requested change.
src/views/PurchaseOrder.vue
Outdated
mapFields(event) { | ||
if(event && event.detail.value){ | ||
const mapping = JSON.parse(JSON.stringify(event.detail.value)); | ||
this.fields = mapping.fieldMapping; |
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.
this.fields = mapping.fieldMapping; | |
this.fields = mapping.fieldMapping; |
name:'PurchaseOrderDetail' | ||
}) | ||
}, | ||
mapFields(event) { |
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.
We could check if mapping fields exist in csv
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.
Made the requested change.
Also displayed a toast if any of the fields is missing.
Could you please share some screenshots and videos for the change? |
…into #2hran7u-updated
…sv(#2hran7u-updated)
Sure Sir, added in the PR description. |
src/views/PurchaseOrder.vue
Outdated
orderItemsList: [], | ||
} | ||
}, | ||
methods: { | ||
saveMapping() { | ||
if (this.mappingName) { | ||
const mappingPrefId = Math.floor(Math.random() * 1000); |
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.
I think we should check if the id already exists.
src/views/PurchaseOrder.vue
Outdated
orderItemsList: [], | ||
} | ||
}, | ||
methods: { | ||
generateUniqueId(id) { |
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
… field mapping applied(#2hran7u)
src/views/PurchaseOrder.vue
Outdated
if(event && event.detail.value) { | ||
const fieldMapping = JSON.parse(JSON.stringify(event.detail.value)); | ||
for(const field in fieldMapping.mappingPrefValue){ | ||
if(!Object.keys(this.content[0]).includes(fieldMapping.mappingPrefValue[field])) fieldMapping.mappingPrefValue[field] = ""; |
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.
We could store Object.keys(this.content[0]) to reuse
src/views/PurchaseOrder.vue
Outdated
mapFields(event) { | ||
if(event && event.detail.value) { | ||
const fieldMapping = JSON.parse(JSON.stringify(event.detail.value)); | ||
for(const field in fieldMapping.mappingPrefValue){ |
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.
We could use reduce() here
…into #2hran7u-updated
const missingFields = Object.values(fieldMapping.mappingPrefValue).filter(field => { | ||
if(!Object.keys(this.content[0]).includes(field)) return field; | ||
}); | ||
if(missingFields.length) showToast(translate(`Some of the mapping fields are missing in the CSV: \n ${ missingFields.join(", ") }`)) |
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.
I think we could pass missingFields as variable
Refer this code
https://github.com/hotwax/preorder/blob/main/src/views/product-details.vue#L347
Related Issues
Closes #81
Short Description and Why It's Useful
Screenshots of Visual Changes before/after (If There Are Any)
screen-recorder-fri-nov-04-2022-12-57-09.webm
IMPORTANT NOTICE - Remember to add changelog entry
Contribution and Currently Important Rules Acceptance