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