-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow user to feed brain from Actions bar (#1882)
Issue: #1881 Demo: https://github.com/StanGirard/quivr/assets/63923024/348c7b17-84ca-46a3-89e3-3a00a621af69
- Loading branch information
1 parent
35bc5bc
commit 9eb6120
Showing
15 changed files
with
88 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...mponents/ChatInput/components/ActionsModal/components/FeedCardTrigger/FeedCardTrigger.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { LuChevronRight } from "react-icons/lu"; | ||
|
||
import { useKnowledgeToFeedContext } from "@/lib/context/KnowledgeToFeedProvider/hooks/useKnowledgeToFeedContext"; | ||
|
||
import { useFeedCardTrigger } from "./hooks/useFeedCardTrigger"; | ||
import { Button } from "../Button"; | ||
|
||
export const FeedCardTrigger = (): JSX.Element => { | ||
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext(); | ||
const { label, Icon } = useFeedCardTrigger(); | ||
|
||
return ( | ||
<Button | ||
label={label} | ||
startIcon={<Icon size={18} />} | ||
endIcon={<LuChevronRight size={18} />} | ||
className="w-full" | ||
onClick={() => setShouldDisplayFeedCard(true)} | ||
/> | ||
); | ||
}; |
20 changes: 20 additions & 0 deletions
20
.../ChatInput/components/ActionsModal/components/FeedCardTrigger/hooks/useFeedCardTrigger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
...Input/components/ActionsModal/components/FeedCardTrigger/hooks/useFeedCardTriggerUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
...tionsBar/components/ChatInput/components/ActionsModal/components/FeedCardTrigger/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./FeedCardTrigger"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters