From 852e101301de7fe34951476040baf7e9e536ed1e Mon Sep 17 00:00:00 2001 From: Zheng Chen Date: Tue, 28 Nov 2023 06:42:25 +0800 Subject: [PATCH] feat(gui): add event yuan_page_view, ai_* (#283) refactor(gui): rule - one action one page refactor(gui): gtag type declaration --- ui/web/public/locales/en/common.json | 1 + ui/web/public/locales/zh/common.json | 1 + ui/web/src/modules/AI/AI.tsx | 6 ++- .../AccountInfo/AccountPerformancePanel.tsx | 48 +++++++++++++++---- ui/web/src/modules/Agent/AgentConfForm.tsx | 9 ---- .../src/modules/Chart/AccountFrameChart.tsx | 1 + ui/web/src/modules/Chart/TechnicalChart.tsx | 1 + ui/web/src/modules/Pages/model.ts | 9 +++- ui/web/src/vite-env.d.ts | 2 +- 9 files changed, 57 insertions(+), 21 deletions(-) diff --git a/ui/web/public/locales/en/common.json b/ui/web/public/locales/en/common.json index e0085c44..9f42948e 100644 --- a/ui/web/public/locales/en/common.json +++ b/ui/web/public/locales/en/common.json @@ -5,6 +5,7 @@ "CreateFile_succeed": "File created successfully: {{ filename }}", "Workspace": "Workspace", "YuanCoin": "Yuan Coin", + "account": "Account", "actions": "Actions", "cancel": "Cancel", "close": "Close", diff --git a/ui/web/public/locales/zh/common.json b/ui/web/public/locales/zh/common.json index 4e2dd979..296cd767 100644 --- a/ui/web/public/locales/zh/common.json +++ b/ui/web/public/locales/zh/common.json @@ -5,6 +5,7 @@ "CreateFile_succeed": "创建文件成功: {{ filename }}", "Workspace": "", "YuanCoin": "原石", + "account": "账户", "actions": "操作", "cancel": "取消", "close": "关闭", diff --git a/ui/web/src/modules/AI/AI.tsx b/ui/web/src/modules/AI/AI.tsx index cde8f7e2..9df717e0 100644 --- a/ui/web/src/modules/AI/AI.tsx +++ b/ui/web/src/modules/AI/AI.tsx @@ -123,11 +123,15 @@ registerPage('AI', () => { pushHistoryMessages({ role: 'assistant', content: `${t('common:saved')}: ${filename}` }); agentConf$.next({ ...agentConf$.value, entry: filename }); + gtag('event', 'ai_agent_complete'); } else { pushHistoryMessages({ role: 'assistant', content: resp.data.message.content }); } + gtag('event', 'ai_complete', { type: resp.data.messageType }); } - } catch (e) {} + } catch (e) { + gtag('event', 'ai_error', { message: `${e}` }); + } setLoading(false); }; return ( diff --git a/ui/web/src/modules/AccountInfo/AccountPerformancePanel.tsx b/ui/web/src/modules/AccountInfo/AccountPerformancePanel.tsx index 7658cd9e..ac43f89f 100644 --- a/ui/web/src/modules/AccountInfo/AccountPerformancePanel.tsx +++ b/ui/web/src/modules/AccountInfo/AccountPerformancePanel.tsx @@ -1,10 +1,11 @@ import { IconInfoCircle } from '@douyinfe/semi-icons'; -import { Descriptions, Select, Space, Tooltip } from '@douyinfe/semi-ui'; +import { Button, Descriptions, Select, Space, Tooltip } from '@douyinfe/semi-ui'; import { AccountPerformanceUnit, IAccountPerformance } from '@yuants/kernel'; import { useObservableState } from 'observable-hooks'; import { useState } from 'react'; import { Trans, useTranslation } from 'react-i18next'; import { WeeklyEquityChart } from '../Chart/WeeklyEquityChart'; +import { executeCommand } from '../CommandCenter'; import { registerPage } from '../Pages'; import { accountPerformance$ } from './model'; @@ -19,13 +20,44 @@ registerPage('AccountPerformancePanel', () => { return ( - + + + + + + + { Object.fromEntries(scene.accountPerformanceUnit.mapAccountIdToPerformance.entries()), ); accountFrameSeries$.next(accountFrameUnit.data); - if (Object.keys(scene.agentUnit.record_table).length > 0) { - executeCommand('Page.open', { type: 'RecordTablePanel' }); - } } else { const terminal = await firstValueFrom(terminal$); const agentCode = await bundleCode(agentConf.entry!); @@ -180,14 +177,8 @@ runAgentAction$.subscribe(async () => { Object.fromEntries(scene.accountPerformanceUnit.mapAccountIdToPerformance.entries()), ); accountFrameSeries$.next(accountFrameUnit.data); - if (Object.keys(scene.agentUnit.record_table).length > 0) { - executeCommand('Page.open', { type: 'RecordTablePanel' }); - } } - executeCommand('Page.open', { type: 'OrderListPanel' }); - executeCommand('Page.open', { type: 'TechnicalChart' }); - executeCommand('Page.open', { type: 'AccountFrameChart' }); executeCommand('Page.open', { type: 'AccountPerformancePanel' }); Toast.success(t('AgentConfForm:run_succeed')); diff --git a/ui/web/src/modules/Chart/AccountFrameChart.tsx b/ui/web/src/modules/Chart/AccountFrameChart.tsx index 4c79ee6c..336d7305 100644 --- a/ui/web/src/modules/Chart/AccountFrameChart.tsx +++ b/ui/web/src/modules/Chart/AccountFrameChart.tsx @@ -42,6 +42,7 @@ registerPage('AccountFrameChart', () => { return (
{ setAccountId(v as string); diff --git a/ui/web/src/modules/Pages/model.ts b/ui/web/src/modules/Pages/model.ts index c56e16cf..d74f6950 100644 --- a/ui/web/src/modules/Pages/model.ts +++ b/ui/web/src/modules/Pages/model.ts @@ -1,9 +1,14 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { executeCommand, registerCommand } from '../CommandCenter'; export const AvailableComponents: Record = {}; export const registerPage = (type: string, component: React.ComponentType) => { - AvailableComponents[type] = React.memo(component); + AvailableComponents[type] = React.memo(() => { + useEffect(() => { + gtag('event', 'yuan_page_view', { type }); + }, []); + return React.createElement(component); + }); registerCommand(type, (params) => executeCommand('Page.open', { type, params })); }; diff --git a/ui/web/src/vite-env.d.ts b/ui/web/src/vite-env.d.ts index 59e54cb1..0030d317 100644 --- a/ui/web/src/vite-env.d.ts +++ b/ui/web/src/vite-env.d.ts @@ -41,4 +41,4 @@ declare module 'lightweight-charts/dist/lightweight-charts.esm.development.js' { export * from 'lightweight-charts'; } -declare function gtag(...args: any[]); +declare function gtag(op: 'event', eventName: string, args?: {});