Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/utils/files/exportBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,10 @@ const getColumns = (req: any, params: ExportBatchParams): Promise<any[]> => {
if (Object.prototype.hasOwnProperty.call(data.data, field)) {
const meta = data.data[field];
const rawColumns = getColumnsFromMeta(meta, params.fields);
const columns = rawColumns.filter((x) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RenzoPrats
just noticed that this is breaking some of the queries
indeed, the code there put too many fields in the export

params.fields.find((f) => f.name === x.name)
);
// Edits the column to match with the fields
columns.forEach((column) => {
rawColumns.forEach((column) => {
const queryField = params.fields.find(
(f) => f.name === column.name
(f) => f.name.toLowerCase() === column.name.toLowerCase()
);
column.title = queryField.title;
if (column.subColumns) {
Expand All @@ -226,7 +223,7 @@ const getColumns = (req: any, params: ExportBatchParams): Promise<any[]> => {
}
}
});
resolve(columns);
resolve(rawColumns);
}
}
});
Expand Down
26 changes: 18 additions & 8 deletions src/utils/files/getRowsFromMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ const setMultiselectRow = (column: any, data: any, row: any) => {
} else {
let value: any;
// If it's a referenceData field, extract value differently.
if (column.name.includes('.') && column.meta.field.generated) {
if (column.meta.field.graphQLFieldName) {
const path = column.name.split('.')[0];
const attribute = column.name.split('.')[1];
const values = get(data, path);
if (Array.isArray(values)) {
value = values.map((x) => x[attribute]);
const lowercasedValues = values.map((obj) => {
const lowercasedObject = Object.keys(obj).reduce((acc, key) => {
acc[key.toLowerCase()] = obj[key];
return acc;
}, {});
return lowercasedObject;
});
value = lowercasedValues.map((x) => x[attribute.toLowerCase()]);
}
} else {
value = get(data, column.field);
Expand Down Expand Up @@ -89,12 +96,15 @@ export const getRowsFromMeta = (columns: any[], records: any[]): any[] => {
}
case 'dropdown': {
let value: any = get(data, column.field);
const choices = column.meta.field.choices || [];
if (choices.length > 0) {
if (Array.isArray(value)) {
value = value.map((x) => getText(choices, x));
} else {
value = getText(choices, value);
// Only enter if not reference data
if (!column.meta.field.graphQLFieldName) {
const choices = column.meta.field.choices || [];
if (choices.length > 0) {
if (Array.isArray(value)) {
value = value.map((x) => getText(choices, x));
} else {
value = getText(choices, value);
}
}
}
set(row, column.name, Array.isArray(value) ? value.join(',') : value);
Expand Down