Skip to content

Commit

Permalink
[Security Assistant] Fix Knowledge Base index entry form (elastic#208268
Browse files Browse the repository at this point in the history
)

## Summary

Fix showing indices with `semantic_text` fields in Knowledge Base Index
entry form

<img width="1751" alt="Zrzut ekranu 2025-01-27 o 20 43 43"
src="https://github.com/user-attachments/assets/f4cb0364-3228-4909-84be-a5bcca00943a"
/>

<img width="1751" alt="Zrzut ekranu 2025-01-27 o 20 43 43"
src="https://github.com/user-attachments/assets/02d80c11-f40b-4ac7-8906-2f11ab75f20d"
/>

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
patrykkopycinski and kibanamachine authored Jan 28, 2025
1 parent 90d768b commit 590b4c7
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,4 @@
import { z } from '@kbn/zod';

export type GetKnowledgeBaseIndicesResponse = z.infer<typeof GetKnowledgeBaseIndicesResponse>;
export const GetKnowledgeBaseIndicesResponse = z.object({
/**
* List of indices with at least one field of a `sematic_text` type.
*/
indices: z.array(z.string()),
});
export const GetKnowledgeBaseIndicesResponse = z.object({}).catchall(z.array(z.string()));
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ paths:
application/json:
schema:
type: object
properties:
indices:
type: array
description: List of indices with at least one field of a `sematic_text` type.
items:
type: string
required:
- indices
additionalProperties:
type: array
description: List of indices with at least one field of a `sematic_text` type.
items:
type: string
400:
description: Generic Error
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('IndexEntryEditor', () => {
beforeEach(() => {
jest.clearAllMocks();
(useKnowledgeBaseIndices as jest.Mock).mockReturnValue({
data: { indices: ['index-1', 'index-2'] },
data: { 'index-1': ['field-1'], 'index-2': ['field-2'] },
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ export const IndexEntryEditor: React.FC<Props> = React.memo(
const { data: kbIndices } = useKnowledgeBaseIndices({
http,
});
const indexOptions = useMemo(() => {
return kbIndices?.indices.map((index) => ({
'data-test-subj': index,
label: index,
value: index,
}));
}, [kbIndices?.indices]);
const indexOptions = useMemo(
() =>
Object.keys(kbIndices ?? {}).map((index) => ({
'data-test-subj': index,
label: index,
value: index,
})),
[kbIndices]
);

const { value: isMissingIndex } = useAsync(async () => {
if (!entry?.index?.length) return false;
Expand All @@ -123,14 +125,12 @@ export const IndexEntryEditor: React.FC<Props> = React.memo(

const fieldOptions = useMemo(
() =>
indexFields?.value
?.filter((field) => field.esTypes?.includes('semantic_text'))
.map((field) => ({
'data-test-subj': field.name,
label: field.name,
value: field.name,
})) ?? [],
[indexFields?.value]
kbIndices?.[entry?.index ?? '']?.map((field) => ({
'data-test-subj': field,
label: field,
value: field,
})) ?? [],
[entry?.index, kbIndices]
);

const outputFieldOptions = useMemo(
Expand Down
Loading

0 comments on commit 590b4c7

Please sign in to comment.