From 26973e621f93b716515b93ec8ba0893ccba5d323 Mon Sep 17 00:00:00 2001 From: Ravi Lodhi Date: Tue, 26 Nov 2024 16:05:06 +0530 Subject: [PATCH 1/2] 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) { From 2e4c78ef04b9eeea8b90046cf2404757794e1ec1 Mon Sep 17 00:00:00 2001 From: Ravi Lodhi Date: Mon, 2 Dec 2024 18:30:43 +0530 Subject: [PATCH 2/2] Fixed: Corrected unwanted change (#166). --- src/store/modules/user/actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/modules/user/actions.ts b/src/store/modules/user/actions.ts index ab46cf7..d576428 100644 --- a/src/store/modules/user/actions.ts +++ b/src/store/modules/user/actions.ts @@ -228,7 +228,7 @@ const actions: ActionTree = { const params = { mappingPrefName: payload.name, mappingPrefValue: JSON.stringify(payload.value), - mappingPrefTypeEnumId: "TT" + mappingPrefTypeEnumId } const resp = await UserService.createFieldMapping(params);