Skip to content

Commit

Permalink
Merge pull request #594 from webitel/fix/members-csv-empty-required
Browse files Browse the repository at this point in the history
Fix/members csv empty required
  • Loading branch information
dlohvinov authored Jan 10, 2024
2 parents 8663525 + 0c8ac91 commit 4e559bd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getNamespacedState
from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import { mapActions, mapState, mapGetters } from 'vuex';
import { mapActions, mapGetters, mapState } from 'vuex';
import baseTableMixin from '../../baseMixins/baseTableMixin/baseTableMixin';
import objectTableAccessControlMixin
from './_internals/objectTableAccessControlMixin';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import getNamespacedState
from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import { mapActions, mapState, mapGetters } from 'vuex';
import { mapActions, mapGetters, mapState } from 'vuex';
import ObjectListPopup
from '../../../components/utils/object-list-popup/object-list-popup.vue';
import OnePlusMany
Expand Down
26 changes: 19 additions & 7 deletions src/modules/_shared/upload-csv-popup/mixins/uploadCSVMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,25 @@ export default {
},
normalizeCSVData(data) {
const nonEmptyMappingFields = this.mappingFields.filter((field) => !isEmpty(field.csv));
return data.map((dataItem) => (
nonEmptyMappingFields.reduce((normalizedItem, { name, csv }) => ({
...normalizedItem,
[name]: Array.isArray(csv)
? csv.map((csv) => dataItem[csv])
: dataItem[csv],
}), {})
return data.map((dataItem, index) => (
nonEmptyMappingFields.reduce((
normalizedItem,
{ name, csv, required },
) => {
// if one of required fields on any row is empty, throw an error
if (required &&
isEmpty(dataItem[csv])) {
// +1 because of indexing starts from 0, but rows counting from 1
throw new Error(`Required field is empty: ${name} on row ${index +
1}`);
}
return {
...normalizedItem,
[name]: Array.isArray(csv)
? csv.map((csv) => dataItem[csv])
: dataItem[csv],
};
}, {})
));
},
async readFile() {
Expand Down

0 comments on commit 4e559bd

Please sign in to comment.