Skip to content

Commit 86a9061

Browse files
committed
More cleanup
1 parent a016342 commit 86a9061

File tree

4 files changed

+35
-21
lines changed

4 files changed

+35
-21
lines changed

src/interfaces/coral_web/src/components/Agents/Layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { Children, PropsWithChildren } from 'react';
33

44
import { AgentsSidePanel } from '@/components/Agents/AgentsSidePanel';
55
import { MobileHeader } from '@/components/Agents/MobileHeader';
6-
import { ConfigurationDrawer } from '@/components/Conversation/ConfigurationDrawer';
6+
import { SettingsDrawer } from '@/components/Settings/SettingsDrawer';
77
import { PageHead } from '@/components/Shared/PageHead';
88
import { cn } from '@/utils/cn';
99

@@ -57,7 +57,7 @@ export const Layout: React.FC<Props> = ({ title = 'Chat', children }) => {
5757
>
5858
{mainElement}
5959
</section>
60-
<ConfigurationDrawer />
60+
<SettingsDrawer />
6161
</div>
6262
</div>
6363
</>

src/interfaces/coral_web/src/components/Settings/FilesTab.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const FilesTab: React.FC<{ className?: string }> = ({ className = '' }) =
2626
} = useFilesStore();
2727
const { isFileInputQueuedToFocus, focusFileInput } = useFocusFileInput();
2828
const { files } = useFilesInConversation();
29-
const { enableDefaultFileLoaderTool } = useDefaultFileLoaderTool();
29+
const { enableDefaultFileLoaderTool, disableDefaultFileLoaderTool } = useDefaultFileLoaderTool();
3030

3131
useEffect(() => {
3232
if (isFileInputQueuedToFocus) {
@@ -77,7 +77,12 @@ export const FilesTab: React.FC<{ className?: string }> = ({ className = '' }) =
7777
newFileIds = [...(fileIds ?? []), fileId];
7878
}
7979

80-
enableDefaultFileLoaderTool();
80+
if (newFileIds.length === 0) {
81+
disableDefaultFileLoaderTool();
82+
} else {
83+
enableDefaultFileLoaderTool();
84+
}
85+
8186
setParams({ fileIds: newFileIds });
8287
};
8388

src/interfaces/coral_web/src/components/Settings/SettingsDrawer.tsx

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Transition } from '@headlessui/react';
2-
import React, { createElement, useMemo, useState } from 'react';
2+
import React, { useMemo, useState } from 'react';
33

44
import { IconButton } from '@/components/IconButton';
55
import { FilesTab } from '@/components/Settings/FilesTab';
@@ -14,12 +14,6 @@ import { cn } from '@/utils';
1414
// TODO(@wujessica): grab these from the agents api
1515
const REQUIRED_TOOLS: string[] = [];
1616

17-
type Tab = {
18-
name: string;
19-
component: React.FC;
20-
props?: Record<string, unknown>;
21-
};
22-
2317
/**
2418
* @description Renders the settings drawer of the main content.
2519
* It opens up on top of the citation panel/the main content.
@@ -38,18 +32,18 @@ export const SettingsDrawer: React.FC = () => {
3832
} = useCitationsStore();
3933
const { files } = useFilesInConversation();
4034

41-
const tabs = useMemo<Tab[]>(() => {
35+
const tabs = useMemo(() => {
4236
return files.length > 0 && conversationId
4337
? [
44-
{ name: 'Tools', component: ToolsTab, props: { requiredTools: REQUIRED_TOOLS } },
45-
{ name: 'Files', component: FilesTab },
46-
{ name: 'Settings', component: SettingsTab },
38+
{ name: 'Tools', component: <ToolsTab requiredTools={REQUIRED_TOOLS} /> },
39+
{ name: 'Files', component: <FilesTab /> },
40+
{ name: 'Settings', component: <SettingsTab /> },
4741
]
4842
: [
49-
{ name: 'Tools', component: ToolsTab, props: { requiredTools: REQUIRED_TOOLS } },
50-
{ name: 'Settings', component: SettingsTab },
43+
{ name: 'Tools', component: <ToolsTab requiredTools={REQUIRED_TOOLS} /> },
44+
{ name: 'Settings', component: <SettingsTab /> },
5145
];
52-
}, [files.length]);
46+
}, [files.length, conversationId]);
5347

5448
return (
5549
<Transition
@@ -94,7 +88,7 @@ export const SettingsDrawer: React.FC = () => {
9488
panelsClassName="pt-7 lg:pt-7 px-0 flex flex-col rounded-b-lg bg-marble-100 md:rounded-b-none"
9589
fitTabsContent={true}
9690
>
97-
{tabs.map((t) => createElement(t.component, { key: t.name, ...t.props }))}
91+
{tabs.map((t) => t.component)}
9892
</Tabs>
9993
</section>
10094
</Transition>

src/interfaces/coral_web/src/hooks/files.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,31 @@ export const useDefaultFileLoaderTool = () => {
190190

191191
const enableDefaultFileLoaderTool = () => {
192192
if (!defaultFileLoaderTool) return;
193-
const visibleFileToolNames = tools?.filter(isDefaultFileLoaderTool).map((t) => t.name) ?? [];
194193

194+
const visibleFileToolNames = tools?.filter(isDefaultFileLoaderTool).map((t) => t.name) ?? [];
195195
const isDefaultFileLoaderToolEnabled = visibleFileToolNames.some((name) =>
196196
params.tools?.some((tool) => tool.name === name)
197197
);
198+
198199
if (isDefaultFileLoaderToolEnabled) return;
199200

200201
const newTools = uniqBy([...(params.tools ?? []), defaultFileLoaderTool], 'name');
201202
setParams({ tools: newTools });
202203
};
203204

204-
return { defaultFileLoaderTool, enableDefaultFileLoaderTool };
205+
const disableDefaultFileLoaderTool = () => {
206+
if (!defaultFileLoaderTool) return;
207+
208+
const visibleFileToolNames = tools?.filter(isDefaultFileLoaderTool).map((t) => t.name) ?? [];
209+
const isDefaultFileLoaderToolEnabled = visibleFileToolNames.some((name) =>
210+
params.tools?.some((tool) => tool.name === name)
211+
);
212+
213+
if (!isDefaultFileLoaderToolEnabled) return;
214+
215+
const newTools = (params.tools ?? []).filter((t) => t.name !== defaultFileLoaderTool.name);
216+
setParams({ tools: newTools });
217+
};
218+
219+
return { defaultFileLoaderTool, enableDefaultFileLoaderTool, disableDefaultFileLoaderTool };
205220
};

0 commit comments

Comments
 (0)