Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/ members csv uploading [WTEL-4865] #766

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/modules/_shared/upload-csv-popup/scripts/normalizeCSVData.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ const normalizeCSVData = ({ data, mappings }) => {
[name]: {
required,
value: Array.isArray(csv) ? csv.map((csv) => dataItem[csv]) : dataItem[csv],
mappingIndexes: Array.isArray(csv) ? csv.map((csv, index) => !isEmpty(dataItem[csv]) ? index : null) : null,
},
};
}, {});

const filteredEmptyValues = Object.entries(normalized).reduce(
(filtered, [name, { required, value }]) => {
(filtered, [name, { required, value, mappingIndexes }]) => {
let filteredValue;
if (Array.isArray(value)) {
filteredValue = value.filter((item) => !isEmpty(item));
Expand All @@ -39,6 +40,8 @@ const normalizeCSVData = ({ data, mappings }) => {
}

const isValueEmpty = isEmpty(filteredValue);
console.log('isValueEmpty', isValueEmpty);


if (required && isValueEmpty) {
throw new Error(`Required field is empty: ${name} on row ${index + 1}`);
Expand All @@ -48,7 +51,10 @@ const normalizeCSVData = ({ data, mappings }) => {
? filtered
: {
...filtered,
[name]: filteredValue,
[name]: {
value: filteredValue,
mappingIndexes
},
};
},
{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,25 @@ export default {
async normalizeData(data) {
await this.getCommunicationTypes();

return data.map((item) => {
// TODO: винести в окремий метод або файл
const modifiedData = data.map(item => {
return Object.entries(item).reduce((acc, [key, { value, mappingIndexes }]) => {
let result;

if (key === 'variables') {
result = {
...acc,
[key]: { value, mappingIndexes }
}
} else {
result = { ...acc, [key]: value }
}

return result;
}, {});
});

return modifiedData.map((item) => {
const normalizedItem = {
...item,
};
Expand All @@ -50,14 +68,17 @@ export default {
normalizedItem.agentId = undefined;
}
if (normalizedItem.variables) {
const variablesMappings = this.mappingFields.find((field) => field.name === 'variables');
normalizedItem.variables = item.variables.reduce(
(variables, variable, index) => ({
// csv is arr of tags
const { csv } = this.mappingFields.find((field) => field.name === 'variables');
const { mappingIndexes, value } = item.variables;

let currentIndex = 0; // to track current index in value array
normalizedItem.variables = mappingIndexes.reduce((variables, mappingIndex, index) => {
return {
...variables,
[variablesMappings.csv[index]]: variable, // csv is arr of tags
}),
{},
);
[csv[index]]: mappingIndex !== null ? value[currentIndex++] : '',
};
}, {});
}
if (!normalizedItem.priority) {
normalizedItem.priority = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import UploadCsvPreviewPopup from '../../../../_shared/upload-csv-popup/componen
import QueueMembersAPI from '../../../../contact-center/modules/queues/modules/members/api/queueMembers';
import normalizeCsvMembers from '../../../../contact-center/modules/queues/modules/members/mixins/normalizeCsvMembers';
import ImportCsvMemberMappings from '../lookups/ImportCsvMemberMappings.lookup';
import ImportCsvRouteNames from '../router/_internals/ImportCsvRouteNames.enum.js';

export default {
name: 'ImportCsvUploadAction',
Expand Down
Loading