Unverified Commit d6673b3e authored by Licho's avatar Licho Committed by GitHub

refactor (#2235)

parent ff1ec5bb
......@@ -34,7 +34,6 @@ import {StateType, STUDIO_MODEL} from "@/pages/DataStudio/model";
const DataSourceDetail = (props : any) => {
const navigate = useNavigate();
const {dataSource, backClick , dispatch ,database: { dbData , selectDatabaseId , expandKeys, selectKeys}} = props;
const [loading, setLoading] = useState<boolean>(false);
const [disabled, setDisabled] = useState<boolean>(true);
......@@ -87,35 +86,33 @@ const DataSourceDetail = (props : any) => {
type: STUDIO_MODEL.updateDatabaseSelectKey,
payload: keys
})
if (isLeaf) {
const queryParams = {id: selectDatabaseId , schemaName, tableName};
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: selectDb.type,
id: selectDatabaseId + schemaName + tableName,
breadcrumbLabel: [selectDb.type,selectDb.name].join("/"),
label: schemaName + '.' + tableName ,
params:{ queryParams: queryParams, tableInfo: fullInfo},
type: "metadata"
}
})
}
if (isLeaf) {
setParams({
id: dataSource.id as number,
schemaName,
tableName
});
setDisabled(false);
/**
* get table columns
*/
setTableInfo(fullInfo);
} else {
if (!isLeaf) {
clearState();
return;
}
dispatch({
type: STUDIO_MODEL.addTab,
payload: {
icon: selectDb.type,
id: selectDatabaseId + schemaName + tableName,
breadcrumbLabel: [selectDb.type, selectDb.name].join("/"),
label: schemaName + '.' + tableName,
params: {queryParams: {id: selectDatabaseId, schemaName, tableName}, tableInfo: fullInfo},
type: "metadata"
}
})
setParams({
id: dataSource.id as number,
schemaName,
tableName
});
setDisabled(false);
// get table columns
setTableInfo(fullInfo);
}, []);
......@@ -130,13 +127,11 @@ const DataSourceDetail = (props : any) => {
})
}
/**
* render back button and refresh button
* @return {JSX.Element}
*/
const renderBackButton = () => {
return <>
const renderBackButton =
<DataSourceDetailBackButton>
<Space size={'middle'}>
<Button size={'middle'} icon={<ReloadOutlined spin={loading}/>} type="primary"
......@@ -144,14 +139,12 @@ const DataSourceDetail = (props : any) => {
<Button size={'middle'} icon={<BackwardOutlined/>} type="primary"
onClick={handleBackClick}>{l('button.back')}</Button>
</Space>
</DataSourceDetailBackButton>
</>;
};
</DataSourceDetailBackButton>;
/**
* render
*/
return <>
return (
<ProCard loading={loading} ghost gutter={[16, 16]} split="vertical">
<ProCard hoverable bordered className={'siderTree schemaTree'} colSpan="16%">
{/* tree */}
......@@ -162,14 +155,13 @@ const DataSourceDetail = (props : any) => {
<RightTagsRouter
tableInfo={tableInfo}
queryParams={params}
rightButtons={renderBackButton()}
rightButtons={renderBackButton}
tagDisabled={disabled}
/>
</ProCard>
</ProCard>
</>;
</ProCard>);
};
export default connect(({Studio}: { Studio: StateType }) => ({
database: Studio.database,
}))(DataSourceDetail); ;
}))(DataSourceDetail);
......@@ -61,20 +61,19 @@ const DataSourceTable = () => {
* set list
*/
const queryDataSourceList = async () => {
await queryList(API_CONSTANTS.DATASOURCE).then(res => {
setDataSource(res.data);
});
const res = await queryList(API_CONSTANTS.DATASOURCE);
setDataSource(res.data);
};
/**
* extra callback
* @param callback
*/
const executeAndCallbackRefresh = async (callback: () => void) => {
await setLoading(true);
const executeAndCallbackRefresh = async (callback: () => Promise<void>) => {
setLoading(true);
await callback();
await queryDataSourceList();
await setLoading(false);
setLoading(false);
};
/**
......@@ -87,7 +86,6 @@ const DataSourceTable = () => {
});
};
/**
* handle delete
* @param id
......@@ -187,7 +185,6 @@ const DataSourceTable = () => {
setDetailPage(!detailPage);
} else {
await WarningMessage(l('rc.ds.enter.error'));
return;
}
};
......
......@@ -99,7 +99,7 @@ export const handleAddOrUpdate = async (url: string, params: any, afterCallBack?
const {code, msg} = await addOrUpdateData(url, {...params});
if (code === RESPONSE_CODE.SUCCESS) {
await SuccessMessage(msg);
afterCallBack && afterCallBack();
afterCallBack?.();
} else {
await WarningMessage(msg);
}
......@@ -121,7 +121,7 @@ export const handleRemoveById = async (url: string, id: number, afterCallBack?:
const {code, msg} = await removeById(url, {id});
if (code === RESPONSE_CODE.SUCCESS) {
await SuccessMessage(msg);
afterCallBack && afterCallBack();
afterCallBack?.();
} else {
await WarningMessage(msg);
}
......@@ -178,7 +178,7 @@ export const handleOption = async (url: string, title: string, param: any, after
const result = await postAll(url, param);
if (result.code === RESPONSE_CODE.SUCCESS) {
SuccessMessage(result.msg);
afterCallBack && afterCallBack();
afterCallBack?.();
return result;
} else {
WarningMessage(result.msg);
......@@ -275,7 +275,7 @@ export const handlePutDataByParams = async (url: string, title: string, params:
const {code, msg} = await putData(url, {...params});
if (code === RESPONSE_CODE.SUCCESS) {
await SuccessMessage(msg);
afterCallBack && afterCallBack();
afterCallBack?.();
return true;
} else {
await WarningMessage(msg);
......
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