feat(frontend): add nb of knowledges per brain (#2502)

# 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):
This commit is contained in:
Antoine Dewez 2024-04-27 10:19:44 +02:00 committed by GitHub
parent b7ff2e77af
commit aa14d6336e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import { Tabs } from "@/lib/components/ui/Tabs/Tabs";
import { Tab } from "@/lib/types/Tab";
import { KnowledgeTab } from "./components/KnowledgeTab/KnowledgeTab";
import { useAddedKnowledge } from "./components/KnowledgeTab/hooks/useAddedKnowledge";
import { PeopleTab } from "./components/PeopleTab/PeopleTab";
import { SettingsTab } from "./components/SettingsTab/SettingsTab";
import { useBrainFetcher } from "./hooks/useBrainFetcher";
@ -15,6 +16,7 @@ import { useBrainManagementTabs } from "./hooks/useBrainManagementTabs";
export const BrainManagementTabs = (): JSX.Element => {
const [selectedTab, setSelectedTab] = useState("Settings");
const { brainId, hasEditRights } = useBrainManagementTabs();
const { allKnowledge } = useAddedKnowledge({ brainId: brainId ?? undefined });
const { brain, isLoading } = useBrainFetcher({
brainId,
@ -43,7 +45,9 @@ export const BrainManagementTabs = (): JSX.Element => {
disabled: !hasEditRights,
},
{
label: "Knowledge",
label: `Knowledge${allKnowledge.length > 1 ? "s" : ""} (${
allKnowledge.length
})`,
isSelected: selectedTab === "Knowledge",
onClick: () => setSelectedTab("Knowledge"),
iconName: "file",
@ -73,7 +77,11 @@ export const BrainManagementTabs = (): JSX.Element => {
{selectedTab === "Settings" && <SettingsTab brainId={brainId} />}
{selectedTab === "People" && <PeopleTab brainId={brainId} />}
{selectedTab === "Knowledge" && (
<KnowledgeTab brainId={brainId} hasEditRights={hasEditRights} />
<KnowledgeTab
brainId={brainId}
hasEditRights={hasEditRights}
allKnowledge={allKnowledge}
/>
)}
</>
);

View File

@ -6,6 +6,7 @@ import { LoaderIcon } from "@/lib/components/ui/LoaderIcon/LoaderIcon";
import { MessageInfoBox } from "@/lib/components/ui/MessageInfoBox/MessageInfoBox";
import QuivrButton from "@/lib/components/ui/QuivrButton/QuivrButton";
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";
import { Knowledge } from "@/lib/types/Knowledge";
import styles from "./KnowledgeTab.module.scss";
import { KnowledgeTable } from "./KnowledgeTable/KnowledgeTable";
@ -14,9 +15,13 @@ import { useAddedKnowledge } from "./hooks/useAddedKnowledge";
type KnowledgeTabProps = {
brainId: UUID;
hasEditRights: boolean;
allKnowledge: Knowledge[];
};
export const KnowledgeTab = ({ brainId }: KnowledgeTabProps): JSX.Element => {
const { isPending, allKnowledge } = useAddedKnowledge({
export const KnowledgeTab = ({
brainId,
allKnowledge,
}: KnowledgeTabProps): JSX.Element => {
const { isPending } = useAddedKnowledge({
brainId,
});
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();