-
Notifications
You must be signed in to change notification settings - Fork 317
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
feat(content-sidebar): added onUserInteraction prop to BoxAISidebar #4027
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ import { | |
ClearConversationButton, | ||
IntelligenceModal, | ||
withApiWrapper, | ||
// @ts-expect-error - TS2305 - Module '"@box/box-ai-content-answers"' has no exported member 'ApiWrapperWithInjectedProps'. | ||
type ApiWrapperWithInjectedProps, | ||
} from '@box/box-ai-content-answers'; | ||
import SidebarContent from './SidebarContent'; | ||
|
@@ -35,7 +34,7 @@ const MARK_NAME_JS_READY: string = `${ORIGIN_BOXAI_SIDEBAR}_${EVENT_JS_READY}`; | |
|
||
mark(MARK_NAME_JS_READY); | ||
|
||
function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) { | ||
function BoxAISidebarContent(props: ApiWrapperWithInjectedProps & { shouldShowLandingPage: boolean }) { | ||
const { | ||
createSession, | ||
encodedSession, | ||
|
@@ -65,6 +64,7 @@ function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) { | |
isStopResponseEnabled, | ||
items, | ||
itemSize, | ||
onUserInteraction, | ||
recordAction, | ||
setCacheValue, | ||
shouldPreinitSession, | ||
|
@@ -88,11 +88,14 @@ function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) { | |
setCacheValue('agents', { agents, requestState, selectedAgent }); | ||
} | ||
|
||
const handleUserIntentToUseAI = () => { | ||
const handleUserIntentToUseAI = (userHasInteracted: boolean = false) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That might be true, however I've named it the same way in content-answers, so for consistency I'd leave it like that. |
||
// Create session if not already created or loading | ||
if (!shouldPreinitSession && !encodedSession && !isLoading && createSession) { | ||
createSession(true, false); | ||
} | ||
if (userHasInteracted && onUserInteraction) { | ||
onUserInteraction(); | ||
} | ||
}; | ||
|
||
const handleModalClose = () => { | ||
|
@@ -199,6 +202,7 @@ function BoxAISidebarContent(props: ApiWrapperWithInjectedProps) { | |
<div className="bcs-BoxAISidebar-content"> | ||
<BoxAiContentAnswers | ||
className="bcs-BoxAISidebar-contentAnswers" | ||
contentName={contentName} | ||
contentType={formatMessage(messages.sidebarBoxAIContent)} | ||
hostAppName={hostAppName} | ||
isAIStudioAgentSelectorEnabled={isAIStudioAgentSelectorEnabled} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ describe('elements/content-sidebar/BoxAISidebar', () => { | |
isResetChatEnabled: true, | ||
isStopResponseEnabled: true, | ||
isStreamingEnabled: true, | ||
onUserInteraction: jest.fn(), | ||
recordAction: jest.fn(), | ||
sendQuestion: jest.fn(), | ||
setCacheValue: jest.fn(), | ||
|
@@ -423,4 +424,14 @@ describe('elements/content-sidebar/BoxAISidebar', () => { | |
expect(mockSendQuestion).not.toHaveBeenCalled(); | ||
}, | ||
); | ||
|
||
test('should call onUserInteraction when user takes action', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we cover when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test already covers that. |
||
await renderComponent(); | ||
|
||
const input = screen.getByTestId('content-answers-question-input'); | ||
input.focus(); | ||
await userEvent.keyboard('foo'); | ||
|
||
expect(mockProps.onUserInteraction).toHaveBeenCalled(); | ||
}); | ||
}); |
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.
🙌