Skip to content

Commit

Permalink
Merge pull request #306 from hotwax/#166
Browse files Browse the repository at this point in the history
Improved: Removed generating  mapping id from client side when creating a new mapping (#166).
  • Loading branch information
ravilodhi authored Dec 2, 2024
2 parents 3b00aba + 2e4c78e commit 6accaf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
10 changes: 2 additions & 8 deletions src/components/CreateMappingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,12 @@ export default defineComponent({
showToast(translate("Map all fields"));
return
}
const id = this.generateUniqueMappingPrefId();
await this.store.dispatch("user/createFieldMapping", { id, name: this.mappingName, value: this.fieldMapping, mappingType: this.mappingType })
this.closeModal(id);
const mappingPrefId = await this.store.dispatch("user/createFieldMapping", { name: this.mappingName, value: this.fieldMapping, mappingType: this.mappingType })
this.closeModal(mappingPrefId);
},
areAllFieldsSelected() {
return Object.values(this.fieldMapping).every(field => field !== "");
},
//Todo: Generating unique identifiers as we are currently storing in local storage. Need to remove it as we will be storing data on server.
generateUniqueMappingPrefId(): any {
const id = Math.floor(Math.random() * 1000);
return !this.fieldMappings[id] ? id : this.generateUniqueMappingPrefId();
}
},
setup() {
const store = useStore();
Expand Down
6 changes: 4 additions & 2 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ const actions: ActionTree<UserState, RootState> = {
},

async createFieldMapping({ commit }, payload) {
let mappingPrefId = ''
try {

const mappingTypes = JSON.parse(process.env.VUE_APP_MAPPING_TYPES as string)
const mappingPrefTypeEnumId = mappingTypes[payload.mappingType];

const params = {
mappingPrefId: payload.id,
mappingPrefName: payload.name,
mappingPrefValue: JSON.stringify(payload.value),
mappingPrefTypeEnumId
Expand All @@ -237,8 +237,9 @@ const actions: ActionTree<UserState, RootState> = {

// using id coming from server, as the random generated id sent in payload is not set as mapping id
// and an auto generated mapping from server is set as id
mappingPrefId = resp.data.mappingPrefId
const fieldMapping = {
id: resp.data.mappingPrefId,
id: mappingPrefId,
name: payload.name,
value: payload.value,
type: payload.mappingType
Expand All @@ -254,6 +255,7 @@ const actions: ActionTree<UserState, RootState> = {
logger.error('error', err)
showToast(translate('Failed to save CSV mapping.'))
}
return mappingPrefId;
},

async updateFieldMapping({ commit, state }, payload) {
Expand Down

0 comments on commit 6accaf6

Please sign in to comment.