From 09c91b0383272c642e099a4fc1d89e00c013eabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9C=9D=E4=BF=8A?= Date: Mon, 29 Jul 2024 14:07:55 +0800 Subject: [PATCH] PullRequest: 483 Fixes oceanbase/odc#3023 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge branch 'fix/dev-4.3.1-odc-3023 of git@code.alipay.com:oceanbase/oceanbase-developer-center.git into dev-4.3.1 https://code.alipay.com/oceanbase/oceanbase-developer-center/pull_requests/483 Signed-off-by: 晓康 * Fixes oceanbase/odc#3023 --- .../CreateModal/DatabaseQueue.tsx | 31 +++++++++-------- .../components/Template/EditTemplate.tsx | 34 +++++++++++-------- src/page/Project/Database/index.tsx | 2 +- .../ResourceTree/DatabaseTree/index.tsx | 15 ++++---- src/page/Workspace/context/WorkspaceStore.tsx | 2 +- src/store/datasourceStatus.ts | 4 +-- 6 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/component/Task/MutipleAsyncTask/CreateModal/DatabaseQueue.tsx b/src/component/Task/MutipleAsyncTask/CreateModal/DatabaseQueue.tsx index 39943241b..61d10df30 100644 --- a/src/component/Task/MutipleAsyncTask/CreateModal/DatabaseQueue.tsx +++ b/src/component/Task/MutipleAsyncTask/CreateModal/DatabaseQueue.tsx @@ -58,22 +58,25 @@ export const DatabaseQueueSelect: React.FC<{ true, true, ); - setDatabaseOptions( - databaseList?.contents?.map((item) => { - const statusInfo = datasourceStatus.statusMap.get(item?.dataSource?.id); - return { - label: item?.name, - value: item?.id, - environment: item?.environment, - dataSource: item?.dataSource, - existed: item?.existed, - unauthorized: !item?.authorizedPermissionTypes?.includes(DatabasePermissionType.CHANGE), - expired: checkDbExpiredByDataSourceStatus(statusInfo?.status), - }; - }), - ); if (databaseList?.contents?.length) { setDefaultDatasource(databaseList?.contents?.[0]?.dataSource); + await datasourceStatus.asyncUpdateStatus([ + ...new Set(databaseList?.contents?.map((item) => item.dataSource?.id)), + ]); + setDatabaseOptions( + databaseList?.contents?.map((item) => { + const statusInfo = datasourceStatus.statusMap.get(item?.dataSource?.id); + return { + label: item?.name, + value: item?.id, + environment: item?.environment, + dataSource: item?.dataSource, + existed: item?.existed, + unauthorized: !item?.authorizedPermissionTypes?.includes(DatabasePermissionType.CHANGE), + expired: checkDbExpiredByDataSourceStatus(statusInfo?.status), + }; + }), + ); } databaseList?.contents?.forEach((db) => { databaseIdMap.set(db.id, false); diff --git a/src/component/Task/MutipleAsyncTask/components/Template/EditTemplate.tsx b/src/component/Task/MutipleAsyncTask/components/Template/EditTemplate.tsx index 349ba6e80..da44e33ab 100644 --- a/src/component/Task/MutipleAsyncTask/components/Template/EditTemplate.tsx +++ b/src/component/Task/MutipleAsyncTask/components/Template/EditTemplate.tsx @@ -50,21 +50,25 @@ const EditTemplate: React.FC<{ true, true, ); - - setDatabaseOptions( - databaseList?.contents?.map((item) => { - const statusInfo = datasourceStatus.statusMap.get(item?.dataSource?.id); - return { - label: item?.name, - value: item?.id, - environment: item?.environment, - dataSource: item?.dataSource, - existed: item?.existed, - unauthorized: !item?.authorizedPermissionTypes?.includes(DatabasePermissionType.CHANGE), - expired: checkDbExpiredByDataSourceStatus(statusInfo?.status), - }; - }), - ); + if (databaseList?.contents?.length) { + await datasourceStatus.asyncUpdateStatus([ + ...new Set(databaseList?.contents?.map((item) => item?.dataSource?.id)), + ]); + setDatabaseOptions( + databaseList?.contents?.map((item) => { + const statusInfo = datasourceStatus.statusMap.get(item?.dataSource?.id); + return { + label: item?.name, + value: item?.id, + environment: item?.environment, + dataSource: item?.dataSource, + existed: item?.existed, + unauthorized: !item?.authorizedPermissionTypes?.includes(DatabasePermissionType.CHANGE), + expired: checkDbExpiredByDataSourceStatus(statusInfo?.status), + }; + }), + ); + } }; const initTemplate = async (templateId: number) => { const response = await detailTemplate(templateId, login?.organizationId?.toString()); diff --git a/src/page/Project/Database/index.tsx b/src/page/Project/Database/index.tsx index e07f924b3..2b9c45a90 100644 --- a/src/page/Project/Database/index.tsx +++ b/src/page/Project/Database/index.tsx @@ -94,7 +94,7 @@ const Database: React.FC = ({ id, modalStore }) => { true, ); if (res) { - datasourceStatus.asyncUpdateStatus(res?.contents?.map((item) => item?.dataSource?.id)); + await datasourceStatus.asyncUpdateStatus(res?.contents?.map((item) => item?.dataSource?.id)); setData(res?.contents); setTotal(res?.page?.totalElements); } diff --git a/src/page/Workspace/SideBar/ResourceTree/DatabaseTree/index.tsx b/src/page/Workspace/SideBar/ResourceTree/DatabaseTree/index.tsx index 0bc34f93e..1617744dc 100644 --- a/src/page/Workspace/SideBar/ResourceTree/DatabaseTree/index.tsx +++ b/src/page/Workspace/SideBar/ResourceTree/DatabaseTree/index.tsx @@ -45,6 +45,14 @@ const DatabaseTree: React.FC = function ({ openSelectPanel }) { async function reloadDatabase() { await reloadDatabaseList(); } + async function handleDatabase() { + setDatabases(databaseList?.filter((item) => !!item?.authorizedPermissionTypes?.length)); + const ids: Set = new Set(); + databaseList.forEach((d) => { + ids.add(d.dataSource?.id); + }); + await datasourceStatus.asyncUpdateStatus(Array.from(ids)); + } useEffect(() => { if (selectDatasourceId || selectProjectId) { @@ -54,12 +62,7 @@ const DatabaseTree: React.FC = function ({ openSelectPanel }) { useEffect(() => { if (databaseList?.length) { - setDatabases(databaseList?.filter((item) => !!item?.authorizedPermissionTypes?.length)); - const ids: Set = new Set(); - databaseList.forEach((d) => { - ids.add(d.dataSource?.id); - }); - datasourceStatus.asyncUpdateStatus(Array.from(ids)); + handleDatabase(); } }, [databaseList]); diff --git a/src/page/Workspace/context/WorkspaceStore.tsx b/src/page/Workspace/context/WorkspaceStore.tsx index 8051ba67e..6036e2862 100644 --- a/src/page/Workspace/context/WorkspaceStore.tsx +++ b/src/page/Workspace/context/WorkspaceStore.tsx @@ -80,7 +80,7 @@ export default function WorkspaceStore({ children }) { const reloadDatasourceList = useCallback(async () => { const data = await fetchDatasource(); setDatasourceList(data?.contents || []); - datasourceStatus.asyncUpdateStatus(data?.contents?.map((a) => a.id)); + await datasourceStatus.asyncUpdateStatus(data?.contents?.map((a) => a.id)); }, []); const reloadProjectList = useCallback(async () => { diff --git a/src/store/datasourceStatus.ts b/src/store/datasourceStatus.ts index 2e9122465..b605832d1 100644 --- a/src/store/datasourceStatus.ts +++ b/src/store/datasourceStatus.ts @@ -68,13 +68,13 @@ export class DataSourceStatusStore { } } - public asyncUpdateStatus(ids: IDatasource['id'][]) { + public async asyncUpdateStatus(ids: IDatasource['id'][]) { ids?.forEach((id) => { this.queue.add(id); }); if (this.status === 'stop') { this.status = 'running'; - this.fetchStatus(); + await this.fetchStatus(); } }