Skip to content

Commit

Permalink
feat: customise feed manage according to brain type
Browse files Browse the repository at this point in the history
  • Loading branch information
mamadoudicko committed Dec 13, 2023
1 parent 3315ee5 commit 6b1f3fa
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useTranslation } from "react-i18next";
import { LuChevronRight, LuFilePlus } from "react-icons/lu";
import { LuChevronRight } from "react-icons/lu";

import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext";

import { Button } from "./Button";
import { useFeedCardTrigger } from "./hooks/useFeedCardTrigger";
import { Button } from "../Button";

export const FeedCardTrigger = (): JSX.Element => {
const { t } = useTranslation("chat");
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
const { label, Icon } = useFeedCardTrigger();

return (
<Button
label={t("add_document")}
startIcon={<LuFilePlus size={18} />}
label={label}
startIcon={<Icon size={18} />}
endIcon={<LuChevronRight size={18} />}
className="w-full"
onClick={() => setShouldDisplayFeedCard(true)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Fragment } from "react";

import { useBrainContext } from "@/lib/context/BrainProvider/hooks/useBrainContext";

import { useFeedCardTriggerUtils } from "./useFeedCardTriggerUtils";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useFeedCardTrigger = () => {
const { brainTypeToIcon, brainTypeToLabel } = useFeedCardTriggerUtils();
const { currentBrain } = useBrainContext();

const isBrainTypeDefined = currentBrain?.brain_type !== undefined;

return {
label: isBrainTypeDefined ? brainTypeToLabel[currentBrain.brain_type] : "",
Icon: isBrainTypeDefined
? brainTypeToIcon[currentBrain.brain_type]
: Fragment,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useTranslation } from "react-i18next";
import { IconType } from "react-icons/lib";
import { LuBot, LuFilePlus, LuUnlock } from "react-icons/lu";

import { BrainType } from "@/lib/types/brainConfig";

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useFeedCardTriggerUtils = () => {
const { t } = useTranslation(["chat", "brain"]);

const brainTypeToLabel: Record<BrainType, string> = {
doc: t("chat:add_document"),
api: t("brain:update_secrets_button"),
composite: t("brain:manage_brain"),
};

const brainTypeToIcon: Record<BrainType, IconType> = {
doc: LuFilePlus,
api: LuUnlock,
composite: LuBot,
};

return {
brainTypeToIcon,
brainTypeToLabel,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./FeedCardTrigger";

0 comments on commit 6b1f3fa

Please sign in to comment.