1- import {
2- COMPONENT_WORKSPACE_CAPABILITIES ,
3- K8S_PROTOCOLS
4- } from "~/shared/connectors/capabilities" ;
1+ import { COMPONENT_WORKSPACE_CAPABILITIES } from "~/shared/connectors/capabilities" ;
52import { useUserInfoStore } from "~/store/modules/userInfo" ;
63
74export {
@@ -33,27 +30,25 @@ interface ConnectMethodsResponse {
3330const connectMethodsCache = new Map < string , ConnectMethodsResponse > ( ) ;
3431const fetchPromise = new Map < string , Promise < ConnectMethodsResponse > > ( ) ;
3532
33+ const isWebIframeMethod = ( method : ConnectMethod ) => {
34+ return method . type === "web" || [ "koko" , "lion" , "chen" , "tinker" , "default" ] . includes ( method . component ) ;
35+ } ;
36+
3637const normalizeWebConnectMethods = ( methods : ConnectMethodsResponse ) : ConnectMethodsResponse => {
3738 const normalized : ConnectMethodsResponse = { ...methods } ;
3839
3940 Object . keys ( normalized ) . forEach ( ( key ) => {
4041 const value = normalized [ key ] ;
4142 if ( ! Array . isArray ( value ) ) return ;
4243
43- // 原远端 iframe 方式统一命名为 Web iframe
44- const renamed = value . map ( ( method ) => {
45- const isWebSurface = method . type === "web" || [ "koko" , "lion" , "chen" , "tinker" , "default" ] . includes ( method . component ) ;
46- return isWebSurface
47- ? { ...method , label : "Web iframe" }
48- : method ;
49- } ) ;
44+ const normalizedMethods = [ ...value ] ;
5045
51- const kokoWebIndex = renamed . findIndex (
46+ const kokoWebIndex = normalizedMethods . findIndex (
5247 ( method ) => method . type === "web" && [ "koko" , "default" ] . includes ( method . component )
5348 ) ;
5449
5550 if ( kokoWebIndex !== - 1 ) {
56- const origin = renamed [ kokoWebIndex ] ! ;
51+ const origin = normalizedMethods [ kokoWebIndex ] ! ;
5752 const declaredMethods = COMPONENT_WORKSPACE_CAPABILITIES
5853 . filter ( ( item ) => item . component === "koko" && item . protocols . includes ( key ) )
5954 . flatMap ( ( item ) =>
@@ -66,17 +61,16 @@ const normalizeWebConnectMethods = (methods: ConnectMethodsResponse): ConnectMet
6661 ) ;
6762
6863 if ( declaredMethods . length ) {
69- const replaceOrigin = key === "sftp" || K8S_PROTOCOLS . has ( key ) ;
70- renamed . splice ( kokoWebIndex , replaceOrigin ? 1 : 0 , ...declaredMethods ) ;
64+ normalizedMethods . splice ( kokoWebIndex , 0 , ...declaredMethods ) ;
7165 }
7266 }
7367
74- const lionWebIndex = renamed . findIndex (
68+ const lionWebIndex = normalizedMethods . findIndex (
7569 ( method ) => method . type === "web" && [ "lion" , "tinker" ] . includes ( method . component )
7670 ) ;
7771
7872 if ( lionWebIndex !== - 1 ) {
79- const origin = renamed [ lionWebIndex ] ! ;
73+ const origin = normalizedMethods [ lionWebIndex ] ! ;
8074 const declaredMethods = COMPONENT_WORKSPACE_CAPABILITIES
8175 . filter ( ( item ) => item . component === "lion" && item . protocols . includes ( key ) )
8276 . flatMap ( ( item ) =>
@@ -89,16 +83,16 @@ const normalizeWebConnectMethods = (methods: ConnectMethodsResponse): ConnectMet
8983 ) ;
9084
9185 if ( declaredMethods . length ) {
92- renamed . splice ( lionWebIndex , 1 , ...declaredMethods ) ;
86+ normalizedMethods . splice ( lionWebIndex , 0 , ...declaredMethods ) ;
9387 }
9488 }
9589
96- const chenWebIndex = renamed . findIndex (
90+ const chenWebIndex = normalizedMethods . findIndex (
9791 ( method ) => method . type === "web" && method . component === "chen"
9892 ) ;
9993
10094 if ( chenWebIndex !== - 1 ) {
101- const origin = renamed [ chenWebIndex ] ! ;
95+ const origin = normalizedMethods [ chenWebIndex ] ! ;
10296 const declaredMethods = COMPONENT_WORKSPACE_CAPABILITIES
10397 . filter ( ( item ) => item . component === "chen" && item . protocols . includes ( key ) )
10498 . flatMap ( ( item ) =>
@@ -111,11 +105,11 @@ const normalizeWebConnectMethods = (methods: ConnectMethodsResponse): ConnectMet
111105 ) ;
112106
113107 if ( declaredMethods . length ) {
114- renamed . splice ( chenWebIndex , 1 , ...declaredMethods ) ;
108+ normalizedMethods . splice ( chenWebIndex , 0 , ...declaredMethods ) ;
115109 }
116110 }
117111
118- normalized [ key ] = renamed ;
112+ normalized [ key ] = normalizedMethods . filter ( ( method ) => method . origin_value || ! isWebIframeMethod ( method ) ) ;
119113 } ) ;
120114
121115 return normalized ;
@@ -158,7 +152,7 @@ export const useConnectMethods = () => {
158152 const getMethodsForProtocol = async ( protocol : string ) : Promise < ConnectMethod [ ] > => {
159153 const allMethods = await fetchConnectMethods ( ) ;
160154 const protocolMethods = allMethods [ protocol ] || [ ] ;
161- // 与 Luna 对齐:连接方法以服务端返回为准,仅过滤 disabled。
155+ // Web iframe is used only as the backend method source for injected workspace methods.
162156 return protocolMethods . filter ( ( method ) => ! method . disabled ) ;
163157 } ;
164158
0 commit comments