fix(editor): Allow importing the same workflow multiple times (#7458)

Fixes #7457
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-10-20 13:58:30 +02:00 committed by GitHub
parent ac814a9c61
commit 3c0a166f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -475,13 +475,13 @@ export default defineComponent({
cb(saved); cb(saved);
}, },
async handleFileImport(): Promise<void> { async handleFileImport(): Promise<void> {
const inputRef = this.$refs.importFile as HTMLInputElement | undefined;
if (inputRef?.files && inputRef.files.length !== 0) {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = (event: ProgressEvent) => { reader.onload = () => {
const data = (event.target as FileReader).result;
let workflowData: IWorkflowDataUpdate; let workflowData: IWorkflowDataUpdate;
try { try {
workflowData = JSON.parse(data as string); workflowData = JSON.parse(reader.result as string);
} catch (error) { } catch (error) {
this.showMessage({ this.showMessage({
title: this.$locale.baseText('mainSidebar.showMessage.handleFileImport.title'), title: this.$locale.baseText('mainSidebar.showMessage.handleFileImport.title'),
@ -489,13 +489,13 @@ export default defineComponent({
type: 'error', type: 'error',
}); });
return; return;
} finally {
reader.onload = undefined;
inputRef.value = null;
} }
nodeViewEventBus.emit('importWorkflowData', { data: workflowData }); nodeViewEventBus.emit('importWorkflowData', { data: workflowData });
}; };
const inputRef = this.$refs.importFile as HTMLInputElement | undefined;
if (inputRef?.files && inputRef.files.length !== 0) {
reader.readAsText(inputRef.files[0]); reader.readAsText(inputRef.files[0]);
} }
}, },