Files
supersonic/webapp/packages/chat-sdk/src/components/Tools/index.tsx
williamhliu 6951eada9d add chat plugin and split query to parse and execute (#25)
* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) add drill down dimensions and metric period compare and modify layout

* [feature](webapp) gitignore add supersonic-webapp

* [feature](webapp) gitignore add supersonic-webapp

* [feature](webapp) add chat plugin and split query to parse and execute

* [feature](webapp) add chat plugin and split query to parse and execute

* [feature](webapp) add chat plugin and split query to parse and execute

---------

Co-authored-by: williamhliu <williamhliu@tencent.com>
2023-08-05 22:17:42 +08:00

128 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { isMobile } from '../../utils/utils';
import { DislikeOutlined, LikeOutlined } from '@ant-design/icons';
import { Button, Popover, message } from 'antd';
import { CLS_PREFIX } from '../../common/constants';
import { MsgDataType } from '../../common/type';
import RecommendOptions from '../RecommendOptions';
import { useState } from 'react';
import classNames from 'classnames';
import { updateQAFeedback } from '../../service';
type Props = {
data: MsgDataType;
scoreValue?: number;
isLastMessage?: boolean;
isMobileMode?: boolean;
onSwitchEntity: (entityId: string) => void;
onChangeChart: () => void;
};
const Tools: React.FC<Props> = ({
data,
scoreValue,
isLastMessage,
isMobileMode,
onSwitchEntity,
onChangeChart,
}) => {
const [recommendOptionsOpen, setRecommendOptionsOpen] = useState(false);
const { queryColumns, queryResults, queryId, chatContext, queryMode } = data || {};
const [score, setScore] = useState(scoreValue || 0);
const prefixCls = `${CLS_PREFIX}-tools`;
const noDashboard =
(queryColumns?.length === 1 &&
queryColumns[0].showType === 'CATEGORY' &&
queryResults?.length === 1) ||
(!queryMode.includes('METRIC') && !queryMode.includes('ENTITY'));
console.log(
'chatContext?.properties?.CONTEXT?.plugin?.name',
chatContext?.properties?.CONTEXT?.plugin?.name
);
const changeChart = () => {
onChangeChart();
};
const addToDashboard = () => {
message.info('正在开发中,敬请期待');
};
const like = () => {
setScore(5);
updateQAFeedback(queryId, 5);
};
const dislike = () => {
setScore(1);
updateQAFeedback(queryId, 1);
};
const switchEntity = (option: string) => {
setRecommendOptionsOpen(false);
onSwitchEntity(option);
};
const likeClass = classNames(`${prefixCls}-like`, {
[`${prefixCls}-feedback-active`]: score === 5,
});
const dislikeClass = classNames(`${prefixCls}-dislike`, {
[`${prefixCls}-feedback-active`]: score === 1,
});
return (
<div className={prefixCls}>
{/* {isLastMessage && chatContext?.domainId && entityInfo?.entityId && (
<Popover
content={
<RecommendOptions
entityId={entityInfo.entityId}
domainId={chatContext.domainId}
domainName={chatContext.domainName}
isMobileMode={isMobileMode}
onSelect={switchEntity}
/>
}
placement={isMobileMode ? 'top' : 'right'}
trigger="click"
open={recommendOptionsOpen}
onOpenChange={open => setRecommendOptionsOpen(open)}
>
<Button shape="round">切换其他匹配内容</Button>
</Popover>
)} */}
{!isMobile && (
<>
{queryMode === 'METRIC_FILTER' && (
<Button shape="round" onClick={changeChart}>
</Button>
)}
{!noDashboard && (
<Button shape="round" onClick={addToDashboard}>
</Button>
)}
{isLastMessage && (
<div className={`${prefixCls}-feedback`}>
<div></div>
<LikeOutlined className={likeClass} onClick={like} />
<DislikeOutlined
className={dislikeClass}
onClick={e => {
e.stopPropagation();
dislike();
}}
/>
</div>
)}
</>
)}
</div>
);
};
export default Tools;