From ef4893ea353a30f1bbcb55d811637158fc237248 Mon Sep 17 00:00:00 2001 From: cp3hnu Date: Fri, 11 Oct 2024 14:00:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E7=A0=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E7=82=B9=E5=87=BB=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- react-ui/src/pages/CodeConfig/List/index.tsx | 9 +++++ .../components/ResourceIntro/index.tsx | 5 ++- .../Model/components/NodeTooltips/index.tsx | 6 ++-- .../components/BasicInfo/index.tsx | 4 ++- react-ui/src/utils/index.ts | 35 +++++++++++++++---- 5 files changed, 44 insertions(+), 15 deletions(-) diff --git a/react-ui/src/pages/CodeConfig/List/index.tsx b/react-ui/src/pages/CodeConfig/List/index.tsx index b61e9016..847d30ec 100644 --- a/react-ui/src/pages/CodeConfig/List/index.tsx +++ b/react-ui/src/pages/CodeConfig/List/index.tsx @@ -1,6 +1,7 @@ import KFEmpty, { EmptyType } from '@/components/KFEmpty'; import KFIcon from '@/components/KFIcon'; import { deleteCodeConfigReq, getCodeConfigListReq } from '@/services/codeConfig'; +import { getGitUrl } from '@/utils'; import { openAntdModal } from '@/utils/modal'; import { to } from '@/utils/promise'; import { modalConfirm } from '@/utils/ui'; @@ -99,6 +100,13 @@ function CodeConfigList() { }); }; + // 查看 + const handleClick = (record: CodeConfigData) => { + const { git_url, git_branch } = record; + const url = getGitUrl(git_url, git_branch); + window.open(url, '_blank'); + }; + // 新建 const createCodeConfig = () => { const { close } = openAntdModal(AddCodeConfigModal, { @@ -152,6 +160,7 @@ function CodeConfigList() { key={item.id} onRemove={handleRemove} onEdit={handleEdit} + onClick={handleClick} /> ))} diff --git a/react-ui/src/pages/Dataset/components/ResourceIntro/index.tsx b/react-ui/src/pages/Dataset/components/ResourceIntro/index.tsx index 21907f63..2ee7fb24 100644 --- a/react-ui/src/pages/Dataset/components/ResourceIntro/index.tsx +++ b/react-ui/src/pages/Dataset/components/ResourceIntro/index.tsx @@ -9,6 +9,7 @@ import { ResourceType, TrainTask, } from '@/pages/Dataset/config'; +import { getGitUrl } from '@/utils'; import styles from './index.less'; type ResourceIntroProps = { @@ -54,9 +55,7 @@ const getProjectUrl = (project?: ProjectDependency) => { return undefined; } const { url, branch } = project; - if (url.endsWith('.git')) { - return `${url.substring(0, url.length - 4)}/tree/${branch}`; - } + return getGitUrl(url, branch); }; const formatProject = (project?: ProjectDependency) => { diff --git a/react-ui/src/pages/Model/components/NodeTooltips/index.tsx b/react-ui/src/pages/Model/components/NodeTooltips/index.tsx index b868de23..8a0f055e 100644 --- a/react-ui/src/pages/Model/components/NodeTooltips/index.tsx +++ b/react-ui/src/pages/Model/components/NodeTooltips/index.tsx @@ -1,4 +1,5 @@ import { ResourceInfoTabKeys } from '@/pages/Dataset/components/ResourceInfo'; +import { getGitUrl } from '@/utils'; import { formatDate } from '@/utils/date'; import { useNavigate } from '@umijs/max'; import { ModelDepsData, NodeType, ProjectDependency, TrainDataset } from '../ModelEvolution/utils'; @@ -127,10 +128,7 @@ function DatasetInfo({ data }: { data: TrainDataset }) { function ProjectInfo({ data }: { data: ProjectDependency }) { const gotoProjectPage = () => { const { url, branch } = data; - let projectUrl = url; - if (url.endsWith('.git')) { - projectUrl = `${url.substring(0, url.length - 4)}/tree/${branch}`; - } + const projectUrl = getGitUrl(url, branch); window.open(projectUrl, '_blank'); }; diff --git a/react-ui/src/pages/ModelDeployment/components/BasicInfo/index.tsx b/react-ui/src/pages/ModelDeployment/components/BasicInfo/index.tsx index 2ade95a0..f741f750 100644 --- a/react-ui/src/pages/ModelDeployment/components/BasicInfo/index.tsx +++ b/react-ui/src/pages/ModelDeployment/components/BasicInfo/index.tsx @@ -1,6 +1,7 @@ import LabelValue from '@/components/LabelValue'; import { useComputingResource } from '@/hooks/resource'; import { ServiceVersionData } from '@/pages/ModelDeployment/types'; +import { getGitUrl } from '@/utils'; import { formatDate } from '@/utils/date'; import { Link } from '@umijs/max'; import { Col, Row } from 'antd'; @@ -27,7 +28,8 @@ function BasicInfo({ info }: BasicInfoProps) { const formatCodeConfig = () => { if (info && info.code_config) { - const url = `${info.code_config.code_path}/tree/${info.code_config.branch}`; + const { code_path, branch } = info.code_config; + const url = getGitUrl(code_path, branch); return ( {info?.code_config?.show_value} diff --git a/react-ui/src/utils/index.ts b/react-ui/src/utils/index.ts index 8ef057ba..4938e2ca 100644 --- a/react-ui/src/utils/index.ts +++ b/react-ui/src/utils/index.ts @@ -31,7 +31,7 @@ export function parseJsonText(text?: string | null): any | null { } } -// 判断是否为对象 +// 判断是否为一般对象 function isPlainObject(value: any) { if (value === null || typeof value !== 'object') return false; let proto = Object.getPrototypeOf(value); @@ -160,13 +160,13 @@ export function changePropertyName(obj: Record, mapping: Record { +export const fittingString = (str: string, maxWidth: number, fontSize: number): string => { if (!str) { return ''; } @@ -200,3 +200,24 @@ export const fittingString = (str: string, maxWidth: number, fontSize: number) = export const isEmptyString = (str: any): boolean => { return str === '' || str === undefined || str === null; }; + +/** + * 获取 git 仓库的 url + * + * @param {string} url - the url of the git repository + * @param {string} branch - the branch of the repository + * @return {string} the url of the repository + * + * If `branch` is given, the url will be in the format of 'http://gitlab.com/user/repo/tree/branch'. + * Otherwise, the url will be in the format of 'http://gitlab.com/user/repo'. + */ +export const getGitUrl = (url: string, branch: string): string => { + if (!url) { + return ''; + } + const gitUrl = url.replace(/\.git$/, ''); + if (branch) { + return `${gitUrl}/tree/${branch}`; + } + return gitUrl; +};