Skip to content

Commit bb5e4f5

Browse files
committed
possibly fix file upload bug that sometimes the upload does not work
1 parent a52561d commit bb5e4f5

6 files changed

Lines changed: 51 additions & 55 deletions

File tree

meta_configurator/e2e/csvImport.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
setCsvTablePath,
99
submitCsvImport,
1010
uploadCsvFile,
11+
uploadCsvFileAndCheckProgress,
1112
} from './utilsCsvImport';
1213
import {SessionMode} from '../src/store/sessionMode';
1314

@@ -48,3 +49,22 @@ test('Import CSV with custom table path and renamed column', async ({page}) => {
4849
],
4950
});
5051
});
52+
53+
test('CSV file upload progresses reliably for 15 consecutive attempts in the same session without reload', async ({page}) => {
54+
test.setTimeout(60000);
55+
await openApp(page, 'settings_testpanel.json');
56+
57+
for (let attempt = 1; attempt <= 15; attempt++) {
58+
await test.step(`csv upload attempt ${attempt}`, async () => {
59+
await openCsvImportDialog(page);
60+
try {
61+
await uploadCsvFileAndCheckProgress(page, 'data_people.csv', 4000);
62+
} catch (error) {
63+
throw new Error(`CSV upload attempt ${attempt} got stuck before parsing completed`, {
64+
cause: error instanceof Error ? error : undefined,
65+
});
66+
}
67+
await submitCsvImport(page);
68+
});
69+
}
70+
});

meta_configurator/e2e/utilsCsvImport.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ export async function uploadCsvFile(page: Page, filename: string) {
1919
await expect(page.getByTestId('csv-submit-import')).toBeVisible();
2020
}
2121

22+
export async function uploadCsvFileAndCheckProgress(page: Page, filename: string, timeoutMs: number = 5000) {
23+
const [fileChooser] = await Promise.all([
24+
page.waitForEvent('filechooser', {timeout: timeoutMs}),
25+
page.getByTestId('csv-select-file').click({timeout: timeoutMs}),
26+
]);
27+
await fileChooser.setFiles(path.join(fixturesDir, filename));
28+
await expect(
29+
page.getByTestId('csv-submit-import'),
30+
'CSV import dialog did not progress past file selection'
31+
).toBeVisible({timeout: timeoutMs});
32+
}
33+
2234
export async function expandImportOptions(page: Page) {
2335
await page.getByTestId('csv-import-options-toggle').click();
2436
}

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {useFileDialog} from '@vueuse/core';
21
import {readFileContentToStringRef} from '@/utility/readFileContent';
32
import type {Ref} from 'vue';
43
import {getDataForMode, getSchemaForMode} from '@/data/useDataLink';
@@ -18,27 +17,18 @@ import type {JsonSchemaType} from '@/schema/jsonSchemaType';
1817
import {identifyArraysInJson} from '@/utility/arrayPathUtils';
1918
import {stringToIdentifier} from '@/utility/stringToIdentifier';
2019
import {useErrorService} from '@/utility/errorServiceInstance';
20+
import {createLazySingleFileDialog} from '@/utility/fileDialogUtils';
2121

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

29-
onChange((files: FileList | null) => {
24+
export function requestUploadFileToRef(resultString: Ref<string>, resultTableName: Ref<string>) {
25+
csvFileDialog.openForSelection(files => {
3026
const firstFile = files?.[0];
3127
if (firstFile) {
3228
resultTableName.value = stringToIdentifier(firstFile.name, true); // Get the name of the first file
3329
readFileContentToStringRef(files, resultString);
3430
}
35-
reset(); // Reset the file dialog after selection
3631
});
37-
38-
// opening it with a small delay might fix the issue of the dialog opening but onChange never triggering
39-
setTimeout(() => {
40-
open();
41-
}, 3);
4232
}
4333

4434
export function inferSchemaForNewDataAndMergeIntoCurrentSchema(

meta_configurator/src/components/toolbar/dialogs/turtle-import/importTurtleUtils.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
import {useFileDialog} from '@vueuse/core';
21
import {readFileContentToStringRef} from '@/utility/readFileContent';
32
import {RdfMediaType} from '@/components/panels/rdf/rdfEnums';
43
import {useSettings} from '@/settings/useSettings';
54
import type {Ref} from 'vue';
65
import * as $rdf from 'rdflib';
6+
import {createLazySingleFileDialog} from '@/utility/fileDialogUtils';
77

88
const settings = useSettings();
9+
const turtleFileDialog = createLazySingleFileDialog('.ttl');
910

1011
export function requestUploadFileToRef(resultString: Ref<string>): void {
11-
const {open, onChange, reset} = useFileDialog({
12-
accept: '.ttl',
13-
multiple: false,
12+
turtleFileDialog.openForSelection(files => {
13+
readFileContentToStringRef(files, resultString);
1414
});
15-
16-
onChange((files: FileList | null) => {
17-
if (files && files.length > 0) {
18-
readFileContentToStringRef(files, resultString);
19-
}
20-
reset();
21-
});
22-
23-
setTimeout(open, 3);
2415
}
2516

2617
/**

meta_configurator/src/components/toolbar/importFile.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
1-
import {useFileDialog} from '@vueuse/core';
21
import {readFileContentForFunction} from '@/utility/readFileContent';
32
import {getDataForMode} from '@/data/useDataLink';
43
import {SessionMode} from '@/store/sessionMode';
54
import type {ManagedData} from '@/data/managedData';
65
import {findAvailableSchemaId} from '@/schema/schemaReadingUtils';
6+
import {createLazySingleFileDialog} from '@/utility/fileDialogUtils';
7+
8+
const importSchemaFileDialog = createLazySingleFileDialog(
9+
'.json, .yaml, .yml, .xml, .schema.json',
10+
5
11+
);
712

813
/**
914
* Opens a file dialog to select a JSON schema to import.
1015
*/
1116
export function openImportSchemaDialog(): void {
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-
});
17-
18-
onChange((files: FileList | null) => {
17+
importSchemaFileDialog.openForSelection(files => {
1918
readFileContentForFunction(files, importSchema);
20-
reset(); // Reset the file dialog after selection
2119
});
22-
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);
2720
}
2821

2922
function importSchema(importedSchema: any) {

meta_configurator/src/components/toolbar/uploadFile.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1-
import {useFileDialog} from '@vueuse/core';
21
import {readFileContentToDataLink} from '@/utility/readFileContent';
32
import {getDataForMode} from '@/data/useDataLink';
43
import type {ManagedData} from '@/data/managedData';
54
import {SessionMode} from '@/store/sessionMode';
5+
import {createLazySingleFileDialog} from '@/utility/fileDialogUtils';
6+
7+
const uploadDataFileDialog = createLazySingleFileDialog('.json, .yaml, .yml, .xml, .schema.json');
68

79
/**
810
* Opens a file dialog to select a file to upload.
911
*
1012
* @param resultDataLink The DataLink to which the file content should be written
1113
*/
1214
export function openUploadFileDialog(resultDataLink: ManagedData): void {
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-
});
18-
19-
onChange((files: FileList | null) => {
15+
uploadDataFileDialog.openForSelection(files => {
2016
readFileContentToDataLink(files, resultDataLink);
21-
reset(); // Reset the file dialog after selection
2217
});
23-
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);
2818
}
2919

3020
/**

0 commit comments

Comments
 (0)