Skip to content

Commit

Permalink
feat(gui): add event yuan_page_view, ai_* (#283)
Browse files Browse the repository at this point in the history
refactor(gui): rule - one action one page
refactor(gui): gtag type declaration
  • Loading branch information
zccz14 authored Nov 27, 2023
1 parent aafe527 commit 852e101
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 21 deletions.
1 change: 1 addition & 0 deletions ui/web/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"CreateFile_succeed": "File created successfully: {{ filename }}",
"Workspace": "Workspace",
"YuanCoin": "Yuan Coin",
"account": "Account",
"actions": "Actions",
"cancel": "Cancel",
"close": "Close",
Expand Down
1 change: 1 addition & 0 deletions ui/web/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"CreateFile_succeed": "创建文件成功: {{ filename }}",
"Workspace": "",
"YuanCoin": "原石",
"account": "账户",
"actions": "操作",
"cancel": "取消",
"close": "关闭",
Expand Down
6 changes: 5 additions & 1 deletion ui/web/src/modules/AI/AI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
48 changes: 40 additions & 8 deletions ui/web/src/modules/AccountInfo/AccountPerformancePanel.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,13 +20,44 @@ registerPage('AccountPerformancePanel', () => {

return (
<Space vertical align="start" style={{ width: '100%' }}>
<Select
value={accountId}
onChange={(v) => {
setAccountId(v as string);
}}
optionList={accountIdOptions.map((v) => ({ label: v, value: v }))}
></Select>
<Space>
<Select
prefix={t('common:account')}
value={accountId}
onChange={(v) => {
setAccountId(v as string);
}}
optionList={accountIdOptions.map((v) => ({ label: v, value: v }))}
></Select>
<Button
onClick={() => {
executeCommand('TechnicalChart');
}}
>
{t('pages:TechnicalChart')}
</Button>
<Button
onClick={() => {
executeCommand('OrderListPanel');
}}
>
{t('pages:OrderListPanel')}
</Button>
<Button
onClick={() => {
executeCommand('AccountFrameChart');
}}
>
{t('pages:AccountFrameChart')}
</Button>
<Button
onClick={() => {
executeCommand('RecordTablePanel');
}}
>
{t('pages:RecordTablePanel')}
</Button>
</Space>
<Descriptions
data={[
{
Expand Down
9 changes: 0 additions & 9 deletions ui/web/src/modules/Agent/AgentConfForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ 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' });
}
} else {
const terminal = await firstValueFrom(terminal$);
const agentCode = await bundleCode(agentConf.entry!);
Expand All @@ -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'));
Expand Down
1 change: 1 addition & 0 deletions ui/web/src/modules/Chart/AccountFrameChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ registerPage('AccountFrameChart', () => {
return (
<div style={{ height: '100%' }}>
<Select
prefix={t('common:account')}
value={accountId}
onChange={(v) => {
setAccountId(v as string);
Expand Down
1 change: 1 addition & 0 deletions ui/web/src/modules/Chart/TechnicalChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ registerPage('TechnicalChart', () => {
<Space vertical align="start" style={{ height: '100%', width: '100%' }}>
<Space>
<Select
prefix={t('common:account')}
value={accountId}
onChange={(v) => {
setAccountId(v as string);
Expand Down
9 changes: 7 additions & 2 deletions ui/web/src/modules/Pages/model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import React from 'react';
import React, { useEffect } from 'react';
import { executeCommand, registerCommand } from '../CommandCenter';

export const AvailableComponents: Record<string, React.ComponentType> = {};

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 }));
};
2 changes: 1 addition & 1 deletion ui/web/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?: {});

0 comments on commit 852e101

Please sign in to comment.