From ad3d5032a58f98c271efe5fbee1d71ea1e155510 Mon Sep 17 00:00:00 2001 From: Ilango Date: Wed, 13 Mar 2024 10:17:31 +0530 Subject: [PATCH] Add chat feedback, allowed domains, and speech to text options to chatflow context menu in table view --- .../src/ui-component/button/FlowListMenu.jsx | 68 +++++++++++++++++-- .../dialog/AllowedDomainsDialog.jsx | 56 +++++++++++++++ .../dialog/ChatFeedbackDialog.jsx | 56 +++++++++++++++ .../dialog/SpeechToTextDialog.jsx | 56 +++++++++++++++ 4 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 packages/ui/src/ui-component/dialog/AllowedDomainsDialog.jsx create mode 100644 packages/ui/src/ui-component/dialog/ChatFeedbackDialog.jsx create mode 100644 packages/ui/src/ui-component/dialog/SpeechToTextDialog.jsx diff --git a/packages/ui/src/ui-component/button/FlowListMenu.jsx b/packages/ui/src/ui-component/button/FlowListMenu.jsx index e8c8786ab..bfee4eb16 100644 --- a/packages/ui/src/ui-component/button/FlowListMenu.jsx +++ b/packages/ui/src/ui-component/button/FlowListMenu.jsx @@ -12,6 +12,9 @@ import FileDownloadIcon from '@mui/icons-material/Downloading' import FileDeleteIcon from '@mui/icons-material/Delete' import FileCategoryIcon from '@mui/icons-material/Category' import PictureInPictureAltIcon from '@mui/icons-material/PictureInPictureAlt' +import ThumbsUpDownOutlinedIcon from '@mui/icons-material/ThumbsUpDownOutlined' +import VpnLockOutlinedIcon from '@mui/icons-material/VpnLockOutlined' +import MicNoneOutlinedIcon from '@mui/icons-material/MicNoneOutlined' import Button from '@mui/material/Button' import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown' import { IconX } from '@tabler/icons' @@ -29,6 +32,9 @@ import StarterPromptsDialog from '@/ui-component/dialog/StarterPromptsDialog' import { generateExportFlowData } from '@/utils/genericHelper' import useNotifier from '@/utils/useNotifier' +import ChatFeedbackDialog from '../dialog/ChatFeedbackDialog' +import AllowedDomainsDialog from '../dialog/AllowedDomainsDialog' +import SpeechToTextDialog from '../dialog/SpeechToTextDialog' const StyledMenu = styled((props) => ( { setAnchorEl(event.currentTarget) @@ -105,9 +117,31 @@ export default function FlowListMenu({ chatflow, updateFlowsApi }) { setConversationStartersDialogOpen(true) } - const saveFlowStarterPrompts = async () => { - setConversationStartersDialogOpen(false) - await updateFlowsApi.request() + const handleFlowChatFeedback = () => { + setAnchorEl(null) + setChatFeedbackDialogProps({ + title: 'Chat Feedback - ' + chatflow.name, + chatflow: chatflow + }) + setChatFeedbackDialogOpen(true) + } + + const handleAllowedDomains = () => { + setAnchorEl(null) + setAllowedDomainsDialogProps({ + title: 'Allowed Domains - ' + chatflow.name, + chatflow: chatflow + }) + setAllowedDomainsDialogOpen(true) + } + + const handleSpeechToText = () => { + setAnchorEl(null) + setSpeechToTextDialogProps({ + title: 'Speech To Text - ' + chatflow.name, + chatflow: chatflow + }) + setSpeechToTextDialogOpen(true) } const saveFlowRename = async (chatflowName) => { @@ -275,6 +309,18 @@ export default function FlowListMenu({ chatflow, updateFlowsApi }) { Starter Prompts + + + Chat Feedback + + + + Allowed Domains + + + + Speech To Text + Update Category @@ -304,9 +350,23 @@ export default function FlowListMenu({ chatflow, updateFlowsApi }) { setConversationStartersDialogOpen(false)} /> + setChatFeedbackDialogOpen(false)} + /> + setAllowedDomainsDialogOpen(false)} + /> + setSpeechToTextDialogOpen(false)} + /> ) } diff --git a/packages/ui/src/ui-component/dialog/AllowedDomainsDialog.jsx b/packages/ui/src/ui-component/dialog/AllowedDomainsDialog.jsx new file mode 100644 index 000000000..6147c173b --- /dev/null +++ b/packages/ui/src/ui-component/dialog/AllowedDomainsDialog.jsx @@ -0,0 +1,56 @@ +import { createPortal } from 'react-dom' +import { useDispatch } from 'react-redux' +import { useEffect } from 'react' +import PropTypes from 'prop-types' + +// material-ui +import { Dialog, DialogContent, DialogTitle } from '@mui/material' + +// store +import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from '@/store/actions' +import useNotifier from '@/utils/useNotifier' + +// Project imports +import AllowedDomains from '@/ui-component/extended/AllowedDomains' + +const AllowedDomainsDialog = ({ show, dialogProps, onCancel }) => { + const portalElement = document.getElementById('portal') + const dispatch = useDispatch() + + useNotifier() + + useEffect(() => { + if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) + else dispatch({ type: HIDE_CANVAS_DIALOG }) + return () => dispatch({ type: HIDE_CANVAS_DIALOG }) + }, [show, dispatch]) + + const component = show ? ( + + + {dialogProps.title || 'Allowed Domains'} + + + + + + ) : null + + return createPortal(component, portalElement) +} + +AllowedDomainsDialog.propTypes = { + show: PropTypes.bool, + dialogProps: PropTypes.object, + onCancel: PropTypes.func, + onConfirm: PropTypes.func +} + +export default AllowedDomainsDialog diff --git a/packages/ui/src/ui-component/dialog/ChatFeedbackDialog.jsx b/packages/ui/src/ui-component/dialog/ChatFeedbackDialog.jsx new file mode 100644 index 000000000..a57e8ce44 --- /dev/null +++ b/packages/ui/src/ui-component/dialog/ChatFeedbackDialog.jsx @@ -0,0 +1,56 @@ +import { createPortal } from 'react-dom' +import { useDispatch } from 'react-redux' +import { useEffect } from 'react' +import PropTypes from 'prop-types' + +// material-ui +import { Dialog, DialogContent, DialogTitle } from '@mui/material' + +// store +import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from '@/store/actions' +import useNotifier from '@/utils/useNotifier' + +// Project imports +import ChatFeedback from '@/ui-component/extended/ChatFeedback' + +const ChatFeedbackDialog = ({ show, dialogProps, onCancel }) => { + const portalElement = document.getElementById('portal') + const dispatch = useDispatch() + + useNotifier() + + useEffect(() => { + if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) + else dispatch({ type: HIDE_CANVAS_DIALOG }) + return () => dispatch({ type: HIDE_CANVAS_DIALOG }) + }, [show, dispatch]) + + const component = show ? ( + + + {dialogProps.title || 'Allowed Domains'} + + + + + + ) : null + + return createPortal(component, portalElement) +} + +ChatFeedbackDialog.propTypes = { + show: PropTypes.bool, + dialogProps: PropTypes.object, + onCancel: PropTypes.func, + onConfirm: PropTypes.func +} + +export default ChatFeedbackDialog diff --git a/packages/ui/src/ui-component/dialog/SpeechToTextDialog.jsx b/packages/ui/src/ui-component/dialog/SpeechToTextDialog.jsx new file mode 100644 index 000000000..a01dafaea --- /dev/null +++ b/packages/ui/src/ui-component/dialog/SpeechToTextDialog.jsx @@ -0,0 +1,56 @@ +import { createPortal } from 'react-dom' +import { useDispatch } from 'react-redux' +import { useEffect } from 'react' +import PropTypes from 'prop-types' + +// material-ui +import { Dialog, DialogContent, DialogTitle } from '@mui/material' + +// store +import { HIDE_CANVAS_DIALOG, SHOW_CANVAS_DIALOG } from '@/store/actions' +import useNotifier from '@/utils/useNotifier' + +// Project imports +import SpeechToText from '@/ui-component/extended/SpeechToText' + +const SpeechToTextDialog = ({ show, dialogProps, onCancel }) => { + const portalElement = document.getElementById('portal') + const dispatch = useDispatch() + + useNotifier() + + useEffect(() => { + if (show) dispatch({ type: SHOW_CANVAS_DIALOG }) + else dispatch({ type: HIDE_CANVAS_DIALOG }) + return () => dispatch({ type: HIDE_CANVAS_DIALOG }) + }, [show, dispatch]) + + const component = show ? ( + + + {dialogProps.title || 'Allowed Domains'} + + + + + + ) : null + + return createPortal(component, portalElement) +} + +SpeechToTextDialog.propTypes = { + show: PropTypes.bool, + dialogProps: PropTypes.object, + onCancel: PropTypes.func, + onConfirm: PropTypes.func +} + +export default SpeechToTextDialog