Skip to content

Commit 7f8802a

Browse files
feat(boxai-sidebar): Add logic to render remote sidebar from prop (#4106)
* feat: add and use remote sidebar component in sidebar props * feat(boxai-sidebar): add unit test * feat(boxai-sidebar): address some comments * feat(boxai-sidebar): fix failed test * fix(boxai-sidebar): pass itemsize in prop as optional * feat(boxai-sidebar): refactor code based on comments * feat(boxai-sidebar): fix unit tests and remove css import * feat(boxai-sidebar): replace remoteModule prop with renderRemoteModule for improved flexibility * fix(boxai-sidebar): simplify return statement for renderRemoteModule --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 02cb22e commit 7f8802a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/elements/content-sidebar/BoxAISidebar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import BoxAISidebarContent from './BoxAISidebarContent';
1010
import { BoxAISidebarContext } from './context/BoxAISidebarContext';
1111
import { SPREADSHEET_FILE_EXTENSIONS } from '../common/content-answers/constants';
1212
import type { BoxAISidebarCache, BoxAISidebarCacheSetter } from './types/BoxAISidebarTypes';
13-
1413
import messages from '../common/content-answers/messages';
1514

1615
export interface BoxAISidebarProps {
@@ -57,6 +56,7 @@ export interface BoxAISidebarProps {
5756
recordAction: (params: RecordActionType) => void;
5857
setCacheValue: BoxAISidebarCacheSetter;
5958
shouldFeedbackFormIncludeFeedbackText?: boolean;
59+
renderRemoteModule?: (elementId: string) => React.ReactNode;
6060
shouldPreinitSession?: boolean;
6161
setHasQuestions: (hasQuestions: boolean) => void;
6262
}
@@ -79,6 +79,7 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
7979
onFeedbackFormSubmit,
8080
onUserInteraction,
8181
recordAction,
82+
renderRemoteModule,
8283
setCacheValue,
8384
shouldFeedbackFormIncludeFeedbackText,
8485
shouldPreinitSession = true,
@@ -130,6 +131,10 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
130131
}
131132
}, [questions.length, setHasQuestions]);
132133

134+
if (renderRemoteModule) {
135+
return renderRemoteModule(elementId);
136+
}
137+
133138
let questionsWithoutInProgress = questions;
134139
if (questions.length > 0 && !questions[questions.length - 1].isCompleted) {
135140
// pass only fully completed questions to not show loading indicator of question where we canceled API request

src/elements/content-sidebar/__tests__/BoxAISidebar.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,26 @@ describe('elements/content-sidebar/BoxAISidebar', () => {
347347
expect(screen.queryByTestId('content-answers-modal')).not.toBeInTheDocument();
348348
});
349349

350+
describe('remote sidebar component', () => {
351+
const MockRemoteSidebar = jest.fn(() => <div data-testid="remote-sidebar" />);
352+
const renderRemoteModule = jest.fn(() => <MockRemoteSidebar elementId={mockProps.elementId} />);
353+
354+
test('should render remote sidebar component when provided', async () => {
355+
await renderComponent({ renderRemoteModule });
356+
357+
expect(renderRemoteModule).toHaveBeenCalledWith(mockProps.elementId);
358+
expect(screen.getByTestId('remote-sidebar')).toBeInTheDocument();
359+
});
360+
361+
test('should not render default sidebar when remote component is provided', async () => {
362+
await renderComponent({ renderRemoteModule });
363+
364+
expect(screen.queryByTestId('boxai-sidebar-title')).not.toBeInTheDocument();
365+
expect(screen.queryByTestId('sidebar-agent-selector')).not.toBeInTheDocument();
366+
expect(screen.queryByRole('button', { name: 'Clear conversation' })).not.toBeInTheDocument();
367+
});
368+
});
369+
350370
describe('given shouldPreinitSession = false, should create session on user intent', () => {
351371
test('agents list open', async () => {
352372
MockBoxAiAgentSelectorWithApi.mockImplementation(({ onAgentsListOpen }) => {

0 commit comments

Comments
 (0)