next csv params

This commit is contained in:
Jan Prochazka
2020-11-19 11:36:34 +01:00
parent 0cd3e393e8
commit 7ccb1d9c90
5 changed files with 21 additions and 6 deletions

View File

@@ -37,12 +37,11 @@ class CsvPrepareStream extends stream.Transform {
} }
} }
async function csvReader({ fileName, encoding = 'utf-8', header = true, delimiter, quoted, limitRows = undefined }) { async function csvReader({ fileName, encoding = 'utf-8', header = true, delimiter, limitRows = undefined }) {
console.log(`Reading file ${fileName}`); console.log(`Reading file ${fileName}`);
const csvStream = csv.parse({ const csvStream = csv.parse({
// @ts-ignore // @ts-ignore
delimiter, delimiter,
quoted,
skip_lines_with_error: true, skip_lines_with_error: true,
to_line: limitRows ? limitRows + 1 : -1, to_line: limitRows ? limitRows + 1 : -1,
}); });

View File

@@ -21,6 +21,20 @@ const csvFormat: FileFormatDefinition = {
], ],
apiName: 'delimiter', apiName: 'delimiter',
}, },
{
type: 'checkbox',
name: 'quoted',
label: 'Quoted',
apiName: 'quoted',
direction: 'target',
},
{
type: 'checkbox',
name: 'header',
label: 'Has header row',
apiName: 'header',
default: true,
},
], ],
}; };

View File

@@ -22,7 +22,7 @@ function extractApiParameters(values, direction, format) {
const pairs = (format.args || []) const pairs = (format.args || [])
.filter((arg) => arg.apiName) .filter((arg) => arg.apiName)
.map((arg) => [arg.apiName, values[`${direction}_${format.storageType}_${arg.name}`]]) .map((arg) => [arg.apiName, values[`${direction}_${format.storageType}_${arg.name}`]])
.filter((x) => x[1]); .filter((x) => x[1] != null);
return _.fromPairs(pairs); return _.fromPairs(pairs);
} }

View File

@@ -20,7 +20,7 @@ function FormArgument({ arg, namePrefix }) {
return <FormTextField label={arg.label} name={name} />; return <FormTextField label={arg.label} name={name} />;
} }
if (arg.type == 'checkbox') { if (arg.type == 'checkbox') {
return <FormCheckboxField label={arg.label} name={name} />; return <FormCheckboxField label={arg.label} name={name} defaultValue={arg.default} />;
} }
if (arg.type == 'select') { if (arg.type == 'select') {
return ( return (

View File

@@ -50,12 +50,14 @@ export function FormTextField({ label, ...other }) {
); );
} }
export function FormCheckboxFieldRaw({ name = undefined, ...other }) { export function FormCheckboxFieldRaw({ name = undefined, defaultValue = undefined, ...other }) {
const { values, setFieldValue } = useFormikContext(); const { values, setFieldValue } = useFormikContext();
const handleChange = (event) => { const handleChange = (event) => {
setFieldValue(name, event.target.checked); setFieldValue(name, event.target.checked);
}; };
return <CheckboxField name={name} checked={!!values[name]} onChange={handleChange} {...other} />; let isChecked = values[name];
if (isChecked == null) isChecked = defaultValue;
return <CheckboxField name={name} checked={!!isChecked} onChange={handleChange} {...other} />;
// return <Field {...other} as={CheckboxField} />; // return <Field {...other} as={CheckboxField} />;
} }