[Obs ai assistant] - bug bulk import for knowledge base (#205075)

Closes #196096 

## Summary

Wrong successful message with error notification pop up on adding a
wrong format file under bulk import for knowledge base
[#196096](https://github.com/elastic/kibana/issues/196096)

---------

Co-authored-by: Søren Louv-Jansen <sorenlouv@gmail.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Arturo Lidueña 2025-01-07 10:44:16 +01:00 committed by GitHub
parent b02c735099
commit 2c97ed3bfe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -47,13 +47,18 @@ export function KnowledgeBaseBulkImportFlyout({ onClose }: { onClose: () => void
};
const handleSubmitNewEntryClick = async () => {
let entries: Array<Omit<KnowledgeBaseEntry, '@timestamp' | 'title'> & { title: string }> = [];
const text = await files[0].text();
const elements = text.split('\n').filter(Boolean);
try {
entries = elements.map((el) => JSON.parse(el));
const entries = elements.map(
(el) =>
JSON.parse(el) as Omit<KnowledgeBaseEntry, '@timestamp' | 'title'> & {
title: string;
}
);
await mutateAsync({ entries });
} catch (_) {
toasts.addError(
new Error(
@ -74,8 +79,7 @@ export function KnowledgeBaseBulkImportFlyout({ onClose }: { onClose: () => void
}
);
}
mutateAsync({ entries }).then(onClose);
onClose();
};
return (