Unverified Commit 3206819d authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[Refactor][web] split codeshow of floatbutton && fix some bug (#1953)

* modify code && fix some bug * added todo * delete timer prpos
parent ff71906d
......@@ -246,9 +246,10 @@ public class UserServiceImpl extends SuperServiceImpl<UserMapper, User> implemen
return Result.succeed(MessageResolverUtils.getMessage("user.assign.role.success"));
} else {
if (userRoleList.size() == 0) {
return Result.succeed(MessageResolverUtils.getMessage("user.assign.role.failed"));
return Result.succeed(
MessageResolverUtils.getMessage("user.binding.role.deleteAll"));
}
return Result.failed(MessageResolverUtils.getMessage("user.binding.role.deleteAll"));
return Result.failed(MessageResolverUtils.getMessage("user.assign.role.failed"));
}
}
......
......@@ -20,225 +20,192 @@
import MonacoEditor, {monaco} from "react-monaco-editor";
import {convertCodeEditTheme} from "@/utils/function";
import {MonacoEditorOptions} from "@/types/Public/data";
import {FloatButton, Space} from "antd";
import {
DownCircleFilled,
StopOutlined,
SyncOutlined,
UpCircleFilled
} from "@ant-design/icons";
import React, {useEffect, useState} from "react";
import React, {useState} from "react";
import {editor} from "monaco-editor";
import {l} from "@/utils/intl";
import IStandaloneCodeEditor = editor.IStandaloneCodeEditor;
import ScrollType = editor.ScrollType;
import EditorFloatBtn from "@/components/CustomEditor/EditorFloatBtn";
/**
* props
* todo:
* 1. Realize full screen/exit full screen in the upper right corner of the editor (Visible after opening)
* 2. Callback for right-clicking to clear logs (optional, not required)
*/
export type CodeShowFormProps = {
height?: string;
width?: string;
language?: string;
options?: any;
code: string;
lineNumbers?: string;
theme?: string;
autoWrap?: string;
showFloatButton?: boolean;
enableTimer?: boolean;
refreshLogCallback?: () => void;
height?: string;
width?: string;
language?: string;
options?: any;
code: string;
lineNumbers?: string;
theme?: string;
autoWrap?: string;
showFloatButton?: boolean;
refreshLogCallback?: () => void;
};
const CodeShow = (props: CodeShowFormProps) => {
/**
* 1. height: edit height
* 2. width: edit width
* 3. language: edit language
* 4. options: edit options
* 5. code: content
* 6. readOnly: is readOnly, value: true | false
* 7. lineNumbers: is show lineNumbers, value: on | off | relative | interval
* 8. theme: edit theme , value: vs-dark | vs | hc-black
* 9. autoWrap: is auto wrap, value: on | off | wordWrapColumn | bounded
*/
const {
height = "30vh", // if null or undefined, set default value
width = "100%", // if null or undefined, set default value
language,
options = {
...MonacoEditorOptions, // set default options
},
code, // content
lineNumbers, // show lineNumbers
theme, // edit theme
autoWrap = "on", // auto wrap
showFloatButton = false,
enableTimer = false,
refreshLogCallback,
} = props;
const [loading, setLoading] = useState<boolean>(false);
const [stoping, setStoping] = useState<boolean>(false);
const [editor, setEditor] = useState<IStandaloneCodeEditor>();
const [timer, setTimer] = useState<NodeJS.Timer>();
// register TypeScript language service
monaco.languages.register({
id: language || "typescript",
});
/**
* @description: handle sync log
* @returns {Promise<void>}
*/
const handleSyncLog = async () => {
setLoading(true);
setTimeout(() => {
refreshLogCallback?.();
setLoading(false);
}, 1000);
};
/**
* @description: handle auto refresh log
*/
useEffect(() => {
if (enableTimer) {
const timerSync = setInterval(() => {
handleSyncLog();
}, 5000);
setTimer(timerSync)
return () => {
clearInterval(timerSync);
}
}
}, [])
/**
* @description: handle stop auto refresh log
*/
const handleStopAutoRefresh = () => {
setStoping(true);
setTimeout(() => {
clearInterval(timer);
setStoping(false)
}, 1000);
}
/**
* @description: handle scroll to top
*/
const handleBackTop = () => {
editor?.revealLine(1);
}
/**
* @description: handle scroll to bottom
*/
const handleBackBottom = () => {
// @ts-ignore
editor?.revealLine(editor?.getModel()?.getLineCount());
}
/**
* @description: handle scroll to down
*/
const handleDownScroll = () => {
// @ts-ignore
editor?.setScrollPosition({scrollTop: editor?.getScrollTop() + 500}, ScrollType.Smooth);
}
/**
* @description: handle scroll to up
*/
const handleUpScroll = () => {
// @ts-ignore
editor?.setScrollPosition({scrollTop: editor?.getScrollTop() - 500}, ScrollType.Smooth);
}
/**
* @description: editorDidMount
* @param {editor.IStandaloneCodeEditor} editor
*/
const editorDidMount = (editor: IStandaloneCodeEditor) => {
setEditor(editor)
// 在编辑器加载完成后,设置自动布局和自动高亮显示
editor.layout();
editor.focus();
}
/**
* @description: render
*/
return (<>
<div className={"monaco-float"}>
<MonacoEditor
width={width}
height={height}
value={loading ? "loading..." : code}
language={language}
options={{
...options,
readOnly: true,
wordWrap: autoWrap,
autoDetectHighContrast: true,
selectOnLineNumbers: true,
fixedOverflowWidgets: true,
autoClosingDelete: "always",
lineNumbers,
}}
editorDidMount={editorDidMount}
theme={theme ? theme : convertCodeEditTheme()}
/>
<FloatButton.Group
open={showFloatButton} shape="square"
className={"float-button"}
>
<Space direction={"vertical"}>
{refreshLogCallback &&
<>
<FloatButton
tooltip={l('button.refresh')}
icon={<SyncOutlined spin={loading}/>}
onClick={handleSyncLog}
/>
{enableTimer &&
<FloatButton
tooltip={l('button.stopRefresh')}
icon={<StopOutlined spin={stoping}/>}
onClick={handleStopAutoRefresh}
/>
}
</>
}
<FloatButton.BackTop
tooltip={l('button.backTop')}
onClick={handleBackTop}
visibilityHeight={0}/>
<FloatButton.BackTop
className={"back-bottom"}
tooltip={l('button.backBottom')}
onClick={handleBackBottom}
visibilityHeight={0}/>
<FloatButton
icon={<UpCircleFilled/>}
tooltip={l('button.upScroll')}
onClick={handleUpScroll}
/>
<FloatButton
icon={<DownCircleFilled/>}
tooltip={l('button.downScroll')}
onClick={handleDownScroll}
/>
</Space>
</FloatButton.Group>
</div>
</>);
/**
* 1. height: edit height
* 2. width: edit width
* 3. language: edit language
* 4. options: edit options
* 5. code: content
* 6. readOnly: is readOnly, value: true | false
* 7. lineNumbers: is show lineNumbers, value: on | off | relative | interval
* 8. theme: edit theme , value: vs-dark | vs | hc-black
* 9. autoWrap: is auto wrap, value: on | off | wordWrapColumn | bounded
*/
const {
height = "30vh", // if null or undefined, set default value
width = "100%", // if null or undefined, set default value
language,
options = {
...MonacoEditorOptions, // set default options
},
code, // content
lineNumbers, // show lineNumbers
theme, // edit theme
autoWrap = "on", // auto wrap
showFloatButton = false,
refreshLogCallback,
} = props;
const {ScrollType} = editor;
const [loading, setLoading] = useState<boolean>(false);
const [stopping, setStopping] = useState<boolean>(false);
const [autoRefresh, setAutoRefresh] = useState<boolean>(false);
const [editorRef, setEditorRef] = useState<any>();
const [timer, setTimer] = useState<NodeJS.Timer>();
// register TypeScript language service
monaco.languages.register({
id: language || "typescript",
});
/**
* handle sync log
* @returns {Promise<void>}
*/
const handleSyncLog = async () => {
setLoading(true);
setTimeout(() => {
refreshLogCallback?.();
setLoading(false);
}, 1000);
};
/**
* handle stop auto refresh log
*/
const handleStopAutoRefresh = () => {
setStopping(true);
setTimeout(() => {
clearInterval(timer);
setStopping(false);
setAutoRefresh(false);
}, 1000);
};
/**
* handle stop auto refresh log
*/
const handleStartAutoRefresh = () => {
setAutoRefresh(true);
const timerSync = setInterval(() => {
handleSyncLog();
}, 5000);
setTimer(timerSync);
};
/**
* handle scroll to top
*/
const handleBackTop = () => {
editorRef.revealLine(1);
};
/**
* handle scroll to bottom
*/
const handleBackBottom = () => {
editorRef.revealLine(editorRef.getModel().getLineCount());
};
/**
* handle scroll to down
*/
const handleDownScroll = () => {
editorRef.setScrollPosition({scrollTop: editorRef.getScrollTop() + 500}, ScrollType.Smooth);
};
/**
* handle scroll to up
*/
const handleUpScroll = () => {
// @ts-ignore
editorRef?.setScrollPosition({scrollTop: editorRef.getScrollTop() - 500}, ScrollType.Smooth);
};
/**
* editorDidMount
* @param {editor.IStandaloneCodeEditor} editor
*/
const editorDidMount = (editor: editor.IStandaloneCodeEditor) => {
setEditorRef(editor);
// 在编辑器加载完成后,设置自动布局和自动高亮显示
editor.layout();
editor.focus();
};
const restEditBtnProps = {
refreshLogCallback,
autoRefresh,
stopping,
loading,
handleSyncLog,
handleStopAutoRefresh,
handleStartAutoRefresh,
handleBackTop,
handleBackBottom,
handleUpScroll,
handleDownScroll,
}
/**
* render
*/
return (<>
<div id={"monaco"} className={"monaco-float"}>
<MonacoEditor
width={width}
height={height}
value={loading ? "loading..." : code}
language={language}
options={{
...options,
readOnly: true,
wordWrap: autoWrap,
autoDetectHighContrast: true,
selectOnLineNumbers: true,
fixedOverflowWidgets: true,
autoClosingDelete: "always",
lineNumbers,
}}
editorDidMount={editorDidMount}
theme={theme ? theme : convertCodeEditTheme()}
/>
{showFloatButton && <EditorFloatBtn {...restEditBtnProps}/>}
</div>
</>);
};
export default CodeShow;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from "react";
import {FloatButton, Space} from "antd";
import {l} from "@/utils/intl";
import {DownCircleFilled, StopFilled, SyncOutlined, UpCircleFilled} from "@ant-design/icons";
import {PlayCircleFilled} from "@ant-design/icons/lib/icons";
/**
* props
*/
type EditFloatBtnProps = {
refreshLogCallback?: () => void; // refresh log callback
autoRefresh?: boolean; // auto refresh flag
stopping?: boolean; // stop auto refresh flag
loading?: boolean; // loading flag
handleSyncLog?: () => void; // sync log callback
handleStopAutoRefresh?: () => void; // stop auto refresh callback
handleStartAutoRefresh?: () => void; // start auto refresh callback
handleBackTop?: () => void; // back to top callback
handleBackBottom?: () => void; // back to bottom callback
handleUpScroll?: () => void; // up scroll callback
handleDownScroll?: () => void; // down scroll callback
}
const EditorFloatBtn: React.FC<EditFloatBtnProps> = (props) => {
/**
* init props
*/
const {
refreshLogCallback,
autoRefresh,
stopping,
loading,
handleSyncLog,
handleStopAutoRefresh,
handleStartAutoRefresh,
handleBackTop,
handleBackBottom,
handleUpScroll,
handleDownScroll
} = props;
/**
* render
*/
return <>
<FloatButton.Group
shape="circle"
className={"float-button"}
>
<Space direction={"vertical"}>
{/* if refreshLogCallback is not null, then show sync button , auto refresh button and stop auto refresh button */}
{refreshLogCallback &&
<>
<FloatButton tooltip={l("button.refresh")} icon={<SyncOutlined spin={loading}/>} onClick={handleSyncLog}/>
{autoRefresh ?
<FloatButton icon={<StopFilled spin={stopping}/>} tooltip={l("button.stopRefresh")} onClick={handleStopAutoRefresh}/> :
<FloatButton icon={<PlayCircleFilled/>} tooltip={l("button.startRefresh")} onClick={handleStartAutoRefresh}/>
}
</>
}
{/* back top */}
<FloatButton.BackTop tooltip={l("button.backTop")} onClick={handleBackTop} visibilityHeight={0}/>
{/* go bottom */}
<FloatButton.BackTop className={"back-bottom"} tooltip={l("button.backBottom")} onClick={handleBackBottom}
visibilityHeight={0}/>
{/* scroll up */}
<FloatButton icon={<UpCircleFilled/>} tooltip={l("button.upScroll")} onClick={handleUpScroll}/>
{/* scroll down */}
<FloatButton icon={<DownCircleFilled/>} tooltip={l("button.downScroll")} onClick={handleDownScroll}/>
</Space>
</FloatButton.Group>
</>;
};
export default EditorFloatBtn;
......@@ -205,3 +205,35 @@ export const MarkDownSvg = () => {
</>;
};
export const LogSvg = () => {
return <>
<Icon style={{...IconStyle}} component={() => (
<svg className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
>
<path
d="M704 64c35.328 0 64 28.672 64 64v321.7408A288 288 0 0 0 496.5376 896H128c-35.328 0-64-28.672-64-64V128c0-35.328 28.672-64 64-64h576zM480 384h-256a32 32 0 0 0-31.488 26.2656l-0.512 5.7344v32c0 15.7184 11.3152 28.7744 26.2656 31.488l5.7344 0.512h256a32 32 0 0 0 31.488-26.2656L512 448v-32a32 32 0 0 0-26.2656-31.488l-5.7344-0.512z m128-192h-384a32 32 0 0 0-31.488 26.2656l-0.512 5.7344V256c0 15.7184 11.3152 28.7744 26.2656 31.488l5.7344 0.512h384a32 32 0 0 0 31.488-26.2656L640 256v-32a32 32 0 0 0-26.2656-31.488l-5.7344-0.512z"
fill="#007AF5"></path>
<path
d="M736 512a224 224 0 1 1 0 448 224 224 0 0 1 0-448z m0 80.0256a32 32 0 0 0-31.488 26.2144l-0.512 5.7856v128l0.512 5.7344a32.0512 32.0512 0 0 0 25.7536 25.7024l5.7344 0.512h128l5.7344-0.512a32.0512 32.0512 0 0 0 25.7536-25.7024l0.512-5.7856-0.512-5.7344a32.0512 32.0512 0 0 0-25.7536-25.7024l-5.7344-0.512H768v-96.0512l-0.512-5.7344a32 32 0 0 0-31.488-26.2144z"
fill="#66AFF9"></path>
</svg>
)}/>
</>;
};
export const ScalaSvg = () => {
return <>
<Icon style={{...IconStyle}} component={() => (
<svg className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
>
<path
d="M213.844 203.564l596.4-87.928v197.952l-596.4 87.928zM213.788 457.312l596.4-87.928v197.952l-596.4 87.928zM213.768 710.4l596.392-87.932v197.952L213.768 908.348z"
fill="#F44336"></path>
<path
d="M225.12 366.636l382.416 123.684-11.328 35.028-382.416-123.684zM427.76 245.496l382.416 123.688-11.328 35.028-382.416-123.688zM225.112 620.148l382.416 123.684-11.328 35.032-382.416-123.688zM427.792 498.604l382.416 123.688-11.332 35.028-382.412-123.688z"
fill="#F44336"></path>
</svg>
)}/>
</>;
};
......@@ -121,8 +121,21 @@ ol {
overflow-y: auto;
max-height: 70vh;
min-height: 70vh;
.ant-tree {
min-width: max-content;
.ant-tree-node-content-wrapper {
display: flex;
:hover {
color: #1eef07;
}
}
}
}
.code-content-empty{
.code-content-empty {
height: 100%;
display: flex;
justify-content: center;
......@@ -132,15 +145,17 @@ ol {
max-height: 70vh;
}
.monaco-float{
.monaco-float {
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
.float-button {
position: absolute;
transform: translate(5%, 15%);
.back-bottom{
.back-bottom {
transform: rotate(180deg);
}
}
......@@ -153,4 +168,4 @@ ol {
*/
.needWrap {
white-space: pre-wrap;
}
\ No newline at end of file
}
......@@ -66,6 +66,7 @@ export default {
'button.downScroll': 'Down Scroll',
'button.upScroll': 'Up Scroll',
'button.stopRefresh': 'Stop Auto Refresh',
'button.startRefresh': 'Start Auto Refresh(5s/e)',
'right.menu.open': 'Open',
'right.menu.submit': 'Sync Submit',
......
......@@ -66,6 +66,7 @@ export default {
'button.downScroll': '向下滚动',
'button.upScroll': '向上滚动',
'button.stopRefresh': '停止自动刷新',
'button.startRefresh': '开始自动刷新(5s/次)',
'right.menu.open': '打开',
......
......@@ -43,17 +43,22 @@ const RoleProTable: React.FC = () => {
const [loading, setLoading] = useState<boolean>(false);
const actionRef = useRef<ActionType>();
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
setLoading(false);
actionRef.current?.reload?.();
}
/**
* delete role by id
* @param id role id
*/
const handleDeleteSubmit = async (id: number) => {
setLoading(true);
// TODO: DELETE role interface is use /api/role , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/role (ROLE)
await handleRemoveById(API_CONSTANTS.ROLE_DELETE, id);
setLoading(false);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
// TODO: DELETE role interface is use /api/role , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/role (ROLE)
await handleRemoveById(API_CONSTANTS.ROLE_DELETE, id);
});
}
/**
......@@ -61,14 +66,13 @@ const RoleProTable: React.FC = () => {
* @param value
*/
const handleAddOrUpdateSubmit = async (value: any) => {
// TODO: added or update role interface is use /api/role/addedOrUpdateRole , because of the backend interface 'saveOrUpdate' is repeat , in the future, we need to change the interface to /api/role (ROLE)
await handleAddOrUpdate(API_CONSTANTS.ROLE_ADDED_OR_UPDATE, {
...value,
tenantId: getTenantByLocalStorage()
await executeAndCallbackRefresh(async () => {
// TODO: added or update role interface is use /api/role/addedOrUpdateRole , because of the backend interface 'saveOrUpdate' is repeat , in the future, we need to change the interface to /api/role (ROLE)
await handleAddOrUpdate(API_CONSTANTS.ROLE_ADDED_OR_UPDATE, {...value, tenantId: getTenantByLocalStorage()});
handleModalVisible(false);
});
handleModalVisible(false);
setFormValues({})
actionRef?.current?.reload?.();
}
/**
......@@ -162,14 +166,12 @@ const RoleProTable: React.FC = () => {
values={{}}
/>
{/* modify */}
{(formValues && Object.keys(formValues).length) &&
<RoleModalForm
onSubmit={(value: any) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
}
<RoleModalForm
onSubmit={(value: any) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
</>
}
;
......
......@@ -38,17 +38,22 @@ const PermissionsProTable: React.FC = () => {
const [loading, setLoading] = useState<boolean>(false);
const actionRef = useRef<ActionType>();
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
setLoading(false);
actionRef.current?.reload?.();
}
/**
* delete role by id
* @param id role id
*/
const handleDeleteSubmit = async (id: number) => {
setLoading(true);
// TODO: DELETE role interface is use /api/rowPermissions/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/rowPermissions (rowPermissions)
await handleRemoveById(API_CONSTANTS.ROW_PERMISSIONS_DELETE, id);
setLoading(false);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
// TODO: DELETE role interface is use /api/rowPermissions/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/rowPermissions (rowPermissions)
await handleRemoveById(API_CONSTANTS.ROW_PERMISSIONS_DELETE, id);
});
}
/**
......@@ -56,13 +61,10 @@ const PermissionsProTable: React.FC = () => {
* @param value
*/
const handleAddOrUpdateSubmit = async (value: any) => {
await handleAddOrUpdate(API_CONSTANTS.ROW_PERMISSIONS, {
...value,
tenantId: getTenantByLocalStorage()
await executeAndCallbackRefresh(async () => {
await handleAddOrUpdate(API_CONSTANTS.ROW_PERMISSIONS, {...value, tenantId: getTenantByLocalStorage()});
handleModalVisible(false);
});
handleModalVisible(false);
setFormValues({})
actionRef.current?.reload?.();
}
/**
......@@ -163,16 +165,13 @@ const PermissionsProTable: React.FC = () => {
/>
{/* modify row Permissions */}
{(formValues && Object.keys(formValues).length) &&
<PermissionsModal
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
}
<PermissionsModal
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
</>
}
export default PermissionsProTable;
\ No newline at end of file
export default PermissionsProTable;
......@@ -44,15 +44,22 @@ const TenantProTable: React.FC = () => {
const [formValues, setFormValues] = useState<Partial<UserBaseInfo.Tenant>>({});
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
setLoading(false);
actionRef.current?.reload?.();
}
/**
* add tenant
* @param value
*/
const handleAddOrUpdateSubmit = async (value: Partial<UserBaseInfo.Tenant>) => {
await handleAddOrUpdate(API_CONSTANTS.TENANT, value);
handleModalVisible(false);
setFormValues({})
actionRef?.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await handleAddOrUpdate(API_CONSTANTS.TENANT, value);
handleModalVisible(false);
})
};
/**
......@@ -60,24 +67,20 @@ const TenantProTable: React.FC = () => {
* @param id tenant id
*/
const handleDeleteSubmit = async (id: number) => {
setLoading(true)
// TODO: delete tenant interface is use /api/tenant/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/tenant (TENANT)
await handleRemoveById(API_CONSTANTS.TENANT_DELETE, id);
setLoading(false)
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
// TODO: delete tenant interface is use /api/tenant/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/tenant (TENANT)
await handleRemoveById(API_CONSTANTS.TENANT_DELETE, id);
})
};
/**
* assign user to tenant
*/
const handleAssignUserSubmit = async () => {
// to save
await handleAddOrUpdate(API_CONSTANTS.ASSIGN_USER_TO_TENANT, {
tenantId: formValues.id as number,
userIds: tenantRelFormValues
});
setHandleGrantTenant(false);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await handleAddOrUpdate(API_CONSTANTS.ASSIGN_USER_TO_TENANT, {tenantId: formValues.id, userIds: tenantRelFormValues});
setHandleGrantTenant(false);
})
}
const handleCancel = () => {
handleModalVisible(false);
......@@ -173,15 +176,13 @@ const TenantProTable: React.FC = () => {
/>
{/*update tenant form*/}
{(formValues && Object.keys(formValues).length) &&
<TenantForm
key={"tenantFormUpdate"}
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
}
<TenantForm
key={"tenantFormUpdate"}
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
{/* assign user to tenant */}
<TenantModalTransfer
tenant={formValues}
......
......@@ -18,7 +18,7 @@
*/
import React, {useRef, useState} from "react";
import React, {useEffect, useRef, useState} from "react";
import {LockTwoTone} from "@ant-design/icons";
import ProTable, {ActionType, ProColumns} from "@ant-design/pro-table";
import {Button} from "antd";
......@@ -61,24 +61,13 @@ const UserProTable = () => {
const actionRef = useRef<ActionType>(); // table action
const access = useAccess(); // access control
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
actionRef.current?.reload?.();
setLoading(false);
actionRef.current?.reload?.();
}
/**
* user add role to submit
*/
const handleGrantRoleSubmit = async () => {
await executeAndCallbackRefresh(() => {
handlePutData(API_CONSTANTS.USER_ASSIGN_ROLE, {userId: formValues.id, roleIds: roleList});
handleAssignRoleTransferOpen(false);
})
};
/**
* edit user
* @param value
......@@ -111,17 +100,31 @@ const UserProTable = () => {
* @param value
*/
const handleDeleteUser = async (value: UserBaseInfo.User) => {
// TODO: delete user interface is use /api/users/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/users (USER)
await executeAndCallbackRefresh(() => handleRemoveById(API_CONSTANTS.USER_DELETE, value.id))
await executeAndCallbackRefresh(async () => {
// TODO: delete user interface is use /api/users/delete , because of the backend interface 'DeleteMapping' is repeat , in the future, we need to change the interface to /api/users (USER)
await handleRemoveById(API_CONSTANTS.USER_DELETE, value.id)
})
};
/**
* user add role to submit
*/
const handleGrantRoleSubmit = async () => {
await executeAndCallbackRefresh(async () => {
await handlePutData(API_CONSTANTS.USER_ASSIGN_ROLE, {userId: formValues.id, roleIds: roleList});
handleAssignRoleTransferOpen(false);
})
};
/**
* user enable or disable
* @param value
*/
const handleChangeEnable = async (value: UserBaseInfo.User) => {
await executeAndCallbackRefresh(() => updateEnabled(API_CONSTANTS.USER_ENABLE, {id: value.id}))
await executeAndCallbackRefresh(async () => {
await updateEnabled(API_CONSTANTS.USER_ENABLE, {id: value.id})
})
};
/**
......@@ -129,8 +132,11 @@ const UserProTable = () => {
* @param value
*/
const handlePasswordChangeSubmit = async (value: any) => {
await handleOption(API_CONSTANTS.USER_MODIFY_PASSWORD, l("button.changePassword"), value);
await handlePasswordModalOpen(false);
await executeAndCallbackRefresh(async () => {
await handleOption(API_CONSTANTS.USER_MODIFY_PASSWORD, l("button.changePassword"), value);
await handlePasswordModalOpen(false);
})
};
/**
......@@ -138,9 +144,9 @@ const UserProTable = () => {
* @param value
*/
const handleSubmitUser = async (value: Partial<UserBaseInfo.User>) => {
await executeAndCallbackRefresh(() => {
handleAddOrUpdate(API_CONSTANTS.USER, value);
handleModalOpen(false);
await executeAndCallbackRefresh(async () => {
await handleAddOrUpdate(API_CONSTANTS.USER, value);
handleModalOpen(false);
})
};
......@@ -171,7 +177,8 @@ const UserProTable = () => {
dataIndex: "enabled",
hideInSearch: true,
render: (_, record) => {
return <EnableSwitchBtn key={`${record.id}_enable`} record={record} onChange={() => handleChangeEnable(record)}/>;
return <EnableSwitchBtn key={`${record.id}_enable`} record={record}
onChange={() => handleChangeEnable(record)}/>;
},
filters: STATUS_MAPPING(),
filterMultiple: false,
......@@ -198,7 +205,8 @@ const UserProTable = () => {
width: "10vh",
render: (_: any, record: UserBaseInfo.User) => [
<EditBtn key={`${record.id}_edit`} onClick={() => handleEditVisible(record)}/>,
<AssignBtn key={`${record.id}_delete`} onClick={() => handleAssignRole(record)} title={l('user.assignRole')}/>,
<AssignBtn key={`${record.id}_delete`} onClick={() => handleAssignRole(record)}
title={l('user.assignRole')}/>,
<Button
className={"options-button"}
key={`${record.id}_change`}
......@@ -245,27 +253,23 @@ const UserProTable = () => {
modalVisible={modalOpen}
values={{}}
/>
{(formValues && Object.keys(formValues).length > 0) && (
<>
<PasswordModal
key={"handlePasswordChangeSubmit"}
onSubmit={handlePasswordChangeSubmit}
onCancel={() => handlePasswordModalOpen(false)}
modalVisible={passwordModalOpen}
values={formValues}
/>
<UserModalForm
key={"handleUpdateUser"}
onSubmit={handleSubmitUser}
onCancel={() => {
handleUpdateModalOpen(false);
setFormValues({});
}}
modalVisible={updateModalOpen}
values={formValues}
/>
</>
)}
<PasswordModal
key={"handlePasswordChangeSubmit"}
onSubmit={handlePasswordChangeSubmit}
onCancel={() => handlePasswordModalOpen(false)}
modalVisible={passwordModalOpen}
values={formValues}
/>
<UserModalForm
key={"handleUpdateUser"}
onSubmit={handleSubmitUser}
onCancel={() => {
handleUpdateModalOpen(false);
setFormValues({});
}}
modalVisible={updateModalOpen}
values={formValues}
/>
{/* assign role to user */}
<RoleModalTransfer
user={formValues}
......
......@@ -38,221 +38,219 @@ import DescriptionsItem from "antd/es/descriptions/Item";
import AlertGroupForm from "@/pages/RegCenter/Alert/AlertGroup/components/AlertGroupForm";
const AlertGroupTableList: React.FC = (props: any) => {
/**
* state
*/
const {dispatch} = props;
const [modalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [formValues, setFormValues] = useState({});
const [alertGroupList, setAlertGroupList] = useState<Alert.AlertGroup[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const actionRef = useRef<ActionType>();
/**
* state
*/
const {dispatch} = props;
const [modalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [formValues, setFormValues] = useState({});
const [alertGroupList, setAlertGroupList] = useState<Alert.AlertGroup[]>([]);
const [loading, setLoading] = useState<boolean>(false);
const actionRef = useRef<ActionType>();
/**
* execute query alert instance list
* set alert instance list
*/
const queryAlertGroupList = async () => {
await queryList(API_CONSTANTS.ALERT_GROUP).then(res => {
setAlertGroupList(res.data);
});
};
/**
* execute query alert instance list
* set alert instance list
*/
const queryAlertGroupList = async () => {
await queryList(API_CONSTANTS.ALERT_GROUP).then(res => {
setAlertGroupList(res.data);
});
};
/**
* mount data
*/
useEffect(() => {
queryAlertGroupList();
showAlertInstance(dispatch);
}, [modalVisible]);
/**
* mount data
*/
useEffect(() => {
queryAlertGroupList();
showAlertInstance(dispatch);
}, [modalVisible]);
/**
* execute and refresh loading
* @param callback
*/
const exexuteWithRefreshLoading = async (callback: any) => {
setLoading(true);
await callback();
await queryAlertGroupList();
setLoading(false);
};
/**
* execute and refresh loading
* @param callback
*/
const exexuteWithRefreshLoading = async (callback: any) => {
setLoading(true);
await callback();
await queryAlertGroupList();
setLoading(false);
};
/**
* handle delete alert instance
* @param id
*/
const handleDeleteSubmit = async (id: number) => {
Modal.confirm({
title: l("rc.ag.delete"),
content: l("rc.ag.deleteConfirm"),
okText: l("button.confirm"),
cancelText: l("button.cancel"),
onOk: async () => {
await exexuteWithRefreshLoading(async () => {
await handleRemoveById(API_CONSTANTS.ALERT_GROUP_DELETE, id);
/**
* handle delete alert instance
* @param id
*/
const handleDeleteSubmit = async (id: number) => {
Modal.confirm({
title: l("rc.ag.delete"),
content: l("rc.ag.deleteConfirm"),
okText: l("button.confirm"),
cancelText: l("button.cancel"),
onOk: async () => {
await exexuteWithRefreshLoading(async () => {
await handleRemoveById(API_CONSTANTS.ALERT_GROUP_DELETE, id);
});
}
});
}
});
};
};
/**
* handle enable alert instance
* @param item
*/
const handleEnable = async (item: Alert.AlertGroup) => {
await exexuteWithRefreshLoading(async () => {
await updateEnabled(API_CONSTANTS.ALERT_GROUP_ENABLE, {id: item.id});
});
};
/**
* handle enable alert instance
* @param item
*/
const handleEnable = async (item: Alert.AlertGroup) => {
await exexuteWithRefreshLoading(async () => {
await updateEnabled(API_CONSTANTS.ALERT_GROUP_ENABLE, {id: item.id});
});
};
/**
* cancel callback
*/
const handleCleanState = () => {
setFormValues({});
handleModalVisible(false);
handleUpdateModalVisible(false);
};
/**
* cancel callback
*/
const handleCleanState = () => {
setFormValues({});
handleModalVisible(false);
handleUpdateModalVisible(false);
};
/**
* handle add alert instance
*/
const handleSubmit = async (value: Alert.AlertGroup) => {
await exexuteWithRefreshLoading(async () => {
await handleAddOrUpdate(API_CONSTANTS.ALERT_GROUP, value);
});
handleCleanState();
};
/**
* handle add alert instance
*/
const handleSubmit = async (value: Alert.AlertGroup) => {
await exexuteWithRefreshLoading(async () => {
await handleAddOrUpdate(API_CONSTANTS.ALERT_GROUP, value);
});
handleCleanState();
};
/**
* render right tool bar
*/
const renderToolBar = () => {
return () => [
<Button key={"CreateAlertGroup"} type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined/> {l("button.create")}
</Button>,
];
};
/**
* render right tool bar
*/
const renderToolBar = () => {
return () => [
<Button key={"CreateAlertGroup"} type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined/> {l("button.create")}
</Button>,
];
};
/**
* edit click callback
* @param item
*/
const editClick = (item: Alert.AlertGroup) => {
setFormValues(item);
handleUpdateModalVisible(!updateModalVisible);
};
/**
* edit click callback
* @param item
*/
const editClick = (item: Alert.AlertGroup) => {
setFormValues(item);
handleUpdateModalVisible(!updateModalVisible);
};
/**
* render alert instance action button
* @param item
*/
const renderAlertGroupActionButton = (item: Alert.AlertGroup) => {
return [
<Button
className={"options-button"}
key={"AlertGroupEdit"}
icon={<EditTwoTone/>}
title={l("button.edit")}
onClick={() => editClick(item)}
/>,
<Button
className={"options-button"}
key={"DeleteAlertGroupIcon"}
icon={<DangerDeleteIcon/>}
onClick={() => handleDeleteSubmit(item.id)}
/>,
];
};
/**
* render alert instance action button
* @param item
*/
const renderAlertGroupActionButton = (item: Alert.AlertGroup) => {
return [
<Button
className={"options-button"}
key={"AlertGroupEdit"}
icon={<EditTwoTone/>}
title={l("button.edit")}
onClick={() => editClick(item)}
/>,
<Button
className={"options-button"}
key={"DeleteAlertGroupIcon"}
icon={<DangerDeleteIcon/>}
onClick={() => handleDeleteSubmit(item.id)}
/>,
];
};
/**
* render alert instance action button
* @param item
*/
const renderAlertGroupContent = (item: Alert.AlertGroup) => {
const instanceCnt= item.alertInstanceIds.split(",").length || 0
return <>
<Space className={"hidden-overflow"}>
<Switch
key={item.id}
{...SWITCH_OPTIONS()}
checked={item.enabled}
onChange={() => handleEnable(item)}
/>
<Tag color="warning">
{l("rc.ag.alertCount", "", {count: instanceCnt})}
</Tag>
</Space>
</>;
};
/**
* render alert instance action button
* @param item
*/
const renderAlertGroupContent = (item: Alert.AlertGroup) => {
const instanceCnt = item.alertInstanceIds.split(",").length || 0
return <>
<Space className={"hidden-overflow"}>
<Switch
key={item.id}
{...SWITCH_OPTIONS()}
checked={item.enabled}
onChange={() => handleEnable(item)}
/>
<Tag color="warning">
{l("rc.ag.alertCount", "", {count: instanceCnt})}
</Tag>
</Space>
</>;
};
/**
* render alert instance sub title
* @param item
*/
const renderAlertGroupSubTitle = (item: Alert.AlertGroup) => {
return (
<Descriptions size={"small"} layout={"vertical"} column={1}>
<DescriptionsItem
className={"hidden-overflow"}
key={item.id}
>
<Tooltip key={item.id} title={item.name}>
<Tag color="success">{item.name}</Tag>
</Tooltip>
</DescriptionsItem>
</Descriptions>
);
};
/**
* render alert instance sub title
* @param item
*/
const renderAlertGroupSubTitle = (item: Alert.AlertGroup) => {
return (
<Descriptions size={"small"} layout={"vertical"} column={1}>
<DescriptionsItem
className={"hidden-overflow"}
key={item.id}
>
<Tooltip key={item.id} title={item.name}>
<Tag color="success">{item.name}</Tag>
</Tooltip>
</DescriptionsItem>
</Descriptions>
);
};
/**
* render data source
*/
const renderDataSource = alertGroupList.map((item: Alert.AlertGroup) => ({
subTitle: renderAlertGroupSubTitle(item),
actions: renderAlertGroupActionButton(item),
avatar: getAlertIcon(ALERT_TYPE.GROUP, 60),
content: renderAlertGroupContent(item),
}));
/**
* render data source
*/
const renderDataSource = alertGroupList.map((item: Alert.AlertGroup) => ({
subTitle: renderAlertGroupSubTitle(item),
actions: renderAlertGroupActionButton(item),
avatar: getAlertIcon(ALERT_TYPE.GROUP, 60),
content: renderAlertGroupContent(item),
}));
return (
<PageContainer title={false}>
{/* alert group list */}
<ProList<Alert.AlertGroup>
{...PROTABLE_OPTIONS_PUBLIC}
{...PRO_LIST_CARD_OPTIONS as any}
actionRef={actionRef}
loading={loading}
headerTitle={l("rc.ag.management")}
toolBarRender={renderToolBar()}
dataSource={renderDataSource}
/>
return (
<PageContainer title={false}>
{/* alert group list */}
<ProList<Alert.AlertGroup>
{...PROTABLE_OPTIONS_PUBLIC}
{...PRO_LIST_CARD_OPTIONS as any}
actionRef={actionRef}
loading={loading}
headerTitle={l("rc.ag.management")}
toolBarRender={renderToolBar()}
dataSource={renderDataSource}
/>
<AlertGroupForm
onSubmit={handleSubmit}
onCancel={handleCleanState}
modalVisible={modalVisible}
values={{}}
/>
{updateModalVisible &&
<AlertGroupForm
onSubmit={handleSubmit}
onCancel={handleCleanState}
modalVisible={updateModalVisible}
values={formValues}
/>
}
<AlertGroupForm
onSubmit={handleSubmit}
onCancel={handleCleanState}
modalVisible={modalVisible}
values={{}}
/>
<AlertGroupForm
onSubmit={handleSubmit}
onCancel={handleCleanState}
modalVisible={updateModalVisible}
values={formValues}
/>
</PageContainer>
);
</PageContainer>
);
};
export default connect()(AlertGroupTableList);
......@@ -21,7 +21,7 @@
import React, {useEffect} from "react";
import {Form, Modal} from "antd";
import {FormContextValue} from "@/components/Context/FormContext";
import {FORM_LAYOUT_PUBLIC, NORMAL_MODAL_OPTIONS} from "@/services/constants";
import {NORMAL_MODAL_OPTIONS} from "@/services/constants";
import {l} from "@/utils/intl";
import {Document} from "@/types/RegCenter/data";
import DocumentForm from "@/pages/RegCenter/Document/components/DocumentModal/DocumentForm";
......
......@@ -18,12 +18,9 @@
*/
import {Button, Drawer, Popconfirm, Space, Switch} from 'antd';
import React, {useRef, useState} from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import type {ActionType, ProColumns} from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import ProDescriptions from '@ant-design/pro-descriptions';
import {l} from "@/utils/intl";
import {Document} from "@/types/RegCenter/data";
import {queryList} from "@/services/api";
......@@ -63,7 +60,14 @@ const DocumentTableList: React.FC = () => {
handleModalVisible(false);
handleUpdateModalVisible(false);
setDrawerOpen(false);
setFormValues({});
}
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
setLoading(false);
handleCancel();
actionRef.current?.reload?.();
}
/**
......@@ -71,8 +75,9 @@ const DocumentTableList: React.FC = () => {
* @param id
*/
const handleDeleteSubmit = async (id: number) => {
await handleRemoveById(API_CONSTANTS.DOCUMENT_DELETE, id);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await handleRemoveById(API_CONSTANTS.DOCUMENT_DELETE, id);
})
}
/**
......@@ -80,10 +85,9 @@ const DocumentTableList: React.FC = () => {
* @param value
*/
const handleChangeEnable = async (value: Partial<Document>) => {
setLoading(true);
await updateEnabled(API_CONSTANTS.DOCUMENT_ENABLE, {id: value.id});
setLoading(false);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await updateEnabled(API_CONSTANTS.DOCUMENT_ENABLE, {id: value.id});
})
};
......@@ -92,9 +96,9 @@ const DocumentTableList: React.FC = () => {
* @param value
*/
const handleAddOrUpdateSubmit = async (value: Partial<Document>) => {
await handleAddOrUpdate(API_CONSTANTS.DOCUMENT, value);
handleCancel();
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await handleAddOrUpdate(API_CONSTANTS.DOCUMENT, value);
})
}
const handleClickEdit = (record: Partial<Document>) => {
......@@ -178,7 +182,8 @@ const DocumentTableList: React.FC = () => {
filterMultiple: false,
valueEnum: STATUS_ENUM(),
render: (_, record) => {
return <EnableSwitchBtn key={`${record.id}_enable`} disabled={drawerOpen} record={record} onChange={() => handleChangeEnable(record)}/>
return <EnableSwitchBtn key={`${record.id}_enable`} disabled={drawerOpen} record={record}
onChange={() => handleChangeEnable(record)}/>
},
},
{
......@@ -229,14 +234,12 @@ const DocumentTableList: React.FC = () => {
values={{}}
/>
{/*UPDATED*/}
{formValues && Object.keys(formValues).length &&
<DocumentModalForm
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
}
<DocumentModalForm
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
{/*DRAWER*/}
<DocumentDrawer onCancel={() => handleCancel()} modalVisible={drawerOpen} values={formValues}
columns={columns}/>
......
......@@ -86,7 +86,7 @@ export const CodeContent: React.FC<CodeContentProps> = (props) => {
} else if (code === "" || code === null) {
return <Empty className={"code-content-empty"} description={l("rc.gp.codeTree.clickShow")}/>
} else {
return <CodeShow {...CodeEditProps} language={getLanguage()} code={code}/>
return <CodeShow {...CodeEditProps} language={getLanguage()} showFloatButton code={code}/>
}
}
......
......@@ -19,7 +19,7 @@
import React from "react";
import {PageLoading} from "@ant-design/pro-components";
import {buildTreeData} from "@/pages/RegCenter/GitProject/components/CodeTree/function";
import {Tree} from "antd";
import {Empty, Tree} from "antd";
import {GitProjectTreeNode} from "@/types/RegCenter/data";
/**
......@@ -45,11 +45,11 @@ export const SiderTree: React.FC<SiderTreeProps> = (props) => {
*/
return <>
{loading ? <PageLoading/> :
<DirectoryTree
multiple
onSelect={(_, info) => onNodeClick(info)}
treeData={buildTreeData(treeData)}
/>
(treeData.length > 0) ?
<DirectoryTree
onSelect={(_, info) => onNodeClick(info)}
treeData={buildTreeData(treeData)}
/> : <Empty className={"code-content-empty"}/>
}
</>;
};
......@@ -23,7 +23,7 @@ import {folderSeparator, renderIcon} from "@/utils/function";
* @param data
* @returns {any}
*/
export const buildTreeData = (data: any) => data?.map((item: any) => {
export const buildTreeData = (data: any): any => data?.map((item: any) => {
// build key
let buildKey = item.path + folderSeparator() + item.name;
......@@ -34,7 +34,7 @@ export const buildTreeData = (data: any) => data?.map((item: any) => {
isLeaf: !item.leaf,
name: item.name,
parentId: item.path,
icon: renderIcon(item, ".", item.leaf),
icon: renderIcon(item.name, ".", item.leaf),
content: item.content,
path: item.path,
title: item.name,
......@@ -46,7 +46,7 @@ export const buildTreeData = (data: any) => data?.map((item: any) => {
isLeaf: !item.leaf,
name: item.name,
parentId: item.path,
icon: renderIcon(item, ".", item.leaf),
icon: renderIcon(item.name, ".", item.leaf),
content: item.content,
path: item.path,
title: item.name,
......
......@@ -41,7 +41,7 @@ export const CodeTree: React.FC<CodeTreeProps> = (props) => {
cancelText={l("button.close")}
okButtonProps={{style: {display: "none"}}}
>
{modalVisible && <CodeTreeShow values={values}/>}
<CodeTreeShow values={values}/>
</Modal>
</>;
};
......@@ -54,11 +54,6 @@ import {EditBtn} from "@/components/CallBackButton/EditBtn";
import {PopconfirmDeleteBtn} from "@/components/CallBackButton/PopconfirmDeleteBtn";
import {EnableSwitchBtn} from "@/components/CallBackButton/EnableSwitchBtn";
import {ShowLogBtn} from "@/components/CallBackButton/ShowLogBtn";
import {
BuildStepOfCodeType,
JavaSteps,
PythonSteps
} from "@/pages/RegCenter/GitProject/components/BuildSteps/constants";
const ProjectProTable: React.FC = () => {
......@@ -90,7 +85,7 @@ const ProjectProTable: React.FC = () => {
* @returns {Promise<void>}
*/
const handleChangeEnable = async (value: Partial<GitProject>) => {
await executeAndCallback(() => updateEnabled(API_CONSTANTS.GIT_PROJECT_ENABLE, {id: value.id}));
await executeAndCallback(async () => await updateEnabled(API_CONSTANTS.GIT_PROJECT_ENABLE, {id: value.id}));
};
......@@ -115,22 +110,19 @@ const ProjectProTable: React.FC = () => {
};
/**
* build modal visible,when build success, set build modal visible to step modal visible
* @param {Partial<GitProject>} value
* @returns {Promise<void>}
*/
const handleBuild = async (value: Partial<GitProject>) => {
setLoading(true);
await setFormValues(value);
const result = await handlePutDataByParams(API_CONSTANTS.GIT_PROJECT_BUILD, l("rc.gp.building"), {id: value.id});
if (result) {
await handleBuildVisible(true);
// todo : build success, set build modal visible and set build steps
}
setLoading(false);
await executeAndCallback(async () => {
const result = await handlePutDataByParams(API_CONSTANTS.GIT_PROJECT_BUILD, l("rc.gp.building"), {id: value.id});
if (result) {
handleBuildVisible(true);
// todo : build success, set build modal visible and set build steps
}
});
};
/**
......@@ -150,7 +142,7 @@ const ProjectProTable: React.FC = () => {
* @returns {Promise<void>}
*/
const handleDeleteSubmit = async (id: number) => {
await executeAndCallback(() => handleRemoveById(API_CONSTANTS.GIT_PROJECT_DELETE, id));
await executeAndCallback(async () => await handleRemoveById(API_CONSTANTS.GIT_PROJECT_DELETE, id));
};
/**
......@@ -174,6 +166,7 @@ const ProjectProTable: React.FC = () => {
title: l("rc.gp.url"),
dataIndex: "url",
copyable: true,
ellipsis: true,
},
{
title: l("rc.gp.codeType"),
......@@ -300,22 +293,19 @@ const ProjectProTable: React.FC = () => {
columns={columns}
/>
{/* added modal form */}
{modalVisible &&
<ProjectModal onCancel={handleCancel} onSubmit={(value) => handleAddOrUpdateSubmit(value)}
modalVisible={modalVisible} values={{}}/>}
<ProjectModal onCancel={handleCancel} onSubmit={(value) => handleAddOrUpdateSubmit(value)}
modalVisible={modalVisible} values={{}}/>
{/* modify modal form */}
{updateModalVisible &&
<ProjectModal onCancel={handleCancel} onSubmit={(value) => handleAddOrUpdateSubmit(value)}
modalVisible={updateModalVisible}
values={formValues}/>}
<ProjectModal onCancel={handleCancel} onSubmit={(value) => handleAddOrUpdateSubmit(value)}
modalVisible={updateModalVisible}
values={formValues}/>
{/* build steps modal */}
{formValues && <BuildSteps onCancel={handleCancel} modalVisible={buildModalVisible}
{buildModalVisible && <BuildSteps onCancel={handleCancel} modalVisible={buildModalVisible}
values={formValues}/>}
{/* show build log modal */}
{logModalVisible && <ShowLog modalVisible={logModalVisible} onCancel={handleCancel} values={formValues}/>}
{logModalVisible && <ShowLog modalVisible={logModalVisible} onCancel={handleCancel} values={formValues}/>}
{/* show code tree modal */}
{codeTreeModalVisible &&
<CodeTree modalVisible={codeTreeModalVisible} onCancel={handleCancel} values={formValues}/>}
<CodeTree modalVisible={codeTreeModalVisible} onCancel={handleCancel} values={formValues}/>
</>;
};
export default ProjectProTable;
......@@ -22,8 +22,7 @@ import {Modal} from "antd";
import {l} from "@/utils/intl";
import {GitProject} from "@/types/RegCenter/data";
import React, {useEffect} from "react";
import {getData} from "@/services/api";
import {getDataByParams, handleData} from "@/services/BusinessCrud";
import {handleData} from "@/services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants";
type ShowLogProps = {
......@@ -86,7 +85,6 @@ export const ShowLog: React.FC<ShowLogProps> = (props) => {
code={log}
showFloatButton={true}
refreshLogCallback={queryAllStepLogs}
enableTimer={true}
/>
</Modal>
);
......
......@@ -49,16 +49,32 @@ const GlobalVarProTable = () => {
const [loading, setLoading] = useState<boolean>(false);
const [drawerOpen, setDrawerOpen] = useState<boolean>(false);
/**
* handle cancel all
*/
const handleCancel = () => {
handleModalVisible(false);
handleUpdateModalVisible(false);
setDrawerOpen(false);
setFormValues({});
}
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
setLoading(false);
handleCancel();
actionRef.current?.reload?.();
}
/**
* var enable or disable
* @param value
*/
const handleChangeEnable = async (value: Partial<GlobalVar>) => {
setLoading(true);
await updateEnabled(API_CONSTANTS.GLOBAL_VARIABLE_ENABLE, {id: value.id});
setLoading(false);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await updateEnabled(API_CONSTANTS.GLOBAL_VARIABLE_ENABLE, {id: value.id});
})
};
/**
......@@ -66,20 +82,12 @@ const GlobalVarProTable = () => {
* @param id role id
*/
const handleDeleteSubmit = async (id: number) => {
await handleRemoveById(API_CONSTANTS.GLOBAL_VARIABLE_DELETE, id);
actionRef.current?.reload?.();
await executeAndCallbackRefresh(async () => {
await handleRemoveById(API_CONSTANTS.GLOBAL_VARIABLE_DELETE, id);
})
}
/**
* handle cancel all
*/
const handleCancel = () => {
handleModalVisible(false);
handleUpdateModalVisible(false);
setDrawerOpen(false);
setFormValues({});
}
/**
* handle edit
......@@ -106,11 +114,9 @@ const GlobalVarProTable = () => {
* @returns {Promise<void>}
*/
const handleAddOrUpdateSubmit = async (value: Partial<GlobalVar>) => {
await handleAddOrUpdate(API_CONSTANTS.GLOBAL_VARIABLE, value);
handleCancel();
if (actionRef.current) {
actionRef.current.reload();
}
await executeAndCallbackRefresh(async () => {
await handleAddOrUpdate(API_CONSTANTS.GLOBAL_VARIABLE, value);
})
}
......@@ -208,14 +214,12 @@ const GlobalVarProTable = () => {
values={{}}
/>
{/*update*/}
{formValues && Object.keys(formValues).length &&
<GlobalVarModal
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
}
<GlobalVarModal
onSubmit={(value) => handleAddOrUpdateSubmit(value)}
onCancel={() => handleCancel()}
modalVisible={updateModalVisible}
values={formValues}
/>
{/*drawer render*/}
<GlobalVarDrawer
......
......@@ -262,6 +262,7 @@ export const SWITCH_OPTIONS =() => {
export const DIALECT = {
JAVA: "java",
LOG: "log",
XML: "xml",
MD: "md",
MDX: "mdx",
......
......@@ -21,7 +21,17 @@ import {THEME, CODE_EDIT_THEME} from "@/types/Public/data";
import {editor} from "monaco-editor";
import React, {useEffect, useState} from "react";
import {trim} from "lodash";
import {FileIcon, FolderSvgExpand, JavaSvg, MarkDownSvg, ShellSvg, XMLSvg, YAMLSvg} from "@/components/Icons/CodeLanguageIcon";
import {
FileIcon,
FolderSvgExpand,
JavaSvg,
LogSvg,
MarkDownSvg,
ScalaSvg,
ShellSvg,
XMLSvg,
YAMLSvg
} from "@/components/Icons/CodeLanguageIcon";
import path from "path";
/**
......@@ -158,6 +168,7 @@ export const useSSEBuildArrayData = (url: string) => {
export const getLanguage = (type: string): string => {
switch (type) {
case DIALECT.JAVA:
case DIALECT.LOG:
return DIALECT.JAVA;
case DIALECT.MD:
case DIALECT.MDX:
......@@ -192,6 +203,8 @@ export const getIcon = (type: string) => {
switch (type) {
case DIALECT.JAVA:
return <JavaSvg/>;
case DIALECT.SCALA:
return <ScalaSvg/>;
case DIALECT.MD:
case DIALECT.MDX:
return <MarkDownSvg/>;
......@@ -204,6 +217,8 @@ export const getIcon = (type: string) => {
case DIALECT.BASH:
case DIALECT.CMD:
return <ShellSvg/>;
case DIALECT.LOG:
return <LogSvg/>;
default:
return <FileIcon/>;
}
......
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