-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[SecuritySolution] Make last conversation local storage keys space aware #214794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5cc98d1
reimplement spaceId in AI Assistant overlay
angorayc dc1a5dd
reimplement spaceId in AI Assistant overlay
angorayc 6ba9d6d
isolate assistant last conversation keys
angorayc 74b73b8
organise files
angorayc f9de988
fix types
angorayc fd67322
unit tests
angorayc 12427e6
use last conversation hook
angorayc 6c60a59
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 374d624
fix types
angorayc 6cba8b1
Merge branch 'issues-214114' of github.com:angorayc/kibana into issue…
angorayc 38cc690
fix import
angorayc 8a84540
fix types
angorayc e6287ce
cypress
angorayc cf4d361
cypress
angorayc 389a9d1
Merge branch 'main' into issues-214114
angorayc cd74c0b
get last conversation from local storage
angorayc 1df09d5
snooze error when conversation not found
angorayc 98af4bc
Merge branch 'main' into issues-214114
angorayc 10a9349
lint
angorayc a6f7a39
fix open assistant flyout with rule id
angorayc 996e07d
Merge branch 'main' into issues-214114
angorayc 64c7e0c
fix unit tests
angorayc 0a80791
revert unnecessary changes
angorayc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
...rm/packages/shared/kbn-elastic-assistant/impl/assistant/use_space_aware_context/index.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 { useAssistantSpaceId, AssistantSpaceIdProvider } from './use_space_id'; | ||
| import { useAssistantLastConversation, type LastConversation } from './use_last_conversation'; | ||
|
|
||
| export { useAssistantSpaceId, AssistantSpaceIdProvider, useAssistantLastConversation }; | ||
| export type { LastConversation }; |
63 changes: 63 additions & 0 deletions
63
...n-elastic-assistant/impl/assistant/use_space_aware_context/use_last_conversation.test.tsx
This file contains hidden or 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,63 @@ | ||
| /* | ||
| * 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 useLocalStorage from 'react-use/lib/useLocalStorage'; | ||
| import { renderHook } from '@testing-library/react'; | ||
| import { useAssistantLastConversation } from './use_last_conversation'; | ||
| import { | ||
| DEFAULT_ASSISTANT_NAMESPACE, | ||
| LAST_CONVERSATION_ID_LOCAL_STORAGE_KEY, | ||
| LAST_SELECTED_CONVERSATION_LOCAL_STORAGE_KEY, | ||
| } from '../../assistant_context/constants'; | ||
|
|
||
| jest.mock('react-use/lib/useLocalStorage', () => | ||
| jest.fn().mockReturnValue([{ id: '456' }, jest.fn()]) | ||
| ); | ||
| const spaceId = 'test'; | ||
|
|
||
| describe('useAssistantLastConversation', () => { | ||
| beforeEach(() => jest.clearAllMocks()); | ||
|
|
||
| test('getLastConversation defaults to provided id', () => { | ||
| const { result } = renderHook(() => useAssistantLastConversation({ spaceId })); | ||
| const id = result.current.getLastConversation({ id: '123' }); | ||
| expect(id).toEqual({ id: '123' }); | ||
| }); | ||
|
|
||
| test('getLastConversation uses local storage id when no id is provided ', () => { | ||
| const { result } = renderHook(() => useAssistantLastConversation({ spaceId })); | ||
| const id = result.current.getLastConversation(); | ||
| expect(id).toEqual({ id: '456' }); | ||
| }); | ||
|
|
||
| test('getLastConversation defaults to empty id when no local storage id and no id is provided ', () => { | ||
| (useLocalStorage as jest.Mock).mockReturnValue([undefined, jest.fn()]); | ||
| const { result } = renderHook(() => useAssistantLastConversation({ spaceId })); | ||
| const id = result.current.getLastConversation(); | ||
| expect(id).toEqual({ id: '' }); | ||
| }); | ||
|
|
||
| test('getLastConversation defaults to empty id when title is provided and preserves title', () => { | ||
| (useLocalStorage as jest.Mock).mockReturnValue([undefined, jest.fn()]); | ||
| const { result } = renderHook(() => useAssistantLastConversation({ spaceId })); | ||
| const id = result.current.getLastConversation({ title: 'something' }); | ||
| expect(id).toEqual({ id: '', title: 'something' }); | ||
| }); | ||
|
|
||
| describe.each([ | ||
| { | ||
| expected: `${DEFAULT_ASSISTANT_NAMESPACE}.${LAST_CONVERSATION_ID_LOCAL_STORAGE_KEY}.${spaceId}`, | ||
| }, | ||
| { | ||
| expected: `${DEFAULT_ASSISTANT_NAMESPACE}.${LAST_SELECTED_CONVERSATION_LOCAL_STORAGE_KEY}.${spaceId}`, | ||
| }, | ||
| ])('useLocalStorage is called with keys with correct spaceId', ({ expected }) => { | ||
| test(`local storage key: ${expected}`, () => { | ||
| renderHook(() => useAssistantLastConversation({ spaceId })); | ||
| expect(useLocalStorage).toBeCalledWith(expected); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should only silence the error when the id comes from the
lastConversation, so down in theuseEffecton L256There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if you're doing the space aware local storage keys, maybe we don't need to silence the error at all?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right.
I wasn't sure if I wanted to make local storage keys space aware in this PR, as wasn't sure how big the scope were 😅
After having another look, I move the last conversation relevant keys to a separate hook, looks alright so far.
To make the scope smaller, I am only making the last conversation local storage keys space aware.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephmilovic I still snooze the error when conversation not found after make the local storage space aware. As I found if I created some conversations, and restart my ES. The not found error would show up.