Skip to content

Commit

Permalink
feat: add i18n and dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Feb 13, 2024
1 parent 3ddca81 commit 24c1c8d
Show file tree
Hide file tree
Showing 18 changed files with 533 additions and 185 deletions.
3 changes: 3 additions & 0 deletions packages/canyon-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nestjs/platform-express": "^10.3.0",
"@nestjs/schedule": "^4.0.0",
"@nestjs/serve-static": "^4.0.0",
"adm-zip": "^0.5.10",
"axios": "^1.6.5",
"body-parser": "^1.20.2",
"class-transformer": "^0.5.1",
Expand All @@ -47,7 +48,9 @@
"graphql-query-complexity": "^0.12.0",
"graphql-subscriptions": "^2.0.0",
"istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^4.0.1",
"istanbul-reports": "^3.1.6",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"prisma": "5.8.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/canyon-backend/src/coverage/coverage.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import {
Post,
Query,
Request,
Res,
UseGuards,
} from '@nestjs/common';
import type { Response } from 'express';
// import { AppService } from './app.service';
import { CoverageClientService } from './services/coverage-client.service';
// import { RetrieveCoverageSummaryService } from './services/retrieve-coverage-summary.service';
Expand All @@ -15,6 +17,9 @@ import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { CoverageService } from './services/coverage.service';
// import { query } from 'express';
import { RetrieveCoverageTreeSummaryService } from './services/retrieve-coverage-tree-summary.service';
import { getSpecificCoverageData } from '../adapter/coverage-data.adapter';
import { join } from 'path';
import {download} from "../utils/download";
// import * as platform from 'platform'
// export function getPlatformInfo(str) {
// return platform.parse(str)
Expand Down Expand Up @@ -116,4 +121,21 @@ export class CoverageController {
reportID: 'reportID',
};
}

// 下载istanbul覆盖率报告文件 参数reportID、commitSha、
@Get('/api/coverage/download')
async downloadCoverageReport(
@Query()
params: {
relationID: string;
instrumentCmd: string;
},
@Res() res: Response,
) {
const coverageMapData = await getSpecificCoverageData(params.relationID);
await download(params.instrumentCmd, coverageMapData);

const url = join(__dirname, '../../public', 'coverage.zip');
res.download(url);
}
}
29 changes: 29 additions & 0 deletions packages/canyon-backend/src/utils/download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as path from 'path';
import { createCoverageMap } from 'istanbul-lib-coverage';

import * as libReport from 'istanbul-lib-report';

import * as reports from 'istanbul-reports';

import * as AdmZip from 'adm-zip';
export async function download(instrumentCmd, coverageMapData) {
const obj = {};
for (const objKey in coverageMapData) {
obj[objKey.replace('~', instrumentCmd)] = {
...coverageMapData[objKey],
path: objKey.replace('~', instrumentCmd),
};
}
const coverageMap = createCoverageMap(obj);

const context = libReport.createContext({
dir: path.join(__dirname, '../../public/coverage'),
defaultSummarizer: 'nested',
coverageMap,
});
const report = reports.create('html', {});
report.execute(context);
const zip = new AdmZip();
zip.addLocalFolder(path.join(__dirname, '../../public/coverage'));
zip.writeZip(path.join(__dirname, '../../public/coverage.zip'));
}
106 changes: 89 additions & 17 deletions packages/canyon-platform/locales/cn.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,103 @@
{
"welcome": {
"hello": "你好,",
"copywriter": "欢迎来到Canyon。",
"desc": "您将被重定向到源代码控制管理系统进行身份验证。",
"continue": "继续"
},
"menus": {
"projects": "项目",
"settings": "设置",
"docs": "文档"
},
"projects": {
"create": "创建项目",
"desc": "查看与您的账户相关的所有项目",
"table": {
"name": "名称",
"description": "描述",
"created_at": "创建时间",
"updated_at": "更新时间",
"option": "操作",
"delete": "删除",
"detail": "详情"
},
"name": "名称",
"report_times": "上报次数",
"max_coverage": "最大覆盖率",
"latest_report_time": "最近上报时间",
"latest_report_coverage": "最近上报覆盖率",
"no_data": "{{msg}}个项目没数据",
"trends_in_coverage": "覆盖率趋势",
"record": "记录",
"overview": "概览"
"overview": "概览",
"branch": "分支",
"compare_target": "对比目标",
"message": "提交信息",
"functions": "函数",
"branches": "分支",
"statements": "语句",
"lines": "",
"newlines": "新增行",
"reported_details": "上报细节",
"reporter": "上报人",
"search_keywords": "搜索关键字",
"overview_search_keywords": "搜索关键字"
},
"settings": {
"desc": "设置您的账户信息",
"form": {
"name": "名称",
"email": "邮箱",
"password": "密码",
"password_confirmation": "确认密码",
"submit": "提交"
}
"user_auth_tokens": "用户授权令牌",
"copied_to_clipboard": "已复制到剪贴板"
},
"common": {
"option": "操作",
"detail": "详情",
"delete": "删除",
"language": "语言",
"confirm": "确认",
"cancel": "取消",
"copy": "复制",
"search": "搜索",
"no_data": "暂无数据",
"no_result": "暂无结果",
"created_at": "创建时间"
},
"app": {
"logout": "退出登录",
"welcome_copywriter": "欢迎",
"name": "名称",
"version": "版本",
"desc": "描述",
"latest_report_time": "最近上报时间",
"report_times": "上报次数",
"max_coverage": "最大覆盖率",
"record": "记录",
"overview": "概览",
"report": "上报",
"report_time": "上报时间",
"coverage": "覆盖率",
"line": "",
"branch": "分支",
"function": "函数",
"statement": "语句",
"report_detail": "上报详情",
"report_files": "上报文件",
"file_path": "文件路径",
"file_name": "文件名",
"file_detail": "文件详情",
"file_report_times": "上报次数",
"file_max_coverage": "最大覆盖率",
"file_latest_report_time": "最近上报时间",
"file_record": "文件记录",
"file_overview": "文件概览",
"file_report": "文件上报",
"file_report_time": "文件上报时间",
"file_coverage": "文件覆盖率",
"file_line": "文件行",
"file_branch": "文件分支",
"file_function": "文件函数",
"file_statement": "文件语句",
"file_report_detail": "文件上报详情",
"file_report_files": "文件上报文件",
"file_file_path": "文件文件路径",
"file_file_name": "文件文件名",
"file_file_coverage": "文件覆盖率",
"file_file_line": "文件行",
"file_file_branch": "文件分支",
"file_file_function": "文件函数",
"file_file_statement": "文件语句",
"file_file_detail": "文件文件详情",
"file_file_report_times": "文件上报次数"
}
}
28 changes: 0 additions & 28 deletions packages/canyon-platform/locales/ko.json

This file was deleted.

28 changes: 0 additions & 28 deletions packages/canyon-platform/locales/tw.json

This file was deleted.

6 changes: 4 additions & 2 deletions packages/canyon-platform/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { ConfigProvider } from 'antd';
import { ConfigProvider, theme } from 'antd';
import { useRoutes } from 'react-router-dom';

import routes from '~react-pages';

const { darkAlgorithm } = theme;
const App = () => {
const isDark = localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : false;
return (
<ConfigProvider
theme={{
token: {
colorPrimary: '#287DFA',
},
algorithm: isDark ? [darkAlgorithm] : [],
}}
>
{useRoutes(routes)}
Expand Down
15 changes: 8 additions & 7 deletions packages/canyon-platform/src/components/app/project/nodata.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useQuery } from '@apollo/client';
import { Button, Modal, Table, Tooltip } from 'antd';
import { Button, Modal, Table, theme, Tooltip } from 'antd';
import dayjs from 'dayjs';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';

import { GetProjectsNoDataDocument } from '../../../helpers/backend/gen/graphql.ts';

const { useToken } = theme;
const ProjectNoData: React.FC = () => {
const { token } = useToken();
const { t } = useTranslation();
const { data, loading } = useQuery(GetProjectsNoDataDocument, {
fetchPolicy: 'no-cache',
Expand All @@ -30,13 +31,13 @@ const ProjectNoData: React.FC = () => {
{data?.getProjectsNoData?.length && (
<Tooltip title={'View Details'}>
<Button type={'link'} onClick={showModal}>
{`${data?.getProjectsNoData?.length || 0} projects no data`}
{t('projects.no_data', { msg: data?.getProjectsNoData?.length || 0 })}
</Button>
</Tooltip>
)}

<Modal
title={`${data?.getProjectsNoData?.length} projects no data`}
title={t('projects.no_data', { msg: data?.getProjectsNoData?.length || 0 })}
open={isModalOpen}
onOk={handleOk}
onCancel={handleCancel}
Expand All @@ -46,7 +47,7 @@ const ProjectNoData: React.FC = () => {
<Table
loading={loading}
size={'small'}
style={{ border: '1px solid #f0f0f0', background: 'white', borderRadius: '4px' }}
style={{ border: `1px solid ${token.colorBorder}`, borderRadius: '4px' }}
dataSource={data?.getProjectsNoData || []}
columns={[
{
Expand All @@ -55,7 +56,7 @@ const ProjectNoData: React.FC = () => {
key: 'id',
},
{
title: t('projects.table.name'),
title: t('projects.name'),
dataIndex: 'pathWithNamespace',
key: 'pathWithNamespace',
},
Expand All @@ -64,7 +65,7 @@ const ProjectNoData: React.FC = () => {
dataIndex: 'bu',
},
{
title: 'Created At',
title: t('common.created_at'),
dataIndex: 'createdAt',
render: (text: string) => dayjs(text).format('MM-DD HH:mm'),
},
Expand Down
12 changes: 3 additions & 9 deletions packages/canyon-platform/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { initReactI18next } from 'react-i18next';
import cn from '../locales/cn.json';
import en from '../locales/en.json';
import ja from '../locales/ja.json';
import ko from '../locales/ko.json';
import tw from '../locales/tw.json';
// import ko from '../locales/ko.json';
// import tw from '../locales/tw.json';
// const getIos = (code: string, languages: { code: string; iso: string }[]) =>
// languages.find((item: { code: string }) => item.code === code)?.iso || 'en-US';
i18n
Expand All @@ -31,17 +31,11 @@ i18n
cn: {
translation: cn,
},
tw: {
translation: tw,
},
ja: {
translation: ja,
},
ko: {
translation: ko,
},
},
lng: 'en' || localStorage.getItem('language') || navigator.language,
lng: localStorage.getItem('language') || navigator.language,
});

export default i18n;
Loading

0 comments on commit 24c1c8d

Please sign in to comment.