From 26973e621f93b716515b93ec8ba0893ccba5d323 Mon Sep 17 00:00:00 2001 From: Ravi Lodhi Date: Tue, 26 Nov 2024 16:05:06 +0530 Subject: [PATCH] Improved: Removed generating mapping id from client side when creating a new mapping (#166). --- src/components/CreateMappingModal.vue | 10 ++-------- src/store/modules/user/actions.ts | 8 +++++--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/CreateMappingModal.vue b/src/components/CreateMappingModal.vue index 58c4255..56313c6 100644 --- a/src/components/CreateMappingModal.vue +++ b/src/components/CreateMappingModal.vue @@ -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(); diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index fdc070f..ab46cf7 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -219,16 +219,16 @@ const actions: ActionTree = { }, 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 + mappingPrefTypeEnumId: "TT" } const resp = await UserService.createFieldMapping(params); @@ -237,8 +237,9 @@ const actions: ActionTree = { // 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 @@ -254,6 +255,7 @@ const actions: ActionTree = { logger.error('error', err) showToast(translate('Failed to save CSV mapping.')) } + return mappingPrefId; }, async updateFieldMapping({ commit, state }, payload) {