Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/base/src/locale/en-US/dmsHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default {
times: 'times',
aiPerformanceEngine: 'AI Performance Engine',
aiSmartCorrection: 'AI Smart Correction',
aiPerformanceEngineNoPermissionPrompt:
'No SQL optimization permission. Please contact your administrator',
paidFeaturePrompt:
'This feature is a paid value-added module. Please contact sales for details',
aiBannerExampleDrawerTitle: 'SQL Rewritten Example',
Expand Down
1 change: 1 addition & 0 deletions packages/base/src/locale/zh-CN/dmsHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
times: '次',
aiPerformanceEngine: 'AI 性能引擎',
aiSmartCorrection: 'AI 智能修正',
aiPerformanceEngineNoPermissionPrompt: '暂无 SQL 调优权限,请联系管理员',
paidFeaturePrompt: '当前功能为付费增值模块,请联系商务获取详细信息',
aiBannerExampleDrawerTitle: 'SQL 重写示例',
aiBannerExampleDrawerDescription:
Expand Down
24 changes: 20 additions & 4 deletions packages/base/src/page/Home/AIBanner/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { mockUseRecentlyOpenedProjects } from '../../../Nav/SideMenu/testUtils/m
import { baseSuperRender } from '../../../../testUtils/superRender';
import AIBanner from '..';
import { mockUsePermission } from '@actiontech/shared/lib/testUtil';
import { PERMISSIONS } from '@actiontech/shared/lib/features';

jest.mock('react-router-dom', () => {
return {
Expand Down Expand Up @@ -221,17 +222,32 @@ describe('test base/home/AIBanner', () => {
expect(screen.getByText('SQL 重写示例')).toBeInTheDocument();
});

it('should not render viewFullReport and performance engine button when all modules are disabled', async () => {
it('should render performance engine button and show no permission prompt when no optimization permission', async () => {
mockUsePermission(
{
checkPagePermission: jest.fn().mockReturnValue(false)
checkPagePermission: jest.fn((permissionKey) => {
if (permissionKey === PERMISSIONS.PAGES.SQLE.SQL_OPTIMIZATION) {
return false;
}
return true;
})
},
{ useSpyOnMockHooks: true }
);

baseSuperRender(<AIBanner />);
await act(async () => jest.advanceTimersByTime(3300));

expect(screen.queryByText('查看完整报告')).not.toBeInTheDocument();
expect(screen.queryByText('AI 性能引擎')).not.toBeInTheDocument();
expect(screen.getByText('查看完整报告')).toBeInTheDocument();
expect(screen.getByText('AI 性能引擎')).toBeInTheDocument();

fireEvent.click(screen.getByText('AI 性能引擎'));

expect(
screen.getByText('暂无 SQL 调优权限,请联系管理员')
).toBeInTheDocument();
expect(navigateSpy).not.toHaveBeenCalledWith(
'/sqle/project/1/sql-audit/create-optimization'
);
});
});
50 changes: 31 additions & 19 deletions packages/base/src/page/Home/AIBanner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useMemo, useState } from 'react';
import { useRequest } from 'ahooks';
import { Card, Space, Typography, message } from 'antd';
import { Card, Space, Typography } from 'antd';
import { useTranslation } from 'react-i18next';
import { useTypedNavigate } from '@actiontech/shared';
import { useNotificationContext, useTypedNavigate } from '@actiontech/shared';
import { BasicButton, BasicTag } from '@actiontech/dms-kit';
import { AiHubService } from '@actiontech/shared/lib/api/sqle';
import {
Expand Down Expand Up @@ -32,7 +32,8 @@ type PendingProjectAction = 'performance' | null;
const AIBanner: React.FC = () => {
const { t } = useTranslation();
const navigate = useTypedNavigate();
const [messageApi, messageContextHolder] = message.useMessage();
const { notificationContextHolder, openNotification } =
useNotificationContext();
const { bindProjects } = useCurrentUser();
const { currentProjectID, updateRecentlyProject } =
useRecentlyOpenedProjects();
Expand Down Expand Up @@ -97,7 +98,15 @@ const AIBanner: React.FC = () => {
}, [bannerData]);

const showPaidFeaturePrompt = () => {
messageApi.info(t('dmsHome.aiBanner.paidFeaturePrompt'));
openNotification('info', {
message: t('dmsHome.aiBanner.paidFeaturePrompt')
});
};

const showNoOptimizationPermissionPrompt = () => {
openNotification('warning', {
message: t('dmsHome.aiBanner.aiPerformanceEngineNoPermissionPrompt')
});
};

// 处理查看完整报告跳转
Expand All @@ -118,6 +127,10 @@ const AIBanner: React.FC = () => {
showPaidFeaturePrompt();
return;
}
if (!checkPagePermission(PERMISSIONS.PAGES.SQLE.SQL_OPTIMIZATION)) {
showNoOptimizationPermissionPrompt();
return;
}

if (!currentProjectID) {
setPendingAction('performance');
Expand Down Expand Up @@ -157,7 +170,7 @@ const AIBanner: React.FC = () => {

return (
<AIBannerStyleWrapper>
{messageContextHolder}
{notificationContextHolder}
<Card className="ai-banner-card" loading={loading}>
<div className="banner-content">
{/* 左侧:AI治理效能洞察 */}
Expand Down Expand Up @@ -232,20 +245,19 @@ const AIBanner: React.FC = () => {

{/* 右侧:快捷行动按钮 */}
<div className="right-section">
{showPerformanceEngineButton &&
checkPagePermission(PERMISSIONS.PAGES.SQLE.SQL_OPTIMIZATION) && (
<BasicButton
type="primary"
size="large"
className="action-button primary-button"
onClick={handleAIPerformanceEngine}
>
<Space>
{t('dmsHome.aiBanner.aiPerformanceEngine')}
<RightOutlined />
</Space>
</BasicButton>
)}
{showPerformanceEngineButton && (
<BasicButton
type="primary"
size="large"
className="action-button primary-button"
onClick={handleAIPerformanceEngine}
>
<Space>
{t('dmsHome.aiBanner.aiPerformanceEngine')}
<RightOutlined />
</Space>
</BasicButton>
)}
{showSmartCorrectionButton && (
<BasicButton
size="large"
Expand Down
6 changes: 3 additions & 3 deletions packages/base/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ export default defineConfig(() => {
open: true,
proxy: {
'^(/v|/sqle/v)': {
target: 'http://10.186.62.13:11000/'
target: 'http://10.186.61.30:11000/'
},
'^/provision/v': {
target: 'http://10.186.62.13:11000/'
target: 'http://10.186.61.30:11000/'
},
'^/logo': {
target: 'http://10.186.62.13:11000/'
target: 'http://10.186.61.30:11000/'
}
},
cors: true
Expand Down
4 changes: 2 additions & 2 deletions scripts/jest/run.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

test_version=${2:-ce}
test_version=${2:-ee}
echo "current test version: $test_version"

export JEST_TEST_VERSION_ENV=$test_version

pnpm jest -u --maxWorkers=50% --watchAll=true --filter='<rootDir>/scripts/jest/custom-filter' --logHeapUsage $1
pnpm jest --maxWorkers=50% --watchAll=true --filter='<rootDir>/scripts/jest/custom-filter' --logHeapUsage $1
Loading