Skip to content

Commit 16e895f

Browse files
authored
attempt to fix issue of file upload sometimes doing nothing (#732)
* attempt to fix issue of file upload sometimes doing nothing * apply formatting changes --------- Co-authored-by: Logende <[email protected]>
1 parent 7971770 commit 16e895f

4 files changed

Lines changed: 35 additions & 8 deletions

File tree

meta_configurator/src/components/dialogs/csvimport/importCsvUtils.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,24 @@ import {identifyArraysInJson} from '@/utility/arrayPathUtils';
1919
import {stringToIdentifier} from '@/utility/stringToIdentifier';
2020

2121
export function requestUploadFileToRef(resultString: Ref<string>, resultTableName: Ref<string>) {
22-
const {open, onChange} = useFileDialog();
22+
const {open, onChange, reset} = useFileDialog({
23+
// accept only json, schema.json, yaml, yml, xml and xsd files
24+
accept: '.csv',
25+
multiple: false,
26+
});
2327

2428
onChange((files: FileList | null) => {
2529
if (files && files.length > 0) {
2630
resultTableName.value = stringToIdentifier(files[0].name, true); // Get the name of the first file
2731
readFileContentToStringRef(files, resultString);
2832
}
33+
reset(); // Reset the file dialog after selection
2934
});
30-
open();
35+
36+
// opening it with a small delay might fix the issue of the dialog opening but onChange never triggering
37+
setTimeout(() => {
38+
open();
39+
}, 3);
3140
}
3241

3342
export function inferSchemaForNewDataAndMergeIntoCurrentSchema(

meta_configurator/src/components/toolbar/importFile.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@ import {findAvailableSchemaId} from '@/schema/schemaReadingUtils';
99
* Opens a file dialog to select a JSON schema to import.
1010
*/
1111
export function openImportSchemaDialog(): void {
12-
const {open, onChange} = useFileDialog();
12+
const {open, onChange, reset} = useFileDialog({
13+
// accept only json, schema.json, yaml, yml, xml and xsd files
14+
accept: '.json, .yaml, .yml, .xml, .schema.json',
15+
multiple: false,
16+
});
1317

1418
onChange((files: FileList | null) => {
1519
readFileContentForFunction(files, importSchema);
20+
reset(); // Reset the file dialog after selection
1621
});
1722

18-
open();
23+
// opening it with a small delay might fix the issue of the dialog opening but onChange never triggering
24+
setTimeout(() => {
25+
open();
26+
}, 5);
1927
}
2028

2129
function importSchema(importedSchema: any) {

meta_configurator/src/components/toolbar/uploadFile.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ import {SessionMode} from '@/store/sessionMode';
1010
* @param resultDataLink The DataLink to which the file content should be written
1111
*/
1212
export function openUploadFileDialog(resultDataLink: ManagedData): void {
13-
const {open, onChange} = useFileDialog();
13+
const {open, onChange, reset} = useFileDialog({
14+
// accept only json, schema.json, yaml, yml, xml and xsd files
15+
accept: '.json, .yaml, .yml, .xml, .schema.json',
16+
multiple: false,
17+
});
1418

1519
onChange((files: FileList | null) => {
1620
readFileContentToDataLink(files, resultDataLink);
21+
reset(); // Reset the file dialog after selection
1722
});
1823

19-
open();
24+
// opening it with a small delay might fix the issue of the dialog opening but onChange never triggering
25+
setTimeout(() => {
26+
open();
27+
}, 3);
2028
}
2129

2230
/**

meta_configurator/src/utility/readFileContent.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function readFileContentFromFileList(
4141
// parse the file content depending on the file suffix
4242
const fileName = file.name;
4343
for (const formatName of formatRegistry.getFormatNames()) {
44-
if (fileName.endsWith(formatName)) {
44+
if (fileName.toLowerCase().endsWith(formatName.toLowerCase())) {
4545
return formatRegistry.getFormat(formatName).dataConverter.parse(await fileContentAsString);
4646
}
4747
}
@@ -98,5 +98,7 @@ export function readFileContentForFunction(
9898
fct(contents as any);
9999
}
100100
})
101-
.catch(error => errorService.onError(error));
101+
.catch(error => {
102+
errorService.onError(error);
103+
});
102104
}

0 commit comments

Comments
 (0)