From f40eeddbdc78f6d3b11a6831aabd541b922aee48 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Wed, 17 Jul 2024 11:12:42 +0800 Subject: [PATCH 01/14] feat: add pm2-logrotate for split logs by day --- .env | 2 +- docker/Dockerfile.server | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 29bdcd0..a598b98 100644 --- a/.env +++ b/.env @@ -21,7 +21,7 @@ DB_PASSWORD='123456' DB_DATABASE='yice-performance' # devops 的默认用户名和密码 -DEVOPS_USERNAME="admin@dtstack.com" +DEVOPS_USERNAME="admin" DEVOPS_PASSWORD="123456" # devops 接口请求时默认的 cookie DEVOPS_COOKIE="" diff --git a/docker/Dockerfile.server b/docker/Dockerfile.server index 9bf4ee3..41ea81a 100644 --- a/docker/Dockerfile.server +++ b/docker/Dockerfile.server @@ -38,7 +38,11 @@ RUN apt-get update -y && apt-get install -y curl \ && apt-get remove -y curl \ && apt-get install -y nodejs \ && npm config set registry https://registry.npmmirror.com/ \ - && npm install pnpm@6.35.1 pm2 -g + && npm install pnpm@6.35.1 pm2 -g \ + # pm2 切分日志 + && pm2 install pm2-logrotate \ + && pm2 set pm2-logrotate:dateFormat YYYY-MM-DD \ + && pm2 set pm2-logrotate:rotateInterval '0 0 * * *' # 设置工作目录 WORKDIR /yice-performance From 608aeec5f1bb9701258162c76f98aaff59d03c39 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Thu, 18 Jul 2024 11:42:18 +0800 Subject: [PATCH 02/14] ci: with turbo --- .github/workflows/CI.yml | 5 ++- .gitlab-ci.yml | 13 +++++- .prettierignore | 1 + .vscode/settings.json | 5 --- apps/server/src/modules/task/dto/task.dto.ts | 1 + .../src/modules/version/dto/version.dto.ts | 1 + apps/server/src/utils/taskRun.ts | 1 + apps/web/src/utils/index.ts | 1 + .../chartModal/projectChart/index.tsx | 2 +- apps/web/tsconfig.json | 1 - package.json | 17 ++++--- pnpm-lock.yaml | 44 +++++++++---------- pnpm-workspace.yaml | 4 +- turbo.json | 21 ++++++--- 14 files changed, 72 insertions(+), 45 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 97cb81f..8b93bfa 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,7 +19,7 @@ jobs: node-version: 14 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: version: 6.35.1 @@ -38,5 +38,8 @@ jobs: - name: Run test run: pnpm test + - name: Run check-types + run: pnpm check-types + - name: Run build run: pnpm build diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 855f6ac..8c3aff1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,12 +3,14 @@ before_script: - echo $CI_COMMIT_REF_NAME - whoami + - npm config set registry https://registry.npmmirror.com/ - pnpm install --reporter=silent stages: - prettier - eslint - stylelint + - check-types - test - build @@ -36,10 +38,19 @@ stylelint: rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~ /master/ +# 创建 MR 时执行;master 分支有 push 时执行 +check-types: + stage: check-types + needs: [prettier, eslint, stylelint] + script: + - pnpm check-types; + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_REF_NAME =~ /master/ + # 创建 MR 时执行;master 分支有 push 时执行 test: stage: test - needs: [prettier, eslint, stylelint] + needs: [check-types] script: - pnpm test; rules: diff --git a/.prettierignore b/.prettierignore index 263ce8f..7403c5f 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,3 +2,4 @@ *.md dist *.less +.turbo diff --git a/.vscode/settings.json b/.vscode/settings.json index 246521a..d8ee3b7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,4 @@ { - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit", - "source.fixAll.stylelint": "explicit" - }, "editor.defaultFormatter": "esbenp.prettier-vscode", "files.insertFinalNewline": true, "[typescriptreact]": { diff --git a/apps/server/src/modules/task/dto/task.dto.ts b/apps/server/src/modules/task/dto/task.dto.ts index 032a94f..f97a0e2 100644 --- a/apps/server/src/modules/task/dto/task.dto.ts +++ b/apps/server/src/modules/task/dto/task.dto.ts @@ -23,6 +23,7 @@ export class TaskDto { readonly createAt?: Date; @IsOptional() + // eslint-disable-next-line camelcase @IsUrl({ protocols: ['http', 'https'], require_protocol: true }, { message: '检测地址无效' }) @MaxLength(2048, { message: '检测地址最大长度为2048' }) @ApiPropertyOptional({ description: '检测地址' }) diff --git a/apps/server/src/modules/version/dto/version.dto.ts b/apps/server/src/modules/version/dto/version.dto.ts index d946756..e48508d 100644 --- a/apps/server/src/modules/version/dto/version.dto.ts +++ b/apps/server/src/modules/version/dto/version.dto.ts @@ -16,6 +16,7 @@ export class VersionDto { @MaxLength(64, { message: '版本名称最大长度为64' }) readonly name: string; + // eslint-disable-next-line camelcase @IsUrl({ protocols: ['http', 'https'], require_protocol: true }, { message: '检测地址无效' }) @IsNotEmpty({ message: '检测地址不能为空' }) @ApiPropertyOptional({ description: '检测地址' }) diff --git a/apps/server/src/utils/taskRun.ts b/apps/server/src/utils/taskRun.ts index ab750a2..adad225 100644 --- a/apps/server/src/utils/taskRun.ts +++ b/apps/server/src/utils/taskRun.ts @@ -217,6 +217,7 @@ export const taskRun = async (task: ITask, successCallback, failCallback, comple console.log(`taskId: ${taskId}, 开始整理数据...`); // 保存检测结果的报告文件,便于预览 + // eslint-disable-next-line no-useless-escape const urlStr = url.replace(/http(s?):\/\//g, '').replace(/\/|\#|\?|\&/g, '-'); // 创建当天的文件夹用于存放报告文件 diff --git a/apps/web/src/utils/index.ts b/apps/web/src/utils/index.ts index e3578d9..8256249 100644 --- a/apps/web/src/utils/index.ts +++ b/apps/web/src/utils/index.ts @@ -14,4 +14,5 @@ export function getImgUrl(fileName: string, url?: string) { * 以 http(s) 开头的检测地址 */ export const httpPattern = + // eslint-disable-next-line no-useless-escape /^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/; diff --git a/apps/web/src/views/home/components/chartModal/projectChart/index.tsx b/apps/web/src/views/home/components/chartModal/projectChart/index.tsx index 41c560a..7216691 100644 --- a/apps/web/src/views/home/components/chartModal/projectChart/index.tsx +++ b/apps/web/src/views/home/components/chartModal/projectChart/index.tsx @@ -26,7 +26,7 @@ export default function ProjectChart(props: IProps) { const { data } = props; const { taskList, versionNameList, maxLength } = data || {}; // echarts 顶部选择展示的版本 - const [legendSelectedMap, setLegendSelectedMap] = useState({}); + const [legendSelectedMap, setLegendSelectedMap] = useState({}); useEffect(() => { if (versionNameList?.length) { diff --git a/apps/web/tsconfig.json b/apps/web/tsconfig.json index 499759f..3038fcb 100644 --- a/apps/web/tsconfig.json +++ b/apps/web/tsconfig.json @@ -13,7 +13,6 @@ "moduleResolution": "Node", "resolveJsonModule": true, "isolatedModules": true, - "suppressImplicitAnyIndexErrors": true, "noEmit": true, "jsx": "react-jsx" }, diff --git a/package.json b/package.json index 2366bfb..7cb6ad4 100644 --- a/package.json +++ b/package.json @@ -14,14 +14,17 @@ "deploy": "zx scripts/deploy.mjs", "deploy-test": "npm run deploy test", "fileSize": "node ./scripts/report-fileSize.js", - "prettier": "npx prettier \"**/*.ts\" \"**/*.tsx\" \"**/*.js\" \"**/*.json\" --check", - "prettier:fix": "npx prettier \"**/*.ts\" \"**/*.tsx\" \"**/*.js\" \"**/*.json\" --write", - "eslint": "npx eslint \"{apps,test}/**/*.ts\" \"{apps,test}/**/*.tsx\"", - "eslint:fix": "npx eslint \"{apps,test}/**/*.ts\" \"{apps,test}/**/*.tsx\" --fix", + "prettier": "npx prettier '**/*.ts' '**/*.tsx' '**/*.js' '**/*.json' --check", + "prettier:fix": "npx prettier '**/*.ts' '**/*.tsx' '**/*.js' '**/*.json' --write", + "eslint": "npx eslint '**/*.ts' '**/*.tsx'", + "eslint:fix": "npx eslint '**/*.ts' '**/*.tsx' --fix", "stylelint": "npx stylelint '**/*.less' '**/*.css'", "stylelint:fix": "npx stylelint '**/*.less' '**/*.css' --fix", + "lint": "turbo run prettier eslint stylelint", + "lint:fix": "npm run prettier:fix && npm run eslint:fix && npm run stylelint:fix", + "check-types": "turbo run check-types --only", "test": "cd apps/server && npm run test", - "check-types": "tsc --skipLibCheck" + "ci": "turbo run prettier eslint stylelint check-types test build" }, "dependencies": { "echarts": "^5.5.0", @@ -39,7 +42,7 @@ "stylelint": "14.11.0", "ts-loader": "^9.2.3", "tsconfig-paths": "4.1.1", - "turbo": "^2.0.3", + "turbo": "2.0.7", "typescript": "4.7.4", "webpack": "^5.0.0", "zx": "^8.1.4" @@ -49,7 +52,7 @@ "path": "./node_modules/cz-conventional-changelog" } }, - "packageManager": "pnpm@6.32.17", + "packageManager": "pnpm@6.35.1", "engines": { "node": ">=14" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e6cd9d3..3df7f51 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,7 +17,7 @@ importers: stylelint: 14.11.0 ts-loader: ^9.2.3 tsconfig-paths: 4.1.1 - turbo: ^2.0.3 + turbo: 2.0.7 typescript: 4.7.4 webpack: ^5.0.0 zx: ^8.1.4 @@ -36,7 +36,7 @@ importers: stylelint: 14.11.0 ts-loader: 9.4.2_typescript@4.7.4+webpack@5.75.0 tsconfig-paths: 4.1.1 - turbo: 2.0.3 + turbo: 2.0.7 typescript: 4.7.4 webpack: 5.75.0 zx: 8.1.4 @@ -10541,64 +10541,64 @@ packages: typescript: 4.7.4 dev: true - /turbo-darwin-64/2.0.3: - resolution: {integrity: sha512-v7ztJ8sxdHw3SLfO2MhGFeeU4LQhFii1hIGs9uBiXns/0YTGOvxLeifnfGqhfSrAIIhrCoByXO7nR9wlm10n3Q==} + /turbo-darwin-64/2.0.7: + resolution: {integrity: sha512-J1RBvQGqKeUwLJrZbfrm4tHshagdMeGAwd7rpLpfUrw0PNmGfcBazJf6dIGXG59/GHzJmS0/eAZ8qDchfVbIFA==} cpu: [x64] os: [darwin] requiresBuild: true dev: true optional: true - /turbo-darwin-arm64/2.0.3: - resolution: {integrity: sha512-LUcqvkV9Bxtng6QHbevp8IK8zzwbIxM6HMjCE7FEW6yJBN1KwvTtRtsGBwwmTxaaLO0wD1Jgl3vgkXAmQ4fqUw==} + /turbo-darwin-arm64/2.0.7: + resolution: {integrity: sha512-h1JK8uuEjoHx1SvvTZiottj+4kDmiv+hivnLUzNwO75qKblMsd38IsFB0J2sMRz7JacFlf+3ry8SItznBW67Xw==} cpu: [arm64] os: [darwin] requiresBuild: true dev: true optional: true - /turbo-linux-64/2.0.3: - resolution: {integrity: sha512-xpdY1suXoEbsQsu0kPep2zrB8ijv/S5aKKrntGuQ62hCiwDFoDcA/Z7FZ8IHQ2u+dpJARa7yfiByHmizFE0r5Q==} + /turbo-linux-64/2.0.7: + resolution: {integrity: sha512-dsr7GFeHAYVMnXWDDjhpsAQetejU4OlkNBRA5hfmnIcl2sSyOYa3EvoeJ6j5z5vTNIJ9VO4I1h0jK3lTjEoonA==} cpu: [x64] os: [linux] requiresBuild: true dev: true optional: true - /turbo-linux-arm64/2.0.3: - resolution: {integrity: sha512-MBACTcSR874L1FtLL7gkgbI4yYJWBUCqeBN/iE29D+8EFe0d3fAyviFlbQP4K/HaDYet1i26xkkOiWr0z7/V9A==} + /turbo-linux-arm64/2.0.7: + resolution: {integrity: sha512-bJbwXvyX1XPzY1jHgkqggls/L4yFyHVK8GGACF3kcg6x7lYV2SXkUYRyOC3WqzW7euqa9Zw/32jrIPP4Qy31Vw==} cpu: [arm64] os: [linux] requiresBuild: true dev: true optional: true - /turbo-windows-64/2.0.3: - resolution: {integrity: sha512-zi3YuKPkM9JxMTshZo3excPk37hUrj5WfnCqh4FjI26ux6j/LJK+Dh3SebMHd9mR7wP9CMam4GhmLCT+gDfM+w==} + /turbo-windows-64/2.0.7: + resolution: {integrity: sha512-aBH+5A7IN957MqXMrw8xN0CWtH/fPFL+xTlloO6074Eaa8WfnctSAnaSujm6f4xF2T8lFx+ZprBvnO9oKvLQQQ==} cpu: [x64] os: [win32] requiresBuild: true dev: true optional: true - /turbo-windows-arm64/2.0.3: - resolution: {integrity: sha512-wmed4kkenLvRbidi7gISB4PU77ujBuZfgVGDZ4DXTFslE/kYpINulwzkVwJIvNXsJtHqyOq0n6jL8Zwl3BrwDg==} + /turbo-windows-arm64/2.0.7: + resolution: {integrity: sha512-ButUCpO5nTi+jyTSIY2mQ9dVz+mCGxJ6sHyn0xGlNoJWdisKXb0BtWCLAjM26gg/yp9Kt1MBowMQyYVruPV0Qw==} cpu: [arm64] os: [win32] requiresBuild: true dev: true optional: true - /turbo/2.0.3: - resolution: {integrity: sha512-jF1K0tTUyryEWmgqk1V0ALbSz3VdeZ8FXUo6B64WsPksCMCE48N5jUezGOH2MN0+epdaRMH8/WcPU0QQaVfeLA==} + /turbo/2.0.7: + resolution: {integrity: sha512-76iNWZpmKAKjj+yL0Wtcu2LpDIM5Nz7JS3fHOZPYS0AKuC2boJ24276VAiK4PKwbpBB//TYKDpSLuQ6cfR49pg==} hasBin: true optionalDependencies: - turbo-darwin-64: 2.0.3 - turbo-darwin-arm64: 2.0.3 - turbo-linux-64: 2.0.3 - turbo-linux-arm64: 2.0.3 - turbo-windows-64: 2.0.3 - turbo-windows-arm64: 2.0.3 + turbo-darwin-64: 2.0.7 + turbo-darwin-arm64: 2.0.7 + turbo-linux-64: 2.0.7 + turbo-linux-arm64: 2.0.7 + turbo-windows-64: 2.0.7 + turbo-windows-arm64: 2.0.7 dev: true /type-check/0.4.0: diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 651d627..0940d51 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,3 @@ packages: - - 'packages/**' - - 'apps/**' + - 'apps/**' + - 'packages/**' diff --git a/turbo.json b/turbo.json index 57e509b..6575a76 100644 --- a/turbo.json +++ b/turbo.json @@ -1,21 +1,32 @@ { "$schema": "https://turbo.build/schema.json", + "ui": "tui", "tasks": { "dev": { "persistent": true, "cache": false }, - "check-types": { - "persistent": true, - "cache": false - }, "build": { "outputs": [".apps/server/dist/**", "!.apps/server/cache/**"], - "cache": false + "cache": false, + "dependsOn": ["//#test"] }, "build-test": { "outputs": [".apps/server/dist/**", "!.apps/server/cache/**"], "cache": false + }, + "//#prettier": {}, + "//#eslint": { + "dependsOn": ["//#prettier"] + }, + "//#stylelint": { + "dependsOn": ["//#prettier", "//#eslint"] + }, + "check-types": { + "dependsOn": ["//#prettier", "//#eslint", "//#stylelint"] + }, + "//#test": { + "dependsOn": ["//#stylelint"] } } } From 6d0668e63a3689e200b9492d19af3d3563e5ad1d Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 9 Sep 2024 19:02:05 +0800 Subject: [PATCH 03/14] feat: some optimize --- .../devops/controllers/devops.controller.ts | 2 +- .../src/modules/devops/dto/devops.req.dto.ts | 2 +- .../modules/email/controllers/email.controller.ts | 13 +++++-------- .../src/modules/email/services/email.service.ts | 10 +++++----- apps/server/src/utils/echarts.ts | 4 ++-- .../components/chartModal/projectChart/index.tsx | 4 ++-- .../views/home/components/patchDataModal/index.tsx | 14 +++++++++++++- .../views/home/components/scheduleModal/index.tsx | 12 +++++++----- .../src/views/home/components/taskTable/index.tsx | 6 +++--- .../views/home/components/versionList/index.tsx | 6 +++++- 10 files changed, 44 insertions(+), 29 deletions(-) diff --git a/apps/server/src/modules/devops/controllers/devops.controller.ts b/apps/server/src/modules/devops/controllers/devops.controller.ts index 325a200..76ef8df 100644 --- a/apps/server/src/modules/devops/controllers/devops.controller.ts +++ b/apps/server/src/modules/devops/controllers/devops.controller.ts @@ -51,7 +51,7 @@ export class DevopsController { @HttpCode(HttpStatus.OK) @Get('getDevopsUrl') async getDevopsUrl(@Query() query: getStagesReqDto) { - return await this.devopsService.getDevopsUrl(query?.shiliId); + return await this.devopsService.getDevopsUrl(+query?.shiliId); } @ApiOperation({ summary: '获取 devops 项目列表' }) diff --git a/apps/server/src/modules/devops/dto/devops.req.dto.ts b/apps/server/src/modules/devops/dto/devops.req.dto.ts index 895d913..0dd7ca9 100644 --- a/apps/server/src/modules/devops/dto/devops.req.dto.ts +++ b/apps/server/src/modules/devops/dto/devops.req.dto.ts @@ -7,7 +7,7 @@ export class getShiLisReqDto { export class getStagesReqDto { @ApiPropertyOptional({ required: false, description: 'devops实例id' }) - shiliId: number; + shiliId: string; } export class getHistoriesReqDto { diff --git a/apps/server/src/modules/email/controllers/email.controller.ts b/apps/server/src/modules/email/controllers/email.controller.ts index c118b47..890d92f 100644 --- a/apps/server/src/modules/email/controllers/email.controller.ts +++ b/apps/server/src/modules/email/controllers/email.controller.ts @@ -34,17 +34,17 @@ export class EmailController { const { projectId, name, emails } = project; if (emails?.split(',').length) { try { + console.log( + `\nprojectId: ${projectId}, ${name}, 开始发送【单个子产品】的数据周报到指定邮箱` + ); await this.sendProject({ projectId, emails }); } catch (error) {} - console.log( - `\nprojectId: ${projectId}, ${name}, 发送【单个子产品】的数据周报到指定邮箱` - ); } }); } async handleSendAll() { if (process.env.DEFAULT_EMAIL) { - console.log('\n发送【所有子产品】的数据周报到指定邮箱'); + console.log('\n开始发送【所有子产品】的数据周报到指定邮箱'); await this.sendAll({ emails: process.env.DEFAULT_EMAIL }); } } @@ -143,10 +143,7 @@ export class EmailController { return result; } } catch (error) { - throw new HttpException( - `尝试发送【所有子产品】的数据周报失败, ${error}`, - HttpStatus.OK - ); + throw new HttpException(`发送【所有子产品】的数据周报失败, ${error}`, HttpStatus.OK); } } } diff --git a/apps/server/src/modules/email/services/email.service.ts b/apps/server/src/modules/email/services/email.service.ts index 08736c9..1b87ccd 100644 --- a/apps/server/src/modules/email/services/email.service.ts +++ b/apps/server/src/modules/email/services/email.service.ts @@ -32,10 +32,10 @@ export class EmailService { return result; } catch (error) { console.log( - `\nprojectId: ${projectId}, ${name}, 尝试发送【单个子产品】的数据周报失败`, + `\nprojectId: ${projectId}, ${name}, 发送【单个子产品】的数据周报失败`, error ); - throw new HttpException('尝试发送单个子产品的数据周报失败', HttpStatus.OK); + throw new HttpException('发送单个子产品的数据周报失败', HttpStatus.OK); } } } @@ -49,15 +49,15 @@ export class EmailService { try { const result = await this.mailerService.sendMail({ to: emails?.split(','), - subject: `【数栈子产品】易测数据周报(${startTime}~${endTime})`, // 标题 + subject: `【所有子产品】易测数据周报(${startTime}~${endTime})`, // 标题 html, }); console.log('\n发送【所有子产品】的数据周报成功', result); return result; } catch (error) { - console.log('\n尝试发送【所有子产品】的数据周报失败', error); - throw new HttpException('尝试发送【所有子产品】的数据周报失败', HttpStatus.OK); + console.log('\n发送【所有子产品】的数据周报失败', error); + throw new HttpException('发送【所有子产品】的数据周报失败', HttpStatus.OK); } } } diff --git a/apps/server/src/utils/echarts.ts b/apps/server/src/utils/echarts.ts index af00ab0..e5fe35c 100644 --- a/apps/server/src/utils/echarts.ts +++ b/apps/server/src/utils/echarts.ts @@ -15,8 +15,8 @@ export const getProjectChartOptions = (projectChartData: IProjectChartData) => { const legendSelectedMap = {}; if (versionNameList?.length) { for (let i = 0; i < versionNameList.length; i++) { - // 默认选择前三个 - legendSelectedMap[versionNameList[i]] = i < 3; + // 默认选择前两个 + legendSelectedMap[versionNameList[i]] = i < 2; } } diff --git a/apps/web/src/views/home/components/chartModal/projectChart/index.tsx b/apps/web/src/views/home/components/chartModal/projectChart/index.tsx index 7216691..3e6ab1d 100644 --- a/apps/web/src/views/home/components/chartModal/projectChart/index.tsx +++ b/apps/web/src/views/home/components/chartModal/projectChart/index.tsx @@ -32,8 +32,8 @@ export default function ProjectChart(props: IProps) { if (versionNameList?.length) { const _map = { ...legendSelectedMap }; for (let i = 0; i < versionNameList.length; i++) { - // 默认选择前三个 - _map[versionNameList[i]] = i < 3; + // 默认选择前两个 + _map[versionNameList[i]] = i < 2; } setLegendSelectedMap(_map); } diff --git a/apps/web/src/views/home/components/patchDataModal/index.tsx b/apps/web/src/views/home/components/patchDataModal/index.tsx index 960d58c..07d6240 100644 --- a/apps/web/src/views/home/components/patchDataModal/index.tsx +++ b/apps/web/src/views/home/components/patchDataModal/index.tsx @@ -39,6 +39,12 @@ export default function PatchDataModal(props: IProps) { }); }; + // 输入框的回车事件 + const handleInputEnter = (e: any) => { + // 中文输入法输入时回车,keyCode 是 229;光标在输入框直接回车,keyCode 是 13 + !loading && e.keyCode === 13 && handleOk(); + }; + return ( - + void; - onCancel: () => void; + onCancel: (needFetch: boolean) => void; } export default function ScheduleModal(props: IProps) { @@ -20,6 +20,7 @@ export default function ScheduleModal(props: IProps) { const [form] = Form.useForm(); const [formLoading, setFormLoading] = useState(false); const [saving, setSaving] = useState(false); + const [_isFreeze, setIsFreeze] = useState(false); const [runLoading, setRunLoading] = useState(false); const yiceRole = localStorage.getItem('yice-role'); @@ -37,6 +38,7 @@ export default function ScheduleModal(props: IProps) { API.getVersion({ versionId }) .then((res) => { const { cron, isFreeze, note } = res.data || {}; + setIsFreeze(isFreeze); setTimeout(() => { form.setFieldsValue({ cron, isFreeze, note }); }, 200); @@ -57,7 +59,7 @@ export default function ScheduleModal(props: IProps) { }) .finally(() => { setRunLoading(false); - onCancel(); + onCancel(false); }); }; @@ -69,7 +71,7 @@ export default function ScheduleModal(props: IProps) { API.updateScheduleConf({ projectId: project?.projectId, versionId, ...values }) .then(() => { message.success('保存成功!'); - onCancel(); + onCancel(_isFreeze !== values.isFreeze); }) .finally(() => { setSaving(false); @@ -121,7 +123,7 @@ export default function ScheduleModal(props: IProps) {
- + @@ -154,7 +156,7 @@ export default function ScheduleModal(props: IProps) { forceRender destroyOnClose footer={renderButtons()} - onCancel={onCancel} + onCancel={() => onCancel(false)} >
diff --git a/apps/web/src/views/home/components/taskTable/index.tsx b/apps/web/src/views/home/components/taskTable/index.tsx index 531a64d..4cff2e7 100644 --- a/apps/web/src/views/home/components/taskTable/index.tsx +++ b/apps/web/src/views/home/components/taskTable/index.tsx @@ -339,10 +339,10 @@ export default function TaskTable(props: IPros) { return (
操作 - + setScheduleOpen(false)} + onCancel={(needFetch: boolean) => { + setScheduleOpen(false); + // 冻结/解除冻结 后需要刷新版本列表 + needFetch && getVersions(!versionList.length); + }} /> ); From f7a6dfa6dd578f7a22dae3ede44bbfa065193277 Mon Sep 17 00:00:00 2001 From: liuxy0551 Date: Mon, 9 Sep 2024 20:16:09 +0800 Subject: [PATCH 04/14] feat: support 63x 70x --- .../modules/devops/services/devops.service.ts | 36 +++++++++++++++-- .../home/components/versionModal/index.tsx | 40 +++++++++++++------ 2 files changed, 59 insertions(+), 17 deletions(-) diff --git a/apps/server/src/modules/devops/services/devops.service.ts b/apps/server/src/modules/devops/services/devops.service.ts index 8885ea1..325850e 100644 --- a/apps/server/src/modules/devops/services/devops.service.ts +++ b/apps/server/src/modules/devops/services/devops.service.ts @@ -82,10 +82,38 @@ export class DevopsService { // 5、获取实例下的详情 url, 相当于同时做了 2, 3, 4 async getDevopsUrl(shiliId: number) { try { - const stages = await this.getStages(shiliId); - const histories = await this.getHistories({ shiliId, stageId: stages?.[0]?.id }); - const history = await this.getHistory(histories?.[0]?.id); - return history; + // 主机环境 + if (shiliId > 99_999) { + // 主机环境,写死地址 + // hostList 的 value 需要和 hostUrlList 的 value 同步修改 + const hostUrlList = [ + { + label: '7.0.x', + value: 100_000, + url: 'http://70x.dtstack.cn', + loginUrl: 'http://70x.dtstack.cn/uic/#/', + }, + { + label: '6.3.x', + value: 100_001, + url: 'http://63x.dtstack.cn', + loginUrl: 'http://63x.dtstack.cn/uic/#/', + }, + ]; + const portalfront = hostUrlList.find((item) => item.value === shiliId)?.url; + return { + portalfront, + loginUrl: `${portalfront}/uic/#/`, + username: process.env.DEVOPS_USERNAME, + password: process.env.DEVOPS_PASSWORD, + }; + } else { + // devops 环境 + const stages = await this.getStages(shiliId); + const histories = await this.getHistories({ shiliId, stageId: stages?.[0]?.id }); + const history = await this.getHistory(histories?.[0]?.id); + return history; + } } catch (error) { console.log(`请求 devops 接口失败, DEVOPS_COOKIE: ${process.env.DEVOPS_COOKIE}`); throw new HttpException('请求 devops 接口失败', HttpStatus.OK); diff --git a/apps/web/src/views/home/components/versionModal/index.tsx b/apps/web/src/views/home/components/versionModal/index.tsx index 0d381a9..7ba3714 100644 --- a/apps/web/src/views/home/components/versionModal/index.tsx +++ b/apps/web/src/views/home/components/versionModal/index.tsx @@ -28,7 +28,14 @@ export default function VersionModal(props: IProps) { const [deleting, setDeleting] = useState(false); const [saving, setSaving] = useState(false); const [devopsShiLiId, setDevopsShiLiId] = useState(undefined); - const [devopsShiLiList, setDevopsShiLiList] = useState([]); + const [envList, setEnvList] = useState([]); + const [envGroupList, setEnvGroupList] = useState([]); + + // hostList 的 value 需要和 hostUrlList 的 value 同步修改 + const hostList = [ + { label: '7.0.x', value: 100_000 }, + { label: '6.3.x', value: 100_001 }, + ]; const yiceRole = localStorage.getItem('yice-role'); @@ -57,30 +64,37 @@ export default function VersionModal(props: IProps) { }); }; - // 获取项目下的 devops 实例列表 + // 获取项目下的环境列表 const getShiLis = () => { setShiliFetching(true); API.getShiLis({ devopsProjectIds }) .then((res) => { - setDevopsShiLiList( + const devopsEnvList = res.data?.map((item: any) => { return { label: item.label, value: item.id, }; - }) || [] - ); + }) || []; + setEnvList(hostList.concat(devopsEnvList)); + setEnvGroupList([ + { label: '主机环境', options: hostList }, + { + label: 'devops 环境', + options: devopsEnvList, + }, + ]); }) .finally(() => { setShiliFetching(false); }); }; - // 选择了某个 devops 实例 + // 选择了某个环境 const handleSelect = (value: any) => { setFormLoading(true); setDevopsShiLiId(value); - const { label: name } = devopsShiLiList.find((item) => item.value === value) || {}; + const { label: name } = envList.find((item) => item.value === value) || {}; API.getDevopsUrl({ shiliId: value }) .then(({ data = {} }) => { const { portalfront: url, loginUrl, username, password } = data; @@ -172,11 +186,11 @@ export default function VersionModal(props: IProps) { const devopsShiLiIdDeleted = isEdit && - devopsShiLiList.length && + envList.length && devopsShiLiId && - !devopsShiLiList.map((item) => item.value).includes(devopsShiLiId); + !envList.map((item) => item.value).includes(devopsShiLiId); const validateStatus = devopsShiLiIdDeleted ? 'error' : ''; - const help = devopsShiLiIdDeleted ? '当前绑定的 devops 实例已被删除' : ''; + const help = devopsShiLiIdDeleted ? '当前绑定环境已被删除' : ''; return (