Skip to content

Commit e17777b

Browse files
authored
Frontend: Add citations toggle (#930)
feat(assistants_web): added citations toggle
1 parent 75594fb commit e17777b

File tree

7 files changed

+74
-23
lines changed

7 files changed

+74
-23
lines changed

src/interfaces/assistants_web/src/app/(main)/settings/Settings.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import { PropsWithChildren, useState } from 'react';
44

55
import { StatusConnection } from '@/components/AgentSettingsForm/StatusConnection';
66
import { MobileHeader } from '@/components/Global';
7-
import { Button, DarkModeToggle, Icon, ShowStepsToggle, Tabs, Text } from '@/components/UI';
7+
import {
8+
Button,
9+
DarkModeToggle,
10+
Icon,
11+
ShowCitationsToggle,
12+
ShowStepsToggle,
13+
Tabs,
14+
Text,
15+
} from '@/components/UI';
816
import { TOOL_GMAIL_ID, TOOL_SLACK_ID } from '@/constants';
917
import { useDeleteAuthTool, useListTools, useNotify } from '@/hooks';
1018
import { cn, getToolAuthUrl } from '@/utils';
@@ -102,6 +110,7 @@ const Advanced = () => {
102110
Advanced
103111
</Text>
104112
<ShowStepsToggle />
113+
<ShowCitationsToggle />
105114
</Wrapper>
106115
);
107116
};

src/interfaces/assistants_web/src/components/MessageRow/CitationTextHighlighter.tsx

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { PropsWithChildren } from 'react';
66
import { Citation } from '@/components/MessageRow';
77
import { useContextStore } from '@/context';
88
import { Breakpoint, useBrandedColors, useBreakpoint, useChatRoutes } from '@/hooks';
9-
import { useCitationsStore } from '@/stores';
9+
import { useCitationsStore, useSettingsStore } from '@/stores';
1010
import { cn, createStartEndKey } from '@/utils';
1111

1212
const FALLBACK_CODE_SNIPPET_TEXT = '[source]';
@@ -40,6 +40,7 @@ export const CitationTextHighlighter: React.FC<Props> = ({
4040
const {
4141
citations: { citationReferences },
4242
} = useCitationsStore();
43+
const { showCitations } = useSettingsStore();
4344
const startEndKey = createStartEndKey(start, end);
4445

4546
const { text, lightText, bg, contrastText, hover, dark, light } = useBrandedColors(agentId);
@@ -88,25 +89,31 @@ export const CitationTextHighlighter: React.FC<Props> = ({
8889
}
8990

9091
return (
91-
<Popover className="group contents" as="span">
92-
<PopoverButton
93-
as="span"
94-
className={cn(
95-
'cursor-pointer rounded bg-transparent',
96-
light(text),
97-
dark(lightText),
98-
hover(bg),
99-
hover(contrastText)
100-
)}
101-
>
102-
{content}
103-
</PopoverButton>
104-
<PopoverPanel
105-
anchor="bottom"
106-
className="z-tooltip h-fit w-[466px] rounded border bg-white p-4 dark:border-volcanic-400 dark:bg-volcanic-200"
107-
>
108-
<Citation generationId={generationId} citationKey={startEndKey} agentId={agentId} />
109-
</PopoverPanel>
110-
</Popover>
92+
<>
93+
{showCitations ? (
94+
<Popover className="group contents" as="span">
95+
<PopoverButton
96+
as="span"
97+
className={cn(
98+
'cursor-pointer rounded bg-transparent',
99+
light(text),
100+
dark(lightText),
101+
hover(bg),
102+
hover(contrastText)
103+
)}
104+
>
105+
{content}
106+
</PopoverButton>
107+
<PopoverPanel
108+
anchor="bottom"
109+
className="z-tooltip h-fit w-[466px] rounded border bg-white p-4 dark:border-volcanic-400 dark:bg-volcanic-200"
110+
>
111+
<Citation generationId={generationId} citationKey={startEndKey} agentId={agentId} />
112+
</PopoverPanel>
113+
</Popover>
114+
) : (
115+
<span>{content}</span>
116+
)}
117+
</>
111118
);
112119
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Switch, Text } from '@/components/UI';
2+
import { useSettingsStore } from '@/stores';
3+
4+
export const ShowCitationsToggle = () => {
5+
const { showCitations, setShowCitations } = useSettingsStore();
6+
7+
const handleSwitchShowCitations = (checked: boolean) => {
8+
setShowCitations(checked);
9+
};
10+
11+
return (
12+
<section className="mb-4 flex gap-6">
13+
<Text styleAs="label" className="font-medium">
14+
Show citations
15+
</Text>
16+
<Switch
17+
checked={showCitations}
18+
onChange={(checked: boolean) => handleSwitchShowCitations(checked)}
19+
showCheckedState
20+
/>
21+
</section>
22+
);
23+
};

src/interfaces/assistants_web/src/components/UI/ShowStepsToggle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const ShowStepsToggle = () => {
99
};
1010

1111
return (
12-
<section className="flex gap-6">
12+
<section className="mb-4 flex gap-6">
1313
<Text styleAs="label" className="font-medium">
1414
Show thinking steps
1515
</Text>

src/interfaces/assistants_web/src/components/UI/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export * from './LongPressMenu';
2222
export * from './Modal';
2323
export * from './RadioGroup';
2424
export * from './Shortcut';
25+
export * from './ShowCitationsToggle';
2526
export * from './ShowStepsToggle';
2627
export * from './Skeleton';
2728
export * from './Slider';

src/interfaces/assistants_web/src/stores/persistedStore.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ export const useSettingsStore = () => {
5151
isLeftPanelOpen: state.isLeftPanelOpen,
5252
isRightPanelOpen: state.isRightPanelOpen,
5353
showSteps: state.showSteps,
54+
showCitations: state.showCitations,
5455
setLeftPanelOpen: state.setLeftPanelOpen,
5556
setRightPanelOpen: state.setRightPanelOpen,
5657
setUseAssistantKnowledge: state.setUseAssistantKnowledge,
5758
setShowSteps: state.setShowSteps,
59+
setShowCitations: state.setShowCitations,
5860
isHotKeysDialogOpen: state.isHotKeysDialogOpen,
5961
setIsHotKeysDialogOpen: state.setIsHotKeysDialogOpen,
6062
}),

src/interfaces/assistants_web/src/stores/slices/settingsSlice.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const INITIAL_STATE = {
55
isLeftPanelOpen: true,
66
isRightPanelOpen: false,
77
showSteps: true,
8+
showCitations: true,
89
isHotKeysDialogOpen: false,
910
};
1011

@@ -13,6 +14,7 @@ type State = {
1314
isLeftPanelOpen: boolean;
1415
isRightPanelOpen: boolean;
1516
showSteps: boolean;
17+
showCitations: boolean;
1618
isHotKeysDialogOpen: boolean;
1719
};
1820

@@ -21,6 +23,7 @@ type Actions = {
2123
setLeftPanelOpen: (isOpen: boolean) => void;
2224
setRightPanelOpen: (isOpen: boolean) => void;
2325
setShowSteps: (showSteps: boolean) => void;
26+
setShowCitations: (showCitations: boolean) => void;
2427
setIsHotKeysDialogOpen: (isOpen: boolean) => void;
2528
};
2629

@@ -53,6 +56,12 @@ export const createSettingsSlice: StateCreator<SettingsStore, [], [], SettingsSt
5356
showSteps: showSteps,
5457
}));
5558
},
59+
setShowCitations(showCitations: boolean) {
60+
set((state) => ({
61+
...state,
62+
showCitations: showCitations,
63+
}));
64+
},
5665
setIsHotKeysDialogOpen(isOpen: boolean) {
5766
set((state) => ({
5867
...state,

0 commit comments

Comments
 (0)