Skip to content

Commit 4947f2e

Browse files
committed
feat: support datasource switcher
1 parent bf19217 commit 4947f2e

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/common/datasource/fileSystem/index.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IDataSourceModeConfig } from '../interface';
33
import { haveOCP } from '@/util/env';
44

55
const CloudStorageConfig: IDataSourceModeConfig = {
6+
isFileSystem: true,
67
connection: {
78
address: {
89
items: ['ip'],
@@ -43,10 +44,4 @@ const HUAWEI: Record<ConnectType.OBS, IDataSourceModeConfig> = {
4344
const QCLOUD: Record<ConnectType.COS, IDataSourceModeConfig> = {
4445
[ConnectType.COS]: CloudStorageConfig,
4546
};
46-
if (haveOCP()) {
47-
delete ALIYUN[ConnectType.OSS];
48-
delete AWSS3[ConnectType.S3A];
49-
delete HUAWEI[ConnectType.OBS];
50-
delete QCLOUD[ConnectType.COS];
51-
}
5247
export default { ALIYUN, AWSS3, HUAWEI, QCLOUD };

src/common/datasource/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { ReactComponent as OBSSvg } from '@/svgr/OBS.svg';
4343
import { ReactComponent as DBOBSSvg } from '@/svgr/obs_file.svg';
4444
import { ReactComponent as S3Svg } from '@/svgr/S3.svg';
4545
import { ReactComponent as DBS3Svg } from '@/svgr/S3_file.svg';
46+
import odc from '@/plugins/odc';
4647

4748
export const _types: Map<
4849
IDataSourceType,
@@ -158,6 +159,9 @@ function register(
158159
) {
159160
const connectTypes: ConnectType[] = Object.entries(items)
160161
.map(([key, value]) => {
162+
if (odc.datasourceSupport && !odc.datasourceSupport?.(key as ConnectType, value)) {
163+
return null;
164+
}
161165
if (value?.disable) {
162166
return null;
163167
}

src/common/datasource/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ interface IProcedureConfig {
114114
}
115115

116116
export interface IDataSourceModeConfig {
117+
isFileSystem?: boolean;
117118
priority?: number;
118119
connection: {
119120
address?: {

src/plugins/odc.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { ConnectType } from '@/d.ts';
1718
import defaultConfig from './defaultConfig';
1819
import type { InternalAxiosRequestConfig } from 'axios';
20+
import { IDataSourceModeConfig } from '@/common/datasource/interface';
1921
interface IODCErrorHandle {
2022
(
2123
errCode: string,
@@ -35,6 +37,10 @@ interface IResponseJsonResolver {
3537
(response: Response, json: Record<string, any>): void;
3638
}
3739

40+
interface IDataSourceSupport {
41+
(type: ConnectType, config: IDataSourceModeConfig): boolean;
42+
}
43+
3844
export class ODC {
3945
public ODCErrorHandle: Set<IODCErrorHandle> = new Set();
4046

@@ -50,6 +56,8 @@ export class ODC {
5056

5157
public responseJsonResolver: IResponseJsonResolver;
5258

59+
public datasourceSupport: IDataSourceSupport;
60+
5361
public addErrorHandle(handle: IODCErrorHandle) {
5462
this.ODCErrorHandle.add(handle);
5563
}
@@ -61,6 +69,9 @@ export class ODC {
6169
public setResponseJsonResolve(handle: IResponseJsonResolver) {
6270
this.responseJsonResolver = handle;
6371
}
72+
public setDataSourceSupport(handle: IDataSourceSupport) {
73+
this.datasourceSupport = handle;
74+
}
6475
public appConfig: Partial<typeof defaultConfig> = defaultConfig;
6576
}
6677

0 commit comments

Comments
 (0)