Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:fix: 修复分析方案代码库切换 #69

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/packages/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"react-i18next": "^11.17.3",
"react-redux": "^7.2.5",
"react-router-dom": "^5.3.0",
"tdesign-react": "0.36.4",
"tdesign-react": "0.42.3",
"universal-cookie": "^4.0.4"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"react-router-dom": "^5.3.0",
"react-copy-to-clipboard": "^5.0.4",
"react-i18next": "^11.17.3",
"tdesign-react": "0.36.4",
"tdesign-react": "0.42.3",
"typescript": "^4.5.5"
}
}
38 changes: 38 additions & 0 deletions web/packages/shared/tca/util/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* 获取代码库地址 path
* @param scmUrl scm url
* @returns path
*/
export const getScmUrlPath = (scmUrl: string) => {
// 处理 ssh http 格式 scm url
const path = scmUrl.replace(/(^https?:\/\/[^/]*\/)|(^git@[^:]*:([0-9]*\/)?)/, '');
return path;
};

interface GetRepoNameParams {
/** 是否仅使用代码库尾部作为name,否则将代码库path作为name */
onlyLastName: boolean
}

/**
* 获取代码库展示名称
* @param repoInfo 代码库信息,可传入{name, url, scmUrl, scm_url},默认存在name直接显示,否则会格式化处理
* @param params 参数项
* @returns repoName
*/
export const getRepoName = (repoInfo: any, params: GetRepoNameParams = { onlyLastName: false }) => {
const info = repoInfo || {};
const { name, url, scmUrl } = info;
if (name) {
return name;
}
const repoUrl = url || scmUrl || info.scm_url;
if (repoUrl) {
if (params.onlyLastName) {
return repoUrl.substring(0, repoUrl.lastIndexOf('/') + 1);
}
return getScmUrlPath(repoUrl);
}
return '';
};

8 changes: 4 additions & 4 deletions web/packages/tca-analysis/src/components/repos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import CaretDown from 'coding-oa-uikit/lib/icon/CaretDown';
import LinkIcon from 'coding-oa-uikit/lib/icon/Link';
import ConfigIcon from 'coding-oa-uikit/lib/icon/Cog';

import { getRepoName } from '@tencent/micro-frontend-shared/tca/util';
import { getRepos } from '@src/services/common';
import { getRepoName } from '@src/utils';
import { getReposRouter } from '@src/utils/getRoutePath';
import { useStateStore, useDispatchStore } from '@src/context/store';
import { SET_CUR_REPO } from '@src/context/constant';
Expand Down Expand Up @@ -101,7 +101,7 @@ const Repos = (props: IProps) => {
return repoList.map(item => (
<Menu.Item key={item.id}>
<RepoIcon className={cn(style.gitMark, style.repoListIcon)} />
{item.name || getRepoName(item.scm_url)}
{getRepoName(item)}
</Menu.Item>
));
};
Expand Down Expand Up @@ -132,12 +132,12 @@ const Repos = (props: IProps) => {
}>
<div className={style.curRepo}>
<RepoIcon className={style.gitMark} />
<span className={style.repoUrl}>{curRepo.scm_url}</span>
<span className={style.repoUrl}>{getRepoName(curRepo)}</span>
<CaretDown className={style.icon} />
</div>
</Dropdown>
{/* <Copy text={curRepo.scm_url} className={style.copyIcon} /> */}
<Tooltip title='跳转代码库'>
<Tooltip title={<div style={{ wordBreak: 'break-all' }}>跳转代码库: {curRepo.scm_url}</div>}>
<a className={style.repoLink} target="_blank" href={curRepo.scm_url} rel="noreferrer">
<LinkIcon />
</a>
Expand Down
4 changes: 2 additions & 2 deletions web/packages/tca-analysis/src/modules/repos/create-repo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { Modal, Form, Input, Select, message } from 'coding-oa-uikit';

import AuthFormItem from '@tencent/micro-frontend-shared/tca/user-auth/auth-form-item';
import { AuthTypeEnum, SCM_MAP } from '@tencent/micro-frontend-shared/tca/user-auth/constant';
import { getRepoName } from '@tencent/micro-frontend-shared/tca/util';
import { userAuthAPI } from '@plat/api';
// import Authority from '@src/components/authority';
// import { SCM_MAP } from '@src/components/authority/constants';
import { postRepo } from '@src/services/repos';
import { getRepos } from '@src/services/common';
import { getAnalysisBaseRouter, getUserAuthBlankRouter } from '@src/utils/getRoutePath';
import { RestfulListAPIParams } from '@src/types';
import { getRepoName } from '@src/utils';
import { REPO_TYPE } from './constant';

const { Option } = Select;
Expand All @@ -37,7 +37,7 @@ const CreateRepo = (props: CreateRepoProps) => {
const url = form.getFieldValue('scm_url');
if (url) {
form.setFieldsValue({
name: getRepoName(url),
name: getRepoName({ url }),
});
}
};
Expand Down
6 changes: 3 additions & 3 deletions web/packages/tca-analysis/src/modules/repos/edit-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
import React, { useEffect, useState } from 'react';
import { Modal, Form, Input, Space, Button, message } from 'coding-oa-uikit';
import { getRepoName } from '@tencent/micro-frontend-shared/tca/util';
import { useLoginUserIsAdmin } from '@plat/hooks';
import { getRepoName } from '@src/utils';
import { putRepo, getRepoMembers, delRepo } from '@src/services/repos';

interface EditModalProps {
Expand Down Expand Up @@ -46,7 +46,7 @@ const EditModal = (props: EditModalProps) => {

const onDel = () => {
Modal.confirm({
title: `是否确认删除代码库【${repoInfo.name || getRepoName(repoInfo.scm_url)}】?`,
title: `是否确认删除代码库【${getRepoName(repoInfo)}】?`,
onOk() {
delRepo(orgSid, teamName, repoInfo.id).then(() => {
message.success('已删除代码库');
Expand Down Expand Up @@ -79,7 +79,7 @@ const EditModal = (props: EditModalProps) => {
layout="vertical"
initialValues={repoInfo && {
...repoInfo,
name: repoInfo.name || getRepoName(repoInfo.scm_url),
name: getRepoName(repoInfo),
}}
>
<Form.Item
Expand Down
7 changes: 4 additions & 3 deletions web/packages/tca-analysis/src/modules/repos/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import MemberSettingsIcon from 'coding-oa-uikit/lib/icon/MemberSettings';
import ClockIcon from 'coding-oa-uikit/lib/icon/Clock';
import AlignLeftIcon from 'coding-oa-uikit/lib/icon/AlignLeft';

import { formatDateTime } from '@tencent/micro-frontend-shared/util';
import { getRepoName } from '@tencent/micro-frontend-shared/tca/util';
import { putRepo } from '@src/services/repos';
// import { subscribedRepo, cancelSubscribedRepo, putRepo } from '@src/services/repos';
import { formatDateTime, getRepoName } from '@src/utils';
import { getProjectRouter } from '@src/utils/getRoutePath';

import MemberConfig from './member-config';
Expand Down Expand Up @@ -131,7 +132,7 @@ const RepoList = (props: RepoListProps) => {
<Highlighter
searchWords={[searchWords]}
autoEscape={true}
textToHighlight={name || getRepoName(data.scm_url)}
textToHighlight={getRepoName(data)}
/>
</Link>
{/* todo: 待接口完善 */}
Expand Down Expand Up @@ -167,7 +168,7 @@ const RepoList = (props: RepoListProps) => {
<div>
<Input
size='small'
defaultValue={name || getRepoName(data.scm_url)}
defaultValue={getRepoName(data)}
onChange={e => setName(e.target.value)}
/>
<div style={{
Expand Down
5 changes: 3 additions & 2 deletions web/packages/tca-analysis/src/modules/repos/repo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import ClockIcon from 'coding-oa-uikit/lib/icon/Clock';
import AlignLeftIcon from 'coding-oa-uikit/lib/icon/AlignLeft';
import MemberSettingsIcon from 'coding-oa-uikit/lib/icon/MemberSettings';

import { formatDateTime } from '@tencent/micro-frontend-shared/util';
import { getRepoName } from '@tencent/micro-frontend-shared/tca/util';
import { getRepo, putRepo } from '@src/services/repos';
import { getProjectRouter, getReposRouter } from '@src/utils/getRoutePath';
import { formatDateTime, getRepoName } from '@src/utils';
import { CLOSE_REPO_MEMBER_CONF } from '@plat/modules';

import MemberConfig from '../member-config';
Expand Down Expand Up @@ -44,7 +45,7 @@ const Repo = () => {
loading: false,
repoInfo,
});
setName(repoInfo.name || getRepoName(repoInfo.scm_url));
setName(getRepoName(repoInfo));
}, [orgSid, teamName, repoId]);

useEffect(() => {
Expand Down
22 changes: 7 additions & 15 deletions web/packages/tca-analysis/src/modules/schemes/baseinfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from 'coding-oa-uikit';
import EllipsisH from 'coding-oa-uikit/lib/icon/EllipsisH';

import { updateSchemeBasic, getLintConfig, updateLintConfig } from '@src/services/schemes';
import { updateSchemeBasic, updateLintConfig } from '@src/services/schemes';
import NodeTag from '@src/components/node-tag';

import style from './style.scss';
Expand All @@ -41,24 +41,18 @@ interface BaseConfigProps {
tags: any[];
languages: any[];
data: any;
lintConf: any; // 环境变量初始值
callback?: (data: any) => void;
}

const BaseConfig = (props: BaseConfigProps) => {
const { orgSid, teamName, data, repoId, tags, languages, callback } = props;
const { orgSid, teamName, data, repoId, tags, languages, lintConf, callback } = props;
const [form] = Form.useForm();
const [visible, setVisible] = useState(false);
const [isDefault, setDefault] = useState(true);
const [lintConfig, setLintConfig] = useState<any>({});
const schemeId = data.id;

useEffect(() => {
if (schemeId) {
getLintConfig(orgSid, teamName, repoId, data.id).then(res => setLintConfig(res));
}
}, [schemeId]);

useEffect(() => form.resetFields(), [schemeId, lintConfig.envs]);
useEffect(() => form.resetFields(), [schemeId, lintConf]);

// todo: remove
const openModal = ({ key }: { key: string }) => {
Expand All @@ -76,12 +70,10 @@ const BaseConfig = (props: BaseConfigProps) => {
callback?.(response);
});

if (formData.envs !== lintConfig.envs) {
if (formData.envs !== lintConf.envs) {
updateLintConfig(orgSid, teamName, repoId, schemeId, {
...lintConfig,
...lintConf,
envs: formData.envs,
}).then((res) => {
setLintConfig(res);
});
}
};
Expand All @@ -104,7 +96,7 @@ const BaseConfig = (props: BaseConfigProps) => {
<Form
labelAlign="left"
className={cn(style.baseConfig, formStyle.schemeFormVertical)}
initialValues={{ ...data, envs: lintConfig.envs }}
initialValues={{ ...data, envs: lintConf.envs }}
form={form}
onFinish={onFinish}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import AngleRight from 'coding-oa-uikit/lib/icon/AngleRight';

import Loading from '@src/components/loading';
import {
getLintConfig,
updateLintConfig,
getCheckPackages,
getLabels,
Expand All @@ -43,17 +42,17 @@ interface CodeLintProps {
schemeId: string | number;
languages: any;
schemeInfo: any;
data: any;
callback?: (data: any) => void;
}

const CodeLint = (props: CodeLintProps) => {
const { orgSid, teamName, repoId, schemeId, languages, schemeInfo } = props;
const { orgSid, teamName, repoId, schemeId, languages, schemeInfo, data, callback } = props;
const history = useHistory();

const [visible, setVisible] = useState(false);
const [selectedPkgs, setSelectedPkgs] = useState<any>([]);
const [customPackage, setCustomPackage] = useState<any>({});
const [data, setData] = useState<any>({});
const [labels, setLabels] = useState([]);
const [allPkgs, setAllPkgs] = useState([]);
const [loading, setLoading] = useState(true);
Expand All @@ -78,7 +77,6 @@ const CodeLint = (props: CodeLintProps) => {
}, []);

useEffect(() => {
(async () => schemeId && setData(await getLintConfig(orgSid, teamName, repoId, schemeId)))();
setSearchParams({});
}, [schemeId]);

Expand Down Expand Up @@ -109,7 +107,7 @@ const CodeLint = (props: CodeLintProps) => {
...data,
...params,
}).then((res) => {
setData(res);
callback(res);
});

const getList = async () => {
Expand Down
Loading