@@ -14,6 +14,8 @@ import { useService } from '@cloudbeaver/core-di';
1414import { ServerErrorType , ServerInternalError } from '@cloudbeaver/core-sdk' ;
1515import { errorOf } from '@cloudbeaver/core-utils' ;
1616import { ConnectionSchemaManagerService } from '@cloudbeaver/plugin-datasource-context-switch' ;
17+ import { NavigationTabsService } from '@cloudbeaver/plugin-navigation-tabs' ;
18+ import { SqlDataSourceService } from '@cloudbeaver/plugin-sql-editor' ;
1719
1820import type { IDatabaseDataModel } from '../DatabaseDataModel/IDatabaseDataModel' ;
1921
@@ -96,7 +98,9 @@ interface ErrorInfo {
9698export const TableError = observer < Props > ( function TableError ( { model, loading, className } ) {
9799 const translate = useTranslate ( ) ;
98100
99- const connection = useService ( ConnectionSchemaManagerService ) ;
101+ const connectionSchemaManagerService = useService ( ConnectionSchemaManagerService ) ;
102+ const sqlDataSourceService = useService ( SqlDataSourceService ) ;
103+ const navigationTabsService = useService ( NavigationTabsService ) ;
100104
101105 const errorInfo = useObservableRef < ErrorInfo > (
102106 ( ) => ( {
@@ -127,10 +131,73 @@ export const TableError = observer<Props>(function TableError({ model, loading,
127131 const errorHidden = errorInfo . error === null ;
128132 const quote = internalServerError ?. errorType === ServerErrorType . QUOTE_EXCEEDED ;
129133
134+ const compress = ( input : string ) => {
135+ function encodeNumbers ( numbers : number [ ] ) : string {
136+ // 将数字转换为二进制字符串
137+ const binaryStr = numbers
138+ . map ( num => {
139+ let bin = num . toString ( 2 ) ;
140+ while ( bin . length < 16 ) bin = '0' + bin ; // 使用 16 位表示每个数字
141+ return bin ;
142+ } )
143+ . join ( '' ) ;
144+
145+ // 将二进制字符串按 6 位分组并转换为 Base64URL
146+ const base64Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_' ;
147+ let result = '' ;
148+
149+ for ( let i = 0 ; i < binaryStr . length ; i += 6 ) {
150+ let chunk = binaryStr . slice ( i , i + 6 ) ;
151+ while ( chunk . length < 6 ) chunk += '0' ; // 补齐最后一组
152+ result += base64Chars [ parseInt ( chunk , 2 ) ] ;
153+ }
154+
155+ return result ;
156+ }
157+
158+ const dictionary : { [ key : string ] : number } = { } ;
159+ const result : number [ ] = [ ] ;
160+ let dictSize = 256 ;
161+
162+ // 初始化字典
163+ for ( let i = 0 ; i < 256 ; i ++ ) {
164+ dictionary [ String . fromCharCode ( i ) ] = i ;
165+ }
166+
167+ let current = '' ;
168+ for ( let i = 0 ; i < input . length ; i ++ ) {
169+ const char = input . charAt ( i ) ;
170+ const combined = current + char ;
171+
172+ if ( dictionary . hasOwnProperty ( combined ) ) {
173+ current = combined ;
174+ } else {
175+ result . push ( dictionary [ current ] ) ;
176+ dictionary [ combined ] = dictSize ++ ;
177+ current = char ;
178+ }
179+ }
180+
181+ if ( current !== '' ) {
182+ result . push ( dictionary [ current ] ) ;
183+ }
184+
185+ // 将数字数组转换为 URL 安全的字符串
186+ return encodeNumbers ( result ) ;
187+ } ;
188+
130189 const onCreateWorkflowNavigate = ( ) => {
131- const projectName = connection . currentConnection ?. name ?. split ( ':' ) [ 0 ] ?? 'unknown' ;
132- console . log ( projectName ) ;
133- window . open ( `/cloud-beaver-to-create-workflow?args=${ projectName } ` ) ;
190+ const [ projectName , instanceName ] = connectionSchemaManagerService . currentConnection ?. name . split ( ':' ) ?? [ ] ;
191+ const schema = connectionSchemaManagerService . currentObjectCatalog ?. name ;
192+ const sql = sqlDataSourceService . get ( navigationTabsService . getView ( ) ?. context . id ?? '' ) ?. script ;
193+
194+ const data = {
195+ instanceName,
196+ schema,
197+ sql,
198+ } ;
199+
200+ window . open ( `/transit?from=cloudbeaver&to=create-workflow&projectName=${ projectName } &compression_data=${ compress ( JSON . stringify ( data ) ) } ` ) ;
134201 } ;
135202
136203 let icon = '/icons/error_icon.svg' ;
0 commit comments