Skip to content

Commit

Permalink
[8.x] [Obs ai assistant] - bug bulk import for knowledge base (#205075)…
Browse files Browse the repository at this point in the history
… (#205688)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Obs ai assistant] - bug bulk import for knowledge base
(#205075)](#205075)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Arturo
Lidueña","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-07T09:44:16Z","message":"[Obs
ai assistant] - bug bulk import for knowledge base (#205075)\n\nCloses
#196096 \r\n\r\n## Summary\r\n\r\nWrong successful message with error
notification pop up on adding a\r\nwrong format file under bulk import
for knowledge
base\r\n[#196096](https://github.com/elastic/kibana/issues/196096)\r\n\r\n---------\r\n\r\nCo-authored-by:
Søren Louv-Jansen <[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"2c97ed3bfec8a99de931d85f50b1e940835bde47","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:Obs
AI
Assistant","v8.16.0","backport:version","v8.17.0","v8.18.0"],"title":"[Obs
ai assistant] - bug bulk import for knowledge
base","number":205075,"url":"https://github.com/elastic/kibana/pull/205075","mergeCommit":{"message":"[Obs
ai assistant] - bug bulk import for knowledge base (#205075)\n\nCloses
#196096 \r\n\r\n## Summary\r\n\r\nWrong successful message with error
notification pop up on adding a\r\nwrong format file under bulk import
for knowledge
base\r\n[#196096](https://github.com/elastic/kibana/issues/196096)\r\n\r\n---------\r\n\r\nCo-authored-by:
Søren Louv-Jansen <[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"2c97ed3bfec8a99de931d85f50b1e940835bde47"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.17","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/205075","number":205075,"mergeCommit":{"message":"[Obs
ai assistant] - bug bulk import for knowledge base (#205075)\n\nCloses
#196096 \r\n\r\n## Summary\r\n\r\nWrong successful message with error
notification pop up on adding a\r\nwrong format file under bulk import
for knowledge
base\r\n[#196096](https://github.com/elastic/kibana/issues/196096)\r\n\r\n---------\r\n\r\nCo-authored-by:
Søren Louv-Jansen <[email protected]>\r\nCo-authored-by: kibanamachine
<[email protected]>","sha":"2c97ed3bfec8a99de931d85f50b1e940835bde47"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Arturo Lidueña <[email protected]>
  • Loading branch information
kibanamachine and arturoliduena authored Jan 7, 2025
1 parent 3cc22d8 commit def21fa
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 def21fa

Please sign in to comment.