forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Detection Engine] update query automatically in r…
…ule create form through AI assistant (elastic#190963) ## Summary - addresses elastic#187270 ### UX Introduced button in code block <img width="1218" alt="Screenshot 2024-08-21 at 16 35 51" src="https://github.com/user-attachments/assets/69c82d7c-7305-41a6-9a29-5f27755727a6"> ### DEMO https://github.com/user-attachments/assets/32419edc-4bfa-4f4e-892b-2a6abb3c0f27 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [x] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
bcb030e
commit 3c9198a
Showing
15 changed files
with
266 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/security_solution/public/assistant/update_query_in_form/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
import { UpdateQueryInFormButton } from '.'; | ||
|
||
const mockUseAssistantContext = { codeBlockRef: { current: jest.fn() } }; | ||
jest.mock('@kbn/elastic-assistant', () => ({ | ||
useAssistantContext: () => mockUseAssistantContext, | ||
})); | ||
|
||
describe('UpdateQueryInFormButton', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('calls codeBlockRef callback on click', () => { | ||
const testQuery = 'from auditbeat* | limit 10'; | ||
render(<UpdateQueryInFormButton query={testQuery} />); | ||
|
||
userEvent.click(screen.getByTestId('update-query-in-form-button')); | ||
|
||
expect(mockUseAssistantContext.codeBlockRef.current).toHaveBeenCalledWith(testQuery); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/security_solution/public/assistant/update_query_in_form/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { FC, PropsWithChildren } from 'react'; | ||
import React from 'react'; | ||
import { EuiButtonEmpty, EuiToolTip, EuiIcon } from '@elastic/eui'; | ||
import { useAssistantContext } from '@kbn/elastic-assistant'; | ||
|
||
import { UPDATE_QUERY_IN_FORM_TOOLTIP } from './translations'; | ||
|
||
export interface UpdateQueryInFormButtonProps { | ||
query: string; | ||
} | ||
|
||
export const UpdateQueryInFormButton: FC<PropsWithChildren<UpdateQueryInFormButtonProps>> = ({ | ||
query, | ||
}) => { | ||
const { codeBlockRef } = useAssistantContext(); | ||
|
||
const handleClick = () => { | ||
codeBlockRef?.current?.(query); | ||
}; | ||
|
||
return ( | ||
<EuiButtonEmpty | ||
data-test-subj="update-query-in-form-button" | ||
aria-label={UPDATE_QUERY_IN_FORM_TOOLTIP} | ||
onClick={handleClick} | ||
color="text" | ||
flush="both" | ||
size="xs" | ||
> | ||
<EuiToolTip position="right" content={UPDATE_QUERY_IN_FORM_TOOLTIP}> | ||
<EuiIcon type="documentEdit" /> | ||
</EuiToolTip> | ||
</EuiButtonEmpty> | ||
); | ||
}; | ||
|
||
UpdateQueryInFormButton.displayName = 'UpdateQueryInFormButton'; |
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/security_solution/public/assistant/update_query_in_form/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const UPDATE_QUERY_IN_FORM_TOOLTIP = i18n.translate( | ||
'xpack.securitySolution.assistant.updateQueryInFormTooltip', | ||
{ | ||
defaultMessage: 'Update query in form', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.