Skip to content

Commit

Permalink
Improved: Removed generating mapping id from client side when creatin…
Browse files Browse the repository at this point in the history
…g a new mapping (#166).
  • Loading branch information
ravilodhi committed Nov 26, 2024
1 parent 3b00aba commit 26973e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 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
8 changes: 5 additions & 3 deletions src/store/modules/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ 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];

Check warning on line 226 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'mappingPrefTypeEnumId' is assigned a value but never used

Check warning on line 226 in src/store/modules/user/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'mappingPrefTypeEnumId' is assigned a value but never used

const params = {
mappingPrefId: payload.id,
mappingPrefName: payload.name,
mappingPrefValue: JSON.stringify(payload.value),
mappingPrefTypeEnumId
mappingPrefTypeEnumId: "TT"
}

const resp = await UserService.createFieldMapping(params);
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 26973e6

Please sign in to comment.