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