quivr/frontend/app/studio/[brainId]/BrainManagementTabs/BrainManagementTabs.tsx
Antoine Dewez 99156955a3
fix(frontend): fix disabled knwoledge tab (#2280)
# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
2024-03-01 11:43:54 -08:00

72 lines
2.0 KiB
TypeScript

/* eslint-disable max-lines */
import { useState } from "react";
import Spinner from "@/lib/components/ui/Spinner";
import { Tabs } from "@/lib/components/ui/Tabs/Tabs";
import { Tab } from "@/lib/types/Tab";
import { KnowledgeTab } from "./components/KnowledgeTab/KnowledgeTab";
import { PeopleTab } from "./components/PeopleTab/PeopleTab";
import { SettingsTab } from "./components/SettingsTab/SettingsTab";
import { useBrainFetcher } from "./hooks/useBrainFetcher";
import { useBrainManagementTabs } from "./hooks/useBrainManagementTabs";
export const BrainManagementTabs = (): JSX.Element => {
const [selectedTab, setSelectedTab] = useState("Settings");
const { brainId, hasEditRights } = useBrainManagementTabs();
const { brain, isLoading } = useBrainFetcher({
brainId,
});
const brainManagementTabs: Tab[] = [
{
label: "Settings",
isSelected: selectedTab === "Settings",
onClick: () => setSelectedTab("Settings"),
iconName: "settings",
},
{
label: "People",
isSelected: selectedTab === "People",
onClick: () => setSelectedTab("People"),
iconName: "user",
disabled: !hasEditRights,
},
{
label: "Knowledge",
isSelected: selectedTab === "Knowledge",
onClick: () => setSelectedTab("Knowledge"),
iconName: "file",
disabled:
!hasEditRights ||
(!brain?.integration_description?.max_files &&
brain?.brain_type !== "doc"),
},
];
if (!brainId) {
return <div />;
}
if (isLoading) {
return (
<div className="flex w-full h-full justify-center items-center">
<Spinner />
</div>
);
}
return (
<>
<Tabs tabList={brainManagementTabs} />
{selectedTab === "Settings" && <SettingsTab brainId={brainId} />}
{selectedTab === "People" && <PeopleTab brainId={brainId} />}
{selectedTab === "Knowledge" && (
<KnowledgeTab brainId={brainId} hasEditRights={hasEditRights} />
)}
</>
);
};