data import download fixes

This commit is contained in:
Jan Prochazka
2020-11-29 20:12:11 +01:00
parent 0785c375a5
commit 6d7e7f97c7
5 changed files with 33 additions and 14 deletions

View File

@@ -43,8 +43,8 @@ ${
? ` ? `
const downloaded=await dbgateApi.download(${JSON.stringify(props.downloadUrl)}); const downloaded=await dbgateApi.download(${JSON.stringify(props.downloadUrl)});
const reader=await ${extractShellApiFunctionName(functionName)}(Object.assign(${JSON.stringify( const reader=await ${extractShellApiFunctionName(functionName)}(Object.assign(${JSON.stringify(
props _.omit(props, ['downloadUrl'])
)}, { fileName: downloaded, downloadUrl: undefined })); )}, { fileName: downloaded }));
` `
: `const reader=await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});` : `const reader=await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});`
} }

View File

@@ -4,7 +4,7 @@ const { uploadsdir } = require('../utility/directories');
const { downloadFile } = require('../utility/downloader'); const { downloadFile } = require('../utility/downloader');
async function download(url) { async function download(url) {
const tmpFile = path.join(uploadsdir(), uuidv1() + '.tgz'); const tmpFile = path.join(uploadsdir(), uuidv1());
await downloadFile(url, tmpFile); await downloadFile(url, tmpFile);
return tmpFile; return tmpFile;
} }

View File

@@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import _ from 'lodash';
const iconNames = { const iconNames = {
'icon minus-box': 'mdi mdi-minus-box-outline', 'icon minus-box': 'mdi mdi-minus-box-outline',
@@ -26,6 +25,7 @@ const iconNames = {
'icon save': 'mdi mdi-content-save', 'icon save': 'mdi mdi-content-save',
'icon account': 'mdi mdi-account', 'icon account': 'mdi mdi-account',
'icon sql-file': 'mdi mdi-file', 'icon sql-file': 'mdi mdi-file',
'icon web': 'mdi mdi-web',
'icon edit': 'mdi mdi-pencil', 'icon edit': 'mdi mdi-pencil',
'icon delete': 'mdi mdi-delete', 'icon delete': 'mdi mdi-delete',

View File

@@ -61,12 +61,17 @@ const SourceNameWrapper = styled.div`
justify-content: space-between; justify-content: space-between;
`; `;
const TrashWrapper = styled.div` const SourceNameButtons = styled.div`
display: flex;
`;
const IconButtonWrapper = styled.div`
&:hover { &:hover {
background-color: ${(props) => props.theme.modal_background2}; background-color: ${(props) => props.theme.modal_background2};
} }
cursor: pointer; cursor: pointer;
color: ${(props) => props.theme.modal_font_blue[7]}; color: ${(props) => props.theme.modal_font_blue[7]};
margin-left: 5px;
`; `;
const SqlWrapper = styled.div` const SqlWrapper = styled.div`
@@ -371,19 +376,36 @@ function SourceTargetConfig({
function SourceName({ name }) { function SourceName({ name }) {
const { values, setFieldValue } = useFormikContext(); const { values, setFieldValue } = useFormikContext();
const theme = useTheme(); const theme = useTheme();
const showModal = useShowModal();
const obj = values[`sourceFile_${name}`];
const handleDelete = () => { const handleDelete = () => {
setFieldValue( setFieldValue(
'sourceList', 'sourceList',
values.sourceList.filter((x) => x != name) values.sourceList.filter((x) => x != name)
); );
}; };
const doChangeUrl = (url) => {
setFieldValue(`sourceFile_${name}`, { downloadUrl: url });
};
const handleChangeUrl = () => {
showModal((modalState) => (
<ChangeDownloadUrlModal modalState={modalState} url={obj.downloadUrl} onConfirm={doChangeUrl} />
));
};
return ( return (
<SourceNameWrapper> <SourceNameWrapper>
<div>{name}</div> <div>{name}</div>
<TrashWrapper onClick={handleDelete} theme={theme}> <SourceNameButtons>
{obj && !!obj.downloadUrl && (
<IconButtonWrapper onClick={handleChangeUrl} theme={theme}>
<FontIcon icon="icon web" />
</IconButtonWrapper>
)}
<IconButtonWrapper onClick={handleDelete} theme={theme}>
<FontIcon icon="icon delete" /> <FontIcon icon="icon delete" />
</TrashWrapper> </IconButtonWrapper>
</SourceNameButtons>
</SourceNameWrapper> </SourceNameWrapper>
); );
} }

View File

@@ -24,12 +24,9 @@ export default class ScriptWriter {
const fileNameVar = this.allocVariable(); const fileNameVar = this.allocVariable();
this.put(`const ${fileNameVar} = await dbgateApi.download(${JSON.stringify(props.downloadUrl)});`); this.put(`const ${fileNameVar} = await dbgateApi.download(${JSON.stringify(props.downloadUrl)});`);
this.put( this.put(
`const ${variableName} = await ${extractShellApiFunctionName(functionName)}( `const ${variableName} = await ${extractShellApiFunctionName(functionName)}(Object.assign(${JSON.stringify(
Object.assign(${JSON.stringify(props)}, { _.omit(props, ['downloadUrl'])
fileName: ${fileNameVar}, )}, { fileName: ${fileNameVar} }));`
downloadUrl: undefined
})
);`
); );
} else { } else {
this.put(`const ${variableName} = await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});`); this.put(`const ${variableName} = await ${extractShellApiFunctionName(functionName)}(${JSON.stringify(props)});`);