Skip to content

Commit

Permalink
[Obs ai assistant] - bug bulk import for knowledge base (elastic#205075)
Browse files Browse the repository at this point in the history
Closes elastic#196096 

## Summary

Wrong successful message with error notification pop up on adding a
wrong format file under bulk import for knowledge base
[elastic#196096](elastic#196096)

---------

Co-authored-by: Søren Louv-Jansen <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored and CAWilson94 committed Jan 10, 2025
1 parent 3674170 commit 57b1b31
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -74,8 +79,7 @@ export function KnowledgeBaseBulkImportFlyout({ onClose }: { onClose: () => void
}
);
}

mutateAsync({ entries }).then(onClose);
onClose();
};

return (
Expand Down

0 comments on commit 57b1b31

Please sign in to comment.