From fb32c4baaedaf820d92b0c201716d3f607c8de4e Mon Sep 17 00:00:00 2001 From: Alban Dumouilla Date: Mon, 2 Dec 2024 10:11:18 +0100 Subject: [PATCH] Adding a function to get assistants' author on popover opening (#8972) * Adding a function to get assistants' author on popover opening for feedback * Make getLastAuthor not mandatory * Add getPopoverInfo to the FeedbackSelector component * Rename feedbackselector * Feedbackselector rename bis * Cleaner spinner * Stories change * Bump version --- sparkle/package-lock.json | 4 +- sparkle/package.json | 2 +- .../ConversationMessageFeedbackSelector.tsx | 121 -------------- sparkle/src/components/FeedbackSelector.tsx | 153 ++++++++++++++++++ sparkle/src/components/index.ts | 4 +- .../src/stories/FeedbackSelector.stories.tsx | 7 +- 6 files changed, 162 insertions(+), 129 deletions(-) delete mode 100644 sparkle/src/components/ConversationMessageFeedbackSelector.tsx create mode 100644 sparkle/src/components/FeedbackSelector.tsx diff --git a/sparkle/package-lock.json b/sparkle/package-lock.json index 30306fd190df..f807a5ab8e71 100644 --- a/sparkle/package-lock.json +++ b/sparkle/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dust-tt/sparkle", - "version": "0.2.329", + "version": "0.2.330", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dust-tt/sparkle", - "version": "0.2.329", + "version": "0.2.330", "license": "ISC", "dependencies": { "@emoji-mart/data": "^1.1.2", diff --git a/sparkle/package.json b/sparkle/package.json index 58ef206cf7af..13eb41c3ad9f 100644 --- a/sparkle/package.json +++ b/sparkle/package.json @@ -1,6 +1,6 @@ { "name": "@dust-tt/sparkle", - "version": "0.2.329", + "version": "0.2.330", "scripts": { "build": "rm -rf dist && npm run tailwind && npm run build:esm && npm run build:cjs", "tailwind": "tailwindcss -i ./src/styles/tailwind.css -o dist/sparkle.css", diff --git a/sparkle/src/components/ConversationMessageFeedbackSelector.tsx b/sparkle/src/components/ConversationMessageFeedbackSelector.tsx deleted file mode 100644 index 7cd1e7b28bd5..000000000000 --- a/sparkle/src/components/ConversationMessageFeedbackSelector.tsx +++ /dev/null @@ -1,121 +0,0 @@ -import React, { useEffect, useRef } from "react"; - -import { Button } from "@sparkle/components/Button"; -import { Page } from "@sparkle/components/Page"; -import { - PopoverContent, - PopoverRoot, - PopoverTrigger, -} from "@sparkle/components/Popover"; -import { TextArea } from "@sparkle/components/TextArea"; -import { HandThumbDownIcon, HandThumbUpIcon } from "@sparkle/icons/solid"; - -export type ThumbReaction = "up" | "down"; -export type ConversationMessageFeedbackType = { - thumb: ThumbReaction; - feedbackContent: string | null; -}; -export interface ConversationMessageFeedbackSelectorProps { - feedback: ConversationMessageFeedbackType | null; - onSubmitThumb: ( - p: ConversationMessageFeedbackType & { - isToRemove: boolean; - } - ) => Promise; - isSubmittingThumb: boolean; -} - -export function FeedbackSelector( - messageFeedback: ConversationMessageFeedbackSelectorProps -) { - const { feedback, onSubmitThumb, isSubmittingThumb } = messageFeedback; - const [isPopoverOpen, setIsPopoverOpen] = React.useState(false); - const containerRef = useRef(null); - const [localFeedbackContent, setLocalFeedbackContent] = React.useState< - string | null - >(null); - - // Reset local feedback content when popup opens - useEffect(() => { - if (isPopoverOpen) { - setLocalFeedbackContent(feedback?.feedbackContent ?? null); - } - }, [isPopoverOpen, feedback?.feedbackContent]); - - const selectThumb = async (thumb: ThumbReaction) => { - const isToRemove = feedback?.thumb === thumb; - setIsPopoverOpen(!isToRemove); - - await onSubmitThumb({ - feedbackContent: localFeedbackContent, - thumb, - isToRemove, - }); - }; - - return ( -
- - -
-
-
- -
- - {feedback?.thumb === "up" - ? "🎉 Glad you liked it! Tell us more?" - : "🫠 Help make the answers better!"} - -