Skip to content

Commit d92b546

Browse files
fix(content-sidebar): Fixed circular dependency for box ai sidebar (#3884)
Apply suggestions from code review Co-authored-by: Trevor <7311041+tjuanitas@users.noreply.github.com>
1 parent d2e2692 commit d92b546

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

src/elements/content-sidebar/BoxAISidebar.tsx

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,15 @@
33
* @author Box
44
*/
55
import * as React from 'react';
6-
import noop from 'lodash/noop';
76
import { useIntl } from 'react-intl';
87
import { type QuestionType } from '@box/box-ai-content-answers';
98
import { RecordActionType } from '@box/box-ai-agent-selector';
109
import BoxAISidebarContent from './BoxAISidebarContent';
10+
import { BoxAISidebarContext } from './context/BoxAISidebarContext';
1111
import { DOCUMENT_SUGGESTED_QUESTIONS, SPREADSHEET_FILE_EXTENSIONS } from '../common/content-answers/constants';
1212

1313
import messages from '../common/content-answers/messages';
1414

15-
export interface BoxAISidebarContextValues {
16-
cache: { encodedSession?: string | null; questions?: QuestionType[] };
17-
contentName: string;
18-
elementId: string;
19-
fileExtension: string;
20-
isStopResponseEnabled: boolean;
21-
itemSize?: string;
22-
recordAction: (params: RecordActionType) => void;
23-
setCacheValue: (key: 'encodedSession' | 'questions', value: string | null | QuestionType[]) => void;
24-
userInfo: { name: string; avatarURL: string };
25-
}
26-
27-
export const BoxAISidebarContext = React.createContext<BoxAISidebarContextValues>({
28-
cache: null,
29-
contentName: '',
30-
elementId: '',
31-
fileExtension: '',
32-
isStopResponseEnabled: false,
33-
recordAction: noop,
34-
setCacheValue: noop,
35-
userInfo: { name: '', avatarURL: '' },
36-
});
37-
3815
export interface BoxAISidebarProps {
3916
contentName: string;
4017
cache: { encodedSession?: string | null; questions?: QuestionType[] };
@@ -107,7 +84,7 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
10784
}, []);
10885

10986
React.useEffect(() => {
110-
document.addEventListener('keydown', handleKeyPress,{ capture: true });
87+
document.addEventListener('keydown', handleKeyPress, { capture: true });
11188
return () => {
11289
document.removeEventListener('keydown', handleKeyPress, { capture: true });
11390
};

src/elements/content-sidebar/BoxAISidebarContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { withLogger } from '../common/logger';
2424
import { ORIGIN_BOXAI_SIDEBAR, SIDEBAR_VIEW_BOXAI } from '../../constants';
2525
import { EVENT_JS_READY } from '../common/logger/constants';
2626
import { mark } from '../../utils/performance';
27-
import { BoxAISidebarContext } from './BoxAISidebar';
27+
import { BoxAISidebarContext } from './context/BoxAISidebarContext';
2828

2929
import messages from '../common/messages';
3030

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
import noop from 'lodash/noop';
3+
import { RecordActionType } from '@box/box-ai-agent-selector';
4+
import type { QuestionType } from '@box/box-ai-content-answers';
5+
6+
export interface BoxAISidebarContextValues {
7+
cache: { encodedSession?: string | null; questions?: QuestionType[] };
8+
contentName: string;
9+
elementId: string;
10+
fileExtension: string;
11+
isStopResponseEnabled: boolean;
12+
itemSize?: string;
13+
recordAction: (params: RecordActionType) => void;
14+
setCacheValue: (key: 'encodedSession' | 'questions', value: string | null | QuestionType[]) => void;
15+
userInfo: { name: string; avatarURL: string };
16+
}
17+
18+
export const BoxAISidebarContext = React.createContext<BoxAISidebarContextValues>({
19+
cache: null,
20+
contentName: '',
21+
elementId: '',
22+
fileExtension: '',
23+
isStopResponseEnabled: false,
24+
recordAction: noop,
25+
setCacheValue: noop,
26+
userInfo: { name: '', avatarURL: '' },
27+
});

0 commit comments

Comments
 (0)