Skip to content

Commit

Permalink
fix(content-sidebar): Fixed circular dependency for box ai sidebar (#…
Browse files Browse the repository at this point in the history
…3884)

Apply suggestions from code review

Co-authored-by: Trevor <[email protected]>
  • Loading branch information
greg-in-a-box and tjuanitas authored Feb 4, 2025
1 parent d2e2692 commit d92b546
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
27 changes: 2 additions & 25 deletions src/elements/content-sidebar/BoxAISidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,15 @@
* @author Box
*/
import * as React from 'react';
import noop from 'lodash/noop';
import { useIntl } from 'react-intl';
import { type QuestionType } from '@box/box-ai-content-answers';
import { RecordActionType } from '@box/box-ai-agent-selector';
import BoxAISidebarContent from './BoxAISidebarContent';
import { BoxAISidebarContext } from './context/BoxAISidebarContext';
import { DOCUMENT_SUGGESTED_QUESTIONS, SPREADSHEET_FILE_EXTENSIONS } from '../common/content-answers/constants';

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

export interface BoxAISidebarContextValues {
cache: { encodedSession?: string | null; questions?: QuestionType[] };
contentName: string;
elementId: string;
fileExtension: string;
isStopResponseEnabled: boolean;
itemSize?: string;
recordAction: (params: RecordActionType) => void;
setCacheValue: (key: 'encodedSession' | 'questions', value: string | null | QuestionType[]) => void;
userInfo: { name: string; avatarURL: string };
}

export const BoxAISidebarContext = React.createContext<BoxAISidebarContextValues>({
cache: null,
contentName: '',
elementId: '',
fileExtension: '',
isStopResponseEnabled: false,
recordAction: noop,
setCacheValue: noop,
userInfo: { name: '', avatarURL: '' },
});

export interface BoxAISidebarProps {
contentName: string;
cache: { encodedSession?: string | null; questions?: QuestionType[] };
Expand Down Expand Up @@ -107,7 +84,7 @@ const BoxAISidebar = (props: BoxAISidebarProps) => {
}, []);

React.useEffect(() => {
document.addEventListener('keydown', handleKeyPress,{ capture: true });
document.addEventListener('keydown', handleKeyPress, { capture: true });
return () => {
document.removeEventListener('keydown', handleKeyPress, { capture: true });
};
Expand Down
2 changes: 1 addition & 1 deletion src/elements/content-sidebar/BoxAISidebarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { withLogger } from '../common/logger';
import { ORIGIN_BOXAI_SIDEBAR, SIDEBAR_VIEW_BOXAI } from '../../constants';
import { EVENT_JS_READY } from '../common/logger/constants';
import { mark } from '../../utils/performance';
import { BoxAISidebarContext } from './BoxAISidebar';
import { BoxAISidebarContext } from './context/BoxAISidebarContext';

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

Expand Down
27 changes: 27 additions & 0 deletions src/elements/content-sidebar/context/BoxAISidebarContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import noop from 'lodash/noop';
import { RecordActionType } from '@box/box-ai-agent-selector';
import type { QuestionType } from '@box/box-ai-content-answers';

export interface BoxAISidebarContextValues {
cache: { encodedSession?: string | null; questions?: QuestionType[] };
contentName: string;
elementId: string;
fileExtension: string;
isStopResponseEnabled: boolean;
itemSize?: string;
recordAction: (params: RecordActionType) => void;
setCacheValue: (key: 'encodedSession' | 'questions', value: string | null | QuestionType[]) => void;
userInfo: { name: string; avatarURL: string };
}

export const BoxAISidebarContext = React.createContext<BoxAISidebarContextValues>({
cache: null,
contentName: '',
elementId: '',
fileExtension: '',
isStopResponseEnabled: false,
recordAction: noop,
setCacheValue: noop,
userInfo: { name: '', avatarURL: '' },
});

0 comments on commit d92b546

Please sign in to comment.