From c055f40dffe67dd0e847026b56e3b804dcd5eb0e Mon Sep 17 00:00:00 2001 From: balibabu <cike8899@users.noreply.github.com> Date: Fri, 19 Apr 2024 19:05:30 +0800 Subject: [PATCH] feat: #345 even if the backend data returns empty, the skeleton of the chart will be displayed. (#461) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … chart will be displayed. ### What problem does this PR solve? feat: #345 even if the backend data returns empty, the skeleton of the chart will be displayed. ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/components/line-chart/index.tsx | 5 ++- web/src/locales/en.ts | 5 +-- web/src/locales/zh-traditional.ts | 11 +++-- web/src/locales/zh.ts | 9 ++-- .../pages/chat/chat-api-key-modal/index.tsx | 2 + .../pages/chat/chat-overview-modal/index.less | 2 +- .../pages/chat/chat-overview-modal/index.tsx | 41 ++++++++++++------- web/src/pages/chat/model.ts | 1 + 8 files changed, 45 insertions(+), 31 deletions(-) diff --git a/web/src/components/line-chart/index.tsx b/web/src/components/line-chart/index.tsx index 6c03220..81ae954 100644 --- a/web/src/components/line-chart/index.tsx +++ b/web/src/components/line-chart/index.tsx @@ -50,9 +50,10 @@ const data = [ interface IProps extends CategoricalChartProps { data?: Array<{ xAxis: string; yAxis: number }>; + showLegend?: boolean; } -const RagLineChart = ({ data }: IProps) => { +const RagLineChart = ({ data, showLegend = false }: IProps) => { return ( <ResponsiveContainer width="100%" height="100%"> <LineChart @@ -72,7 +73,7 @@ const RagLineChart = ({ data }: IProps) => { <XAxis dataKey="xAxis" /> <YAxis /> <Tooltip /> - <Legend /> + {showLegend && <Legend />} <Line type="monotone" dataKey="yAxis" diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index ea3f507..18b94cd 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -349,19 +349,18 @@ export default { 'This sets the maximum length of the model’s output, measured in the number of tokens (words or pieces of words).', quote: 'Show Quote', quoteTip: 'Should the source of the original text be displayed?', - overview: 'API', + overview: 'Chat Bot API', pv: 'Number of messages', uv: 'Active user number', speed: 'Token output speed', tokens: 'Consume the token number', round: 'Session Interaction Number', thumbUp: 'customer satisfaction', - publicUrl: 'Public URL', preview: 'Preview', embedded: 'Embedded', serviceApiEndpoint: 'Service API Endpoint', apiKey: 'Api Key', - apiReference: 'Api Reference', + apiReference: 'API Documents', dateRange: 'Date Range:', backendServiceApi: 'Backend service API', createNewKey: 'Create new key', diff --git a/web/src/locales/zh-traditional.ts b/web/src/locales/zh-traditional.ts index 73c150a..21ba278 100644 --- a/web/src/locales/zh-traditional.ts +++ b/web/src/locales/zh-traditional.ts @@ -321,21 +321,20 @@ export default { '這č¨ç˝®äş†ć¨ˇĺž‹čĽ¸ĺ‡şçš„最大長度,以標č¨ďĽĺ–®č©žć–單詞片段)的數量來衡量。', quote: '顯示引文', quoteTip: 'ćŻĺ¦ć‡‰č©˛éˇŻç¤şĺŽźć–‡ĺ‡şč™•ďĽź', - overview: 'API', + overview: 'čŠĺ¤© API', pv: 'ć¶ćŻć•¸', uv: '活躍用ć¶ć•¸', speed: 'Token 輸出速度', tokens: 'ć¶č€—Token數', round: 'ćśč©±äş’動數', thumbUp: '用ć¶ć»żć„Źĺş¦', - publicUrl: '公共url', preview: 'é 覽', embedded: '嵌入', - serviceApiEndpoint: '服務API端點', - apiKey: 'API鍵', - apiReference: 'APIĺŹč€', + serviceApiEndpoint: '服務 API 端點', + apiKey: 'API 鍵', + apiReference: 'API 文件', dateRange: '日期範圍:', - backendServiceApi: '後端服務API', + backendServiceApi: '後端服務 API', createNewKey: '創建新密鑰', created: '創建於', action: '操作', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index b379303..439be39 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -338,21 +338,20 @@ export default { 'čż™č®ľç˝®äş†ć¨ˇĺž‹čľ“ĺ‡şçš„ćś€ĺ¤§é•żĺş¦ďĽŚä»Ąć ‡č®°ďĽĺŤ•词ć–单词片段)的数量来衡量。', quote: 'ćľç¤şĺĽ•ć–‡', quoteTip: 'ćŻĺ¦ĺş”该ćľç¤şĺŽźć–‡ĺ‡şĺ¤„ďĽź', - overview: 'API', + overview: 'čŠĺ¤© API', pv: 'ć¶ćŻć•°', uv: 'ć´»č·ç”¨ć·ć•°', speed: 'Token 输出速度', tokens: 'ć¶č€—Tokenć•°', round: '会话互动数', thumbUp: '用ć·ć»ˇć„Źĺş¦', - publicUrl: '公共Url', preview: '预č§', embedded: '嵌入', serviceApiEndpoint: '服务API端点', - apiKey: 'APIé”®', - apiReference: 'API参č€', + apiKey: 'API é”®', + apiReference: 'API 文档', dateRange: 'ć—ĄćśźčŚĺ›´ďĽš', - backendServiceApi: 'ĺŽç«ŻćśŤĺЎAPI', + backendServiceApi: 'ĺŽç«ŻćśŤĺЎ API', createNewKey: 'ĺ›ĺ»şć–°ĺŻ†é’Ą', created: 'ĺ›ĺ»şäşŽ', action: '操作', diff --git a/web/src/pages/chat/chat-api-key-modal/index.tsx b/web/src/pages/chat/chat-api-key-modal/index.tsx index b4545a4..c3bb10b 100644 --- a/web/src/pages/chat/chat-api-key-modal/index.tsx +++ b/web/src/pages/chat/chat-api-key-modal/index.tsx @@ -50,7 +50,9 @@ const ChatApiKeyModal = ({ title={t('apiKey')} open={visible} onCancel={hideModal} + cancelButtonProps={{ style: { display: 'none' } }} style={{ top: 300 }} + onOk={hideModal} width={'50vw'} > <Table diff --git a/web/src/pages/chat/chat-overview-modal/index.less b/web/src/pages/chat/chat-overview-modal/index.less index 1a37671..eeccc2f 100644 --- a/web/src/pages/chat/chat-overview-modal/index.less +++ b/web/src/pages/chat/chat-overview-modal/index.less @@ -5,7 +5,7 @@ .chartItem { height: 300px; - padding: 10px 0 30px; + padding: 10px 0 50px; } .chartLabel { diff --git a/web/src/pages/chat/chat-overview-modal/index.tsx b/web/src/pages/chat/chat-overview-modal/index.tsx index 6381d65..21856bd 100644 --- a/web/src/pages/chat/chat-overview-modal/index.tsx +++ b/web/src/pages/chat/chat-overview-modal/index.tsx @@ -2,6 +2,7 @@ import LineChart from '@/components/line-chart'; import { useSetModalState, useTranslate } from '@/hooks/commonHooks'; import { IModalProps } from '@/interfaces/common'; import { IDialog, IStats } from '@/interfaces/database/chat'; +import { formatDate } from '@/utils/date'; import { Button, Card, DatePicker, Flex, Modal, Space, Typography } from 'antd'; import { RangePickerProps } from 'antd/es/date-picker'; import dayjs from 'dayjs'; @@ -19,13 +20,29 @@ import styles from './index.less'; const { Paragraph } = Typography; const { RangePicker } = DatePicker; +const StatsLineChart = ({ statsType }: { statsType: keyof IStats }) => { + const { t } = useTranslate('chat'); + const chartList = useSelectChartStatsList(); + const list = + chartList[statsType]?.map((x) => ({ + ...x, + xAxis: formatDate(x.xAxis), + })) ?? []; + + return ( + <div className={styles.chartItem}> + <b className={styles.chartLabel}>{t(camelCase(statsType))}</b> + <LineChart data={list}></LineChart> + </div> + ); +}; + const ChatOverviewModal = ({ visible, hideModal, dialog, }: IModalProps<any> & { dialog: IDialog }) => { const { t } = useTranslate('chat'); - const chartList = useSelectChartStatsList(); const { visible: apiKeyVisible, hideModal: hideApiKeyModal, @@ -53,6 +70,8 @@ const ChatOverviewModal = ({ title={t('overview')} open={visible} onCancel={hideModal} + cancelButtonProps={{ style: { display: 'none' } }} + onOk={hideModal} width={'100vw'} > <Flex vertical gap={'middle'}> @@ -76,14 +95,8 @@ const ChatOverviewModal = ({ </a> </Space> </Card> - <Card title={dialog.name}> + <Card title={`${dialog.name} Web App`}> <Flex gap={8} vertical> - {t('publicUrl')} - {/* <Flex className={styles.linkText} gap={10}> - <span>{urlWithToken}</span> - <CopyToClipboard text={urlWithToken}></CopyToClipboard> - <ReloadOutlined onClick={createUrlToken} /> - </Flex> */} <Space size={'middle'}> <Button onClick={handlePreview}>{t('preview')}</Button> <Button onClick={showEmbedModal}>{t('embedded')}</Button> @@ -101,12 +114,12 @@ const ChatOverviewModal = ({ /> </Space> <div className={styles.chartWrapper}> - {Object.keys(chartList).map((x) => ( - <div key={x} className={styles.chartItem}> - <b className={styles.chartLabel}>{t(camelCase(x))}</b> - <LineChart data={chartList[x as keyof IStats]}></LineChart> - </div> - ))} + <StatsLineChart statsType={'pv'}></StatsLineChart> + <StatsLineChart statsType={'round'}></StatsLineChart> + <StatsLineChart statsType={'speed'}></StatsLineChart> + <StatsLineChart statsType={'thumb_up'}></StatsLineChart> + <StatsLineChart statsType={'tokens'}></StatsLineChart> + <StatsLineChart statsType={'uv'}></StatsLineChart> </div> </Flex> <ChatApiKeyModal diff --git a/web/src/pages/chat/model.ts b/web/src/pages/chat/model.ts index e1a6122..1651f4c 100644 --- a/web/src/pages/chat/model.ts +++ b/web/src/pages/chat/model.ts @@ -210,6 +210,7 @@ const model: DvaModel<ChatModelState> = { omit(payload, ['dialogId']), ); if (data.retcode === 0) { + message.success(i18n.t('message.deleted')); yield put({ type: 'listToken', payload: { dialog_id: payload.dialogId }, -- GitLab