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

feat: layout模块调整 #46

Merged
merged 1 commit into from
Aug 30, 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
22 changes: 19 additions & 3 deletions web/packages/shared/component/authority/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ import { AUTH_TYPE, AUTH_TYPE_TXT, SCM_MAP, SCM_PLATFORM_CHOICES } from './const
import { FormInstance } from 'rc-field-form';
const { Option, OptGroup } = Select;

export interface RestfulListAPIParams {
results: any[];
count: number;
next: string;
previous: string
}

interface AuthorityProps {
name: string; // 对应表单 name
form: FormInstance; // form 对象
label: string | React.ReactNode; // FormItem label
getAuthList: Array<Promise<any>>;
/* 接口顺序:获取ssh凭证,获取用户名密码凭证,获取各平台OAuth授权状态,获取各平台OAuth应用配置状态 **/
getAuthList: Array<(param?: any) => Promise<any>>;
initAuth?: any;
selectStyle?: any;
placeholder?: string;
Expand Down Expand Up @@ -55,7 +63,15 @@ const Authority = (props: AuthorityProps) => {

const getAuth = () => {
setAuthLoading(true);
Promise.all(getAuthList).then((result: any) => {
Promise.all([
getAuthList[0]({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
getAuthList[1]({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
getAuthList[2]()
.then(({ results }: RestfulListAPIParams) => results || []),
getAuthList[3]().then(r => r || {}),
]).then((result: any) => {
const activeOauth = filter(
result[2].map((item: any) => ({
...item,
Expand Down Expand Up @@ -134,7 +150,7 @@ const Authority = (props: AuthorityProps) => {
</Form.Item>
<div style={{
position: 'absolute',
top: 5,
top: 0,
right: 10,
}}>
<Tooltip title='新增凭证' placement='top' getPopupContainer={() => document.body}>
Expand Down
3 changes: 1 addition & 2 deletions web/packages/tca-layout/src/constant/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const TASK_STATE_CHOICES = {

export const getNodeSearchFields = (tagOptions: any[]): SearchFormField[] => [{
name: 'name',
label: '名称',
type: 'string',
formType: 'input',
placeholder: '节点名称',
Expand All @@ -77,7 +76,7 @@ export const getNodeSearchFields = (tagOptions: any[]): SearchFormField[] => [{
placeholder: '负责人',
}, {
name: 'exec_tags',
label: '标签',
label: '所属标签',
type: 'string',
formType: 'select',
placeholder: '全部',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ const Profile = () => {
};

const onFinish = (values: any) => {
const params = {
...userinfo,
...pick(values, ['nickname', 'tel_number']),
};
UserAPI.putLoginUserInfo(params).then((res) => {
const params = pick(values, ['nickname', 'tel_number']);
UserAPI.putUserInfo(params).then(() => {
message.success('用户信息已更新');
dispatch({
type: SET_USERINFO,
payload: res,
payload: {
...userinfo,
...params,
},
});
onReset();
});
Expand Down
7 changes: 6 additions & 1 deletion web/packages/tca-layout/src/modules/nodes/node-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ const NodeTable = ({ tagOptions }: NodeTableProps) => {
onCancel={() => setNodeTaskVisible(false)}
nodeId={selectNode?.id}
/>
<Search fields={filterFields} searchParams={searchParams} loading={false} />
<Search
style={{ padding: '1px 0px' }}
fields={filterFields}
searchParams={searchParams}
loading={false}
/>
<Table
pagination={{
current: currentPage,
Expand Down
1 change: 1 addition & 0 deletions web/packages/tca-layout/src/modules/team/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const Team = () => {
const onCreateFinish = () => {
setPager(DEFAULT_TEAM_PAGER);
getTeamList(false, DEFAULT_TEAM_PAGER.pageStart, INIT_LOAD_SIZE, {});
setVisible(false);
};

return (
Expand Down
15 changes: 6 additions & 9 deletions web/packages/tca-layout/src/modules/tool-libs/create-libs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const CreateToollibs = (props: CreateToollibsProps) => {
>
<Input.Group compact>
<Form.Item name='scm_type' noStyle>
<Select style={{ width: 70 }}>
<Select style={{ width: '15%' }}>
{REPO_TYPE_OPTIONS.map((item: any, index: number) => (
<Option key={index} value={item.value}>
{item.label}
Expand All @@ -202,7 +202,7 @@ const CreateToollibs = (props: CreateToollibsProps) => {
{ required: true, message: '依赖仓库地址' },
]}
>
<Input style={{ width: 357 }} />
<Input style={{ width: '85%' }} />
</Form.Item>
</Input.Group>
</Form.Item>
Expand All @@ -219,13 +219,10 @@ const CreateToollibs = (props: CreateToollibsProps) => {
</span>
)}
getAuthList={[
UserAPI.authSSH().get({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.authAccount().get({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.getOAuthInfos()
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.getPlatformStatus().then(r => r || {}),
UserAPI.authSSH().get,
UserAPI.authAccount().get,
UserAPI.getOAuthInfos,
UserAPI.getPlatformStatus,
]}
initAuth={detail.scm_auth}
selectStyle={{ width: 360 }}
Expand Down
15 changes: 4 additions & 11 deletions web/packages/tca-layout/src/modules/tool-libs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import React, { useEffect, useState } from 'react';
import { useHistory, useParams } from 'react-router-dom';
import { useSelector } from 'react-redux';
import cn from 'classnames';
import qs from 'qs';
import { omitBy, toNumber, isString, find, get } from 'lodash';
import { omitBy, toNumber, isString, get } from 'lodash';
import { Table, Button, Tag } from 'coding-oa-uikit';
import EditIcon from 'coding-oa-uikit/lib/icon/Edit';
import { useURLSearch, useURLParams } from '@tencent/micro-frontend-shared/hooks';
Expand All @@ -15,7 +16,6 @@ import Search from '@tencent/micro-frontend-shared/component/search';

import { NAMESPACE, UserState } from '@src/store/user';
import { getToolLibs } from '@src/services/tools';
import { getTeamMember } from '@src/services/team';
import { DEFAULT_PAGER, LIB_TYPE, LibTypeEnum, LIB_ENV } from '@src/constant';
import { useStateStore } from '@tencent/micro-frontend-shared/hook-store';

Expand All @@ -29,7 +29,6 @@ export const ToolLibs = () => {
const history = useHistory();
const { orgSid }: any = useParams();
const { userinfo } = useStateStore<UserState>(NAMESPACE);
const [admins, setAdmins] = useState([]);
const [modalData, setModalData] = useState({
visible: false,
libId: null,
Expand All @@ -42,16 +41,10 @@ export const ToolLibs = () => {
const pageSize = toNumber(query.limit) || DEFAULT_PAGER.pageSize;
const pageStart = toNumber(query.offset) || DEFAULT_PAGER.pageStart;
const { searchParams } = useURLParams(filterFields);
const isAdmin = !!find(admins, { username: userinfo?.username }); // 当前用户是否是管理员
const isAdmin = useSelector((state: any) => state.APP)?.isOrgAdminUser ?? false;
const isSuperuser = userinfo?.is_superuser; // 是否为超级管理员
const editable = isAdmin || isSuperuser; // 编辑权限

useEffect(() => {
getTeamMember(orgSid).then((res: any) => {
setAdmins(res.admins || []);
});
}, [orgSid]);

useEffect(() => {
getListData();
}, []);
Expand Down Expand Up @@ -88,7 +81,7 @@ export const ToolLibs = () => {
loading={loading}
searchParams={searchParams}
route={false}
style={{ paddingLeft: 30, paddingRight: 30 }}
style={{ padding: '1px 24px' }}
fields={TOOLLIB_SEARCH_FIELDS}
callback={(params: any) => {
getListData(DEFAULT_PAGER.pageStart, pageSize, params);
Expand Down
15 changes: 6 additions & 9 deletions web/packages/tca-layout/src/modules/tools/create-tool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const CreateToolModal = ({ orgId, visible, onClose }: CreateToolModalProps) => {
>
<Input.Group compact>
<Form.Item name='scm_type' noStyle>
<Select style={{ width: 70 }} options={REPO_TYPE_OPTIONS} />
<Select style={{ width: '15%' }} options={REPO_TYPE_OPTIONS} />
</Form.Item>
<Form.Item
name='scm_url'
Expand All @@ -102,7 +102,7 @@ const CreateToolModal = ({ orgId, visible, onClose }: CreateToolModalProps) => {
{ required: true, message: t('请输入工具仓库地址') },
]}
>
<Input style={{ width: 357 }} />
<Input style={{ width: '85%' }} />
</Form.Item>
</Input.Group>
</Form.Item>
Expand All @@ -111,13 +111,10 @@ const CreateToolModal = ({ orgId, visible, onClose }: CreateToolModalProps) => {
name='scm_auth_id'
label={t('凭证')}
getAuthList={[
UserAPI.authSSH().get({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.authAccount().get({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.getOAuthInfos()
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.getPlatformStatus().then(r => r || {}),
UserAPI.authSSH().get,
UserAPI.authAccount().get,
UserAPI.getOAuthInfos,
UserAPI.getPlatformStatus,
]}
selectStyle={{ width: 360 }}
required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ interface BaseInfoProps {

const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
const [form] = Form.useForm();
const [isEdit, setIsEdit] = useState(false);
const [isEdit, setIsEdit] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
const statusRef = useRef();
const { t } = useTranslation();

Expand All @@ -45,6 +46,7 @@ const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
}, [isEdit, data.id]);

const onFinish = (formData: any) => {
setLoading(true);
const newFormData = formData;
if (newFormData.scm_auth_id) {
const [authType, id] = newFormData?.scm_auth_id?.split('#') ?? [];
Expand All @@ -64,7 +66,8 @@ const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
message.success(t('修改成功'));
getDetail();
setIsEdit(false);
});
})
.finally(() => setLoading(false));
};

const updateStatus = () => {
Expand Down Expand Up @@ -194,7 +197,7 @@ const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
getComponent(
<Input.Group compact>
<Form.Item name='scm_type' noStyle>
<Select style={{ width: 70 }} options={REPO_TYPE_OPTIONS} />
<Select style={{ width: '15%' }} options={REPO_TYPE_OPTIONS} />
</Form.Item>
<Form.Item
name='scm_url'
Expand All @@ -203,7 +206,7 @@ const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
{ required: true, message: t('请输入工具仓库地址') },
]}
>
<Input style={{ width: 380 }} />
<Input style={{ width: '85%' }} />
</Form.Item>
</Input.Group>,
data.scm_url,
Expand All @@ -220,13 +223,10 @@ const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
name='scm_auth_id'
label={t('凭证')}
getAuthList={[
UserAPI.authSSH().get({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.authAccount().get({ limit: 200 })
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.getOAuthInfos()
.then(({ results }: RestfulListAPIParams) => results || []),
UserAPI.getPlatformStatus().then(r => r || {}),
UserAPI.authSSH().get,
UserAPI.authAccount().get,
UserAPI.getOAuthInfos,
UserAPI.getPlatformStatus,
]}
selectStyle={{ width: 360 }}
required={isEdit}
Expand Down Expand Up @@ -300,11 +300,12 @@ const BaseInfo = ({ orgSid, data, editable, getDetail }: BaseInfoProps) => {
type='primary'
htmlType='submit'
key='edit'
loading={loading}
>{t('确认')}</Button>
<Button className="ml-12" onClick={() => setIsEdit(false)}>{t('取消')}</Button>
</>
) : (
<Button type='primary' onClick={() => {
<Button type='primary' loading={loading} onClick={() => {
setIsEdit(true);
}}>{t('编辑')}</Button>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams, useHistory } from 'react-router-dom';
import { find } from 'lodash';
import { useSelector } from 'react-redux';
import { Tabs } from 'coding-oa-uikit';
import ArrowLeft from 'coding-oa-uikit/lib/icon/ArrowLeft';

import { getToolsRouter } from '@src/utils/getRoutePath';
import { getToolDetail } from '@src/services/tools';
import { getTeamMember } from '@src/services/team';
import { useStateStore } from '@tencent/micro-frontend-shared/hook-store';
import { NAMESPACE, UserState } from '@src/store/user';
import { isEnableManage } from '@plat/util';
Expand All @@ -30,19 +29,12 @@ const ToolDetail = () => {
const { userinfo } = useStateStore<UserState>(NAMESPACE);
const { orgSid, toolId, tab }: any = useParams();
const [detail, setDetail] = useState<any>({});
const [admins, setAdmins] = useState([]);
const isAdmin = !!find(admins, { username: userinfo.username }); // 当前用户是否是管理员
const isAdmin = useSelector((state: any) => state.APP)?.isOrgAdminUser ?? false;
const isCustom = orgSid === detail?.org_detail?.org_sid; // 当前工具为自定义工具
const isSuperuser = userinfo.is_superuser; // 是否为超级管理员
const isManage = /^\/manage/.test(window.location.pathname); // 管理页面
const editable = (isCustom && isAdmin) || isSuperuser || isEnableManage(); // 编辑权限

useEffect(() => {
getTeamMember(orgSid).then(({ admins }: any) => {
setAdmins(admins || []);
});
}, [orgSid]);

useEffect(() => {
getDetail();
}, [orgSid, toolId]);
Expand Down
Loading