single file options in excel export

This commit is contained in:
Jan Prochazka 2020-11-19 12:07:30 +01:00
parent 7ccb1d9c90
commit 03451c6897
3 changed files with 39 additions and 2 deletions

View File

@ -21,6 +21,32 @@ const excelFormat: FileFormatDefinition = {
}; };
} }
}, },
args: [
{
type: 'checkbox',
name: 'singleFile',
label: 'Create single file',
direction: 'target',
},
],
getDefaultOutputName: (sourceName, values) => {
if (values.target_excel_singleFile) {
return sourceName;
}
return null;
},
getOutputParams: (sourceName, values) => {
if (values.target_excel_singleFile) {
return {
sheetName: values[`targetName_${sourceName}`] || sourceName,
fileName:'data.xlsx'
};
}
return null;
},
}; };
export default excelFormat; export default excelFormat;

View File

@ -14,4 +14,6 @@ export interface FileFormatDefinition {
[key: string]: any; [key: string]: any;
} }
) => void; ) => void;
getDefaultOutputName?: (sourceName, values) => string;
getOutputParams?: (sourceName, values) => any;
} }

View File

@ -10,7 +10,11 @@ export function getTargetName(source, values) {
const key = `targetName_${source}`; const key = `targetName_${source}`;
if (values[key]) return values[key]; if (values[key]) return values[key];
const format = findFileFormat(values.targetStorageType); const format = findFileFormat(values.targetStorageType);
if (format) return `${source}.${format.extension}`; if (format) {
const res = format.getDefaultOutputName ? format.getDefaultOutputName(source, values) : null;
if (res) return res;
return `${source}.${format.extension}`;
}
return source; return source;
} }
@ -113,10 +117,15 @@ function getTargetExpr(sourceName, values, targetConnection, targetDriver) {
const { targetStorageType } = values; const { targetStorageType } = values;
const format = findFileFormat(targetStorageType); const format = findFileFormat(targetStorageType);
if (format && format.writerFunc) { if (format && format.writerFunc) {
const outputParams = format.getOutputParams && format.getOutputParams(sourceName, values);
return [ return [
format.writerFunc, format.writerFunc,
{ {
fileName: getTargetName(sourceName, values), ...(outputParams
? outputParams
: {
fileName: getTargetName(sourceName, values),
}),
...extractApiParameters(values, 'target', format), ...extractApiParameters(values, 'target', format),
}, },
]; ];