Browse Source

feat: 代码配置可以点击跳转

pull/135/head
cp3hnu 1 year ago
parent
commit
ef4893ea35
5 changed files with 44 additions and 15 deletions
  1. +9
    -0
      react-ui/src/pages/CodeConfig/List/index.tsx
  2. +2
    -3
      react-ui/src/pages/Dataset/components/ResourceIntro/index.tsx
  3. +2
    -4
      react-ui/src/pages/Model/components/NodeTooltips/index.tsx
  4. +3
    -1
      react-ui/src/pages/ModelDeployment/components/BasicInfo/index.tsx
  5. +28
    -7
      react-ui/src/utils/index.ts

+ 9
- 0
react-ui/src/pages/CodeConfig/List/index.tsx View File

@@ -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}
/>
))}
</div>


+ 2
- 3
react-ui/src/pages/Dataset/components/ResourceIntro/index.tsx View File

@@ -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) => {


+ 2
- 4
react-ui/src/pages/Model/components/NodeTooltips/index.tsx View File

@@ -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');
};



+ 3
- 1
react-ui/src/pages/ModelDeployment/components/BasicInfo/index.tsx View File

@@ -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 (
<a href={url} target="_blank" rel="noreferrer">
{info?.code_config?.show_value}


+ 28
- 7
react-ui/src/utils/index.ts View File

@@ -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<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) {
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;
};

Loading…
Cancel
Save