From 411a17476062ef27e5cd6bf59104a451bd4ccfc9 Mon Sep 17 00:00:00 2001 From: Chareice Date: Fri, 2 Feb 2024 12:04:55 +0800 Subject: [PATCH] chore: reloading status --- .../src/server/models/data-source.ts | 15 +++++++++++++-- .../src/server/plugin.ts | 7 ++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/models/data-source.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/models/data-source.ts index b3e3624819..04aea9d3a6 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/models/data-source.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/models/data-source.ts @@ -52,7 +52,11 @@ export class DataSourceModel extends Model { const pluginDataSourceManagerServer = app.pm.get('data-source-manager') as PluginDataSourceManagerServer; - pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] = 'loading'; + if (pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] === 'loaded') { + pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] = 'reloading'; + } else { + pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] = 'loading'; + } const loadRoleIntoDataSource = async (model: DataSourcesRolesModel, dataSource: DataSource) => { const pluginACL: any = app.pm.get('acl'); @@ -108,7 +112,14 @@ export class DataSourceModel extends Model { } catch (e) { app.logger.error(`load data source failed, ${e.message}`); - pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] = 'failed'; + if (pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] === 'loading') { + pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] = 'loading-failed'; + } + + if (pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] === 'reloading') { + pluginDataSourceManagerServer.dataSourceStatus[dataSourceKey] = 'reloading-failed'; + } + pluginDataSourceManagerServer.dataSourceErrors[dataSourceKey] = e; return; } diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts index a60f22e41b..1aee96b391 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/plugin.ts @@ -14,7 +14,7 @@ import { DataSourcesRolesResourcesActionModel } from './models/connections-roles import { DataSourceModel } from './models/data-source'; import lodash from 'lodash'; -type DataSourceState = 'loading' | 'loaded' | 'failed'; +type DataSourceState = 'loading' | 'loaded' | 'loading-failed' | 'reloading' | 'reloading-failed'; export class PluginDataSourceManagerServer extends Plugin { public dataSourceErrors: { @@ -102,9 +102,10 @@ export class PluginDataSourceManagerServer extends Plugin { const dataSourceStatus = this.dataSourceStatus[item.get('key')]; data['status'] = dataSourceStatus; - if (dataSourceStatus === 'failed') { + if (dataSourceStatus === 'loading-failed' || dataSourceStatus === 'reloading-failed') { data['errorMessage'] = this.dataSourceErrors[item.get('key')].message; } + return data; }), ); @@ -129,7 +130,7 @@ export class PluginDataSourceManagerServer extends Plugin { status: dataSourceStatus, }; - if (dataSourceStatus === 'failed') { + if (dataSourceStatus === 'loading-failed' || dataSourceStatus === 'reloading-failed') { item['errorMessage'] = plugin.dataSourceErrors[dataSourceModel.get('key')].message; }