| @@ -1,6 +1,7 @@ | |||||
| import KFEmpty, { EmptyType } from '@/components/KFEmpty'; | import KFEmpty, { EmptyType } from '@/components/KFEmpty'; | ||||
| import KFIcon from '@/components/KFIcon'; | import KFIcon from '@/components/KFIcon'; | ||||
| import { deleteCodeConfigReq, getCodeConfigListReq } from '@/services/codeConfig'; | import { deleteCodeConfigReq, getCodeConfigListReq } from '@/services/codeConfig'; | ||||
| import { getGitUrl } from '@/utils'; | |||||
| import { openAntdModal } from '@/utils/modal'; | import { openAntdModal } from '@/utils/modal'; | ||||
| import { to } from '@/utils/promise'; | import { to } from '@/utils/promise'; | ||||
| import { modalConfirm } from '@/utils/ui'; | 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 createCodeConfig = () => { | ||||
| const { close } = openAntdModal(AddCodeConfigModal, { | const { close } = openAntdModal(AddCodeConfigModal, { | ||||
| @@ -152,6 +160,7 @@ function CodeConfigList() { | |||||
| key={item.id} | key={item.id} | ||||
| onRemove={handleRemove} | onRemove={handleRemove} | ||||
| onEdit={handleEdit} | onEdit={handleEdit} | ||||
| onClick={handleClick} | |||||
| /> | /> | ||||
| ))} | ))} | ||||
| </div> | </div> | ||||
| @@ -9,6 +9,7 @@ import { | |||||
| ResourceType, | ResourceType, | ||||
| TrainTask, | TrainTask, | ||||
| } from '@/pages/Dataset/config'; | } from '@/pages/Dataset/config'; | ||||
| import { getGitUrl } from '@/utils'; | |||||
| import styles from './index.less'; | import styles from './index.less'; | ||||
| type ResourceIntroProps = { | type ResourceIntroProps = { | ||||
| @@ -54,9 +55,7 @@ const getProjectUrl = (project?: ProjectDependency) => { | |||||
| return undefined; | return undefined; | ||||
| } | } | ||||
| const { url, branch } = project; | 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) => { | const formatProject = (project?: ProjectDependency) => { | ||||
| @@ -1,4 +1,5 @@ | |||||
| import { ResourceInfoTabKeys } from '@/pages/Dataset/components/ResourceInfo'; | import { ResourceInfoTabKeys } from '@/pages/Dataset/components/ResourceInfo'; | ||||
| import { getGitUrl } from '@/utils'; | |||||
| import { formatDate } from '@/utils/date'; | import { formatDate } from '@/utils/date'; | ||||
| import { useNavigate } from '@umijs/max'; | import { useNavigate } from '@umijs/max'; | ||||
| import { ModelDepsData, NodeType, ProjectDependency, TrainDataset } from '../ModelEvolution/utils'; | import { ModelDepsData, NodeType, ProjectDependency, TrainDataset } from '../ModelEvolution/utils'; | ||||
| @@ -127,10 +128,7 @@ function DatasetInfo({ data }: { data: TrainDataset }) { | |||||
| function ProjectInfo({ data }: { data: ProjectDependency }) { | function ProjectInfo({ data }: { data: ProjectDependency }) { | ||||
| const gotoProjectPage = () => { | const gotoProjectPage = () => { | ||||
| const { url, branch } = data; | 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'); | window.open(projectUrl, '_blank'); | ||||
| }; | }; | ||||
| @@ -1,6 +1,7 @@ | |||||
| import LabelValue from '@/components/LabelValue'; | import LabelValue from '@/components/LabelValue'; | ||||
| import { useComputingResource } from '@/hooks/resource'; | import { useComputingResource } from '@/hooks/resource'; | ||||
| import { ServiceVersionData } from '@/pages/ModelDeployment/types'; | import { ServiceVersionData } from '@/pages/ModelDeployment/types'; | ||||
| import { getGitUrl } from '@/utils'; | |||||
| import { formatDate } from '@/utils/date'; | import { formatDate } from '@/utils/date'; | ||||
| import { Link } from '@umijs/max'; | import { Link } from '@umijs/max'; | ||||
| import { Col, Row } from 'antd'; | import { Col, Row } from 'antd'; | ||||
| @@ -27,7 +28,8 @@ function BasicInfo({ info }: BasicInfoProps) { | |||||
| const formatCodeConfig = () => { | const formatCodeConfig = () => { | ||||
| if (info && info.code_config) { | 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 ( | return ( | ||||
| <a href={url} target="_blank" rel="noreferrer"> | <a href={url} target="_blank" rel="noreferrer"> | ||||
| {info?.code_config?.show_value} | {info?.code_config?.show_value} | ||||
| @@ -31,7 +31,7 @@ export function parseJsonText(text?: string | null): any | null { | |||||
| } | } | ||||
| } | } | ||||
| // 判断是否为对象 | |||||
| // 判断是否为一般对象 | |||||
| function isPlainObject(value: any) { | function isPlainObject(value: any) { | ||||
| if (value === null || typeof value !== 'object') return false; | if (value === null || typeof value !== 'object') return false; | ||||
| let proto = Object.getPrototypeOf(value); | let proto = Object.getPrototypeOf(value); | ||||
| @@ -160,13 +160,13 @@ export function changePropertyName(obj: Record<string, any>, mapping: Record<str | |||||
| } | } | ||||
| /** | /** | ||||
| * 计算显示的字符串 | |||||
| * @param tr 要裁剪的字符串 | |||||
| * @param maxWidth 最大宽度 | |||||
| * @param fontSize 字体大小 | |||||
| * @return 处理后的字符串 | |||||
| * 计算能显示的字符串 | |||||
| * @param {string} str 要裁剪的字符串 | |||||
| * @param {number} maxWidth 最大宽度 | |||||
| * @param {number} fontSize 字体大小 | |||||
| * @return {string} 处理后的字符串 | |||||
| */ | */ | ||||
| export const fittingString = (str: string, maxWidth: number, fontSize: number) => { | |||||
| export const fittingString = (str: string, maxWidth: number, fontSize: number): string => { | |||||
| if (!str) { | if (!str) { | ||||
| return ''; | return ''; | ||||
| } | } | ||||
| @@ -200,3 +200,24 @@ export const fittingString = (str: string, maxWidth: number, fontSize: number) = | |||||
| export const isEmptyString = (str: any): boolean => { | export const isEmptyString = (str: any): boolean => { | ||||
| return str === '' || str === undefined || str === null; | 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; | |||||
| }; | |||||