Unverified Commit 2c644be3 authored by Licho's avatar Licho Committed by GitHub

refactor: some trivial refactor (#2243)

Signed-off-by: 's avatarLicho <lecho.sun@gmail.com>
parent 748d4780
...@@ -1152,9 +1152,6 @@ export default { ...@@ -1152,9 +1152,6 @@ export default {
'pages.datastudio.footer.codePosition': '行{Ln}:列{Col} ', 'pages.datastudio.footer.codePosition': '行{Ln}:列{Col} ',
'pages.datastudio.label.result.query.latest.data': '获取最新数据', 'pages.datastudio.label.result.query.latest.data': '获取最新数据',
'pages.datastudio.help.sqlChangedPrompt':
'检测到当前页远程有更改,是否刷新更新数据?',
'pages.datastudio.help.sqlChanged': 'Sql内容或配置变更',
'datastudio.middle.qg': '快捷引导', 'datastudio.middle.qg': '快捷引导',
'datastudio.middle.qg.clusterInstance': '注册 Session 集群', 'datastudio.middle.qg.clusterInstance': '注册 Session 集群',
......
...@@ -29,8 +29,8 @@ export const IconRender = ({ icon }: { icon: string }) => { ...@@ -29,8 +29,8 @@ export const IconRender = ({ icon }: { icon: string }) => {
return icon ? React.createElement(Icons[icon]) : null; return icon ? React.createElement(Icons[icon]) : null;
}; };
const renderMenuType = (menuYype: string) => { const renderMenuType = (menuType: string) => {
switch (menuYype) { switch (menuType) {
case 'F': case 'F':
return <>{l('menu.type.button')}</>; return <>{l('menu.type.button')}</>;
case 'M': case 'M':
...@@ -111,7 +111,7 @@ export const buildMenuTree = ( ...@@ -111,7 +111,7 @@ export const buildMenuTree = (
// 获取当前级别最大的 orderNum // 获取当前级别最大的 orderNum
let maxChildOrderNum = let maxChildOrderNum =
item.children && item.children.length > 0 item.children?.length > 0
? Math.max(...item.children.map((item) => item.orderNum)) ? Math.max(...item.children.map((item) => item.orderNum))
: item.orderNum; : item.orderNum;
...@@ -154,10 +154,6 @@ export const buildMenuTree = ( ...@@ -154,10 +154,6 @@ export const buildMenuTree = (
/** /**
* build menu form tree (filter button) * build menu form tree (filter button)
* @param {SysMenu[]} data
* @param {string} searchValue
* @param {boolean} filterButton
* @returns {any}
*/ */
export const buildMenuFormTree = ( export const buildMenuFormTree = (
......
...@@ -61,7 +61,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => { ...@@ -61,7 +61,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => {
/** /**
* close * close
* @type {() => void}
*/ */
const handleClose = useCallback(() => { const handleClose = useCallback(() => {
onClose(); onClose();
...@@ -73,14 +72,13 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => { ...@@ -73,14 +72,13 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => {
*/ */
const handleSubmit = async () => { const handleSubmit = async () => {
setLoading(true); setLoading(true);
await onSubmit(selectValue); onSubmit(selectValue);
setLoading(false); setLoading(false);
setMenuData({ menus: [], selectedMenuIds: [] }); setMenuData({ menus: [], selectedMenuIds: [] });
}; };
/** /**
* render extra buttons * render extra buttons
* @returns {JSX.Element}
*/ */
const renderExtraButtons = () => { const renderExtraButtons = () => {
return ( return (
...@@ -97,7 +95,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => { ...@@ -97,7 +95,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => {
/** /**
* search tree node * search tree node
* @type {(e: {target: {value: React.SetStateAction<string>}}) => void}
*/ */
const onSearchChange = useCallback( const onSearchChange = useCallback(
(e: { target: { value: React.SetStateAction<string> } }) => { (e: { target: { value: React.SetStateAction<string> } }) => {
...@@ -111,7 +108,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => { ...@@ -111,7 +108,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => {
}; };
return ( return (
<>
<Drawer <Drawer
title={l('role.assignMenu', '', { roleName: values.roleName })} title={l('role.assignMenu', '', { roleName: values.roleName })}
open={open} open={open}
...@@ -149,7 +145,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => { ...@@ -149,7 +145,6 @@ const AssignMenu: React.FC<AssignMenuProps> = (props) => {
<Empty className={'code-content-empty'} /> <Empty className={'code-content-empty'} />
)} )}
</Drawer> </Drawer>
</>
); );
}; };
......
...@@ -76,8 +76,8 @@ const RoleModalForm: React.FC<RoleModalProps> = (props) => { ...@@ -76,8 +76,8 @@ const RoleModalForm: React.FC<RoleModalProps> = (props) => {
*/ */
const submitForm = async () => { const submitForm = async () => {
const fieldsValue = await form.validateFields(); const fieldsValue = await form.validateFields();
await handleSubmit({ ...values, ...fieldsValue }); handleSubmit({ ...values, ...fieldsValue });
await handleCancel(); handleCancel();
}; };
/** /**
......
...@@ -54,7 +54,7 @@ const RoleProTable: React.FC = () => { ...@@ -54,7 +54,7 @@ const RoleProTable: React.FC = () => {
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const executeAndCallbackRefresh = async (callback: () => void) => { const executeAndCallbackRefresh = async (callback: () => Promise<void>) => {
setLoading(true); setLoading(true);
await callback(); await callback();
setLoading(false); setLoading(false);
......
...@@ -43,7 +43,6 @@ type PermissionsFormProps = { ...@@ -43,7 +43,6 @@ type PermissionsFormProps = {
/** /**
* CodeEditProps * CodeEditProps
* @type {{lineNumbers: string, height: string}}
*/ */
const CodeEditProps = { const CodeEditProps = {
height: '25vh', height: '25vh',
...@@ -52,26 +51,21 @@ const CodeEditProps = { ...@@ -52,26 +51,21 @@ const CodeEditProps = {
const PermissionsForm: React.FC<PermissionsFormProps> = (props) => { const PermissionsForm: React.FC<PermissionsFormProps> = (props) => {
const { values, roles, form } = props; const { values, roles, form } = props;
const [expression, setExpression] = useState<string>(values.expression || ''); const [expression, setExpression] = useState<string>(values.expression ?? '');
/** /**
* get role options * get role options
* @returns {DefaultOptionType[]}
*/ */
const getRoleOptions = () => { const getRoleOptions = () => {
const itemList: DefaultOptionType[] = []; const itemList: DefaultOptionType[] = roles.map((item) => ({
roles.map((item) => {
return itemList.push({
label: item.roleName, label: item.roleName,
value: item.id, value: item.id,
}); }));
});
return itemList; return itemList;
}; };
/** /**
* render row permissions form * render row permissions form
* @returns {JSX.Element}
*/ */
const renderRowPermissionsForm = () => { const renderRowPermissionsForm = () => {
return ( return (
...@@ -111,7 +105,7 @@ const PermissionsForm: React.FC<PermissionsFormProps> = (props) => { ...@@ -111,7 +105,7 @@ const PermissionsForm: React.FC<PermissionsFormProps> = (props) => {
> >
<CodeEdit <CodeEdit
onChange={(value) => { onChange={(value) => {
setExpression(value); setExpression(value ?? '');
}} }}
code={expression} code={expression}
language={'sql'} language={'sql'}
......
...@@ -91,19 +91,17 @@ export const PermissionsModal: React.FC<RoleSelectPermissionsFormProps> = ( ...@@ -91,19 +91,17 @@ export const PermissionsModal: React.FC<RoleSelectPermissionsFormProps> = (
/** /**
* submit form * submit form
* @returns {Promise<void>}
*/ */
const submitForm = async () => { const submitForm = async () => {
const fieldsValue = await form.validateFields(); const fieldsValue = await form.validateFields();
await handleSubmit({ ...values, ...fieldsValue }); handleSubmit({ ...values, ...fieldsValue });
await handleCancel(); handleCancel();
}; };
/** /**
* render * render
*/ */
return ( return (
<>
<Modal <Modal
{...NORMAL_MODAL_OPTIONS} {...NORMAL_MODAL_OPTIONS}
title={ title={
...@@ -115,6 +113,5 @@ export const PermissionsModal: React.FC<RoleSelectPermissionsFormProps> = ( ...@@ -115,6 +113,5 @@ export const PermissionsModal: React.FC<RoleSelectPermissionsFormProps> = (
> >
<PermissionsForm form={form} values={values} roles={roleList} /> <PermissionsForm form={form} values={values} roles={roleList} />
</Modal> </Modal>
</>
); );
}; };
...@@ -38,7 +38,7 @@ const PermissionsProTable: React.FC = () => { ...@@ -38,7 +38,7 @@ const PermissionsProTable: React.FC = () => {
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const executeAndCallbackRefresh = async (callback: () => void) => { const executeAndCallbackRefresh = async (callback: () => Promise<void>) => {
setLoading(true); setLoading(true);
await callback(); await callback();
setLoading(false); setLoading(false);
......
...@@ -67,15 +67,14 @@ const TenantModalForm: React.FC<TenantModalFormProps> = (props) => { ...@@ -67,15 +67,14 @@ const TenantModalForm: React.FC<TenantModalFormProps> = (props) => {
*/ */
const submitForm = async () => { const submitForm = async () => {
const fieldsValue = await form.validateFields(); const fieldsValue = await form.validateFields();
await handleSubmit({ ...values, ...fieldsValue }); handleSubmit({ ...values, ...fieldsValue });
await handleCancel(); handleCancel();
}; };
/** /**
* render * render
*/ */
return ( return (
<>
<Modal <Modal
{...NORMAL_MODAL_OPTIONS} {...NORMAL_MODAL_OPTIONS}
title={values.id ? l('tenant.update') : l('tenant.create')} title={values.id ? l('tenant.update') : l('tenant.create')}
...@@ -85,7 +84,6 @@ const TenantModalForm: React.FC<TenantModalFormProps> = (props) => { ...@@ -85,7 +84,6 @@ const TenantModalForm: React.FC<TenantModalFormProps> = (props) => {
> >
<TenantForm values={values} form={form} /> <TenantForm values={values} form={form} />
</Modal> </Modal>
</>
); );
}; };
......
...@@ -59,7 +59,7 @@ const TenantProTable: React.FC = () => { ...@@ -59,7 +59,7 @@ const TenantProTable: React.FC = () => {
); );
}; };
const executeAndCallbackRefresh = async (callback: () => void) => { const executeAndCallbackRefresh = async (callback: () => Promise<void>) => {
setLoading(true); setLoading(true);
await callback(); await callback();
setLoading(false); setLoading(false);
......
...@@ -48,7 +48,7 @@ const GlobalVarForm: React.FC<GlobalVarModalProps> = (props) => { ...@@ -48,7 +48,7 @@ const GlobalVarForm: React.FC<GlobalVarModalProps> = (props) => {
const { values, form } = props; const { values, form } = props;
const [globalVarValue, setGlobalVarValue] = useState<string>( const [globalVarValue, setGlobalVarValue] = useState<string>(
values.fragmentValue || '', values.fragmentValue ?? '',
); );
const handleGlobalVarChange = (value: string) => { const handleGlobalVarChange = (value: string) => {
...@@ -85,7 +85,7 @@ const GlobalVarForm: React.FC<GlobalVarModalProps> = (props) => { ...@@ -85,7 +85,7 @@ const GlobalVarForm: React.FC<GlobalVarModalProps> = (props) => {
rules={[{ required: true, message: l('rc.gv.valuePlaceholder') }]} rules={[{ required: true, message: l('rc.gv.valuePlaceholder') }]}
> >
<CodeEdit <CodeEdit
onChange={(value) => handleGlobalVarChange(value)} onChange={(value) => handleGlobalVarChange(value ?? '')}
code={globalVarValue} code={globalVarValue}
language={'sql'} language={'sql'}
{...CodeEditProps} {...CodeEditProps}
......
...@@ -75,8 +75,8 @@ const GlobalVarModal: React.FC<GlobalVarModalProps> = (props) => { ...@@ -75,8 +75,8 @@ const GlobalVarModal: React.FC<GlobalVarModalProps> = (props) => {
*/ */
const submitForm = async () => { const submitForm = async () => {
const fieldsValue = await form.validateFields(); const fieldsValue = await form.validateFields();
await handleSubmit({ ...values, ...fieldsValue }); handleSubmit({ ...values, ...fieldsValue });
await handleCancel(); handleCancel();
}; };
return ( return (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment