|
5 | 5 | * Licensed under the Apache License, Version 2.0.
|
6 | 6 | * you may not use this file except in compliance with the License.
|
7 | 7 | */
|
| 8 | +import { compressToEncodedURIComponent } from 'lz-string'; |
8 | 9 | import { observable } from 'mobx';
|
9 | 10 | import { observer } from 'mobx-react-lite';
|
10 | 11 | import styled, { css, use } from 'reshadow';
|
11 | 12 |
|
12 | 13 | import { Button, IconOrImage, useErrorDetails, useObservableRef, useStateDelay, useTranslate } from '@cloudbeaver/core-blocks';
|
| 14 | +import { useService } from '@cloudbeaver/core-di'; |
13 | 15 | import { ServerErrorType, ServerInternalError } from '@cloudbeaver/core-sdk';
|
14 | 16 | import { errorOf } from '@cloudbeaver/core-utils';
|
| 17 | +import { ConnectionSchemaManagerService } from '@cloudbeaver/plugin-datasource-context-switch'; |
| 18 | +import { NavigationTabsService } from '@cloudbeaver/plugin-navigation-tabs'; |
| 19 | +import { SqlDataSourceService } from '@cloudbeaver/plugin-sql-editor'; |
15 | 20 |
|
16 | 21 | import type { IDatabaseDataModel } from '../DatabaseDataModel/IDatabaseDataModel';
|
17 | 22 |
|
@@ -93,6 +98,11 @@ interface ErrorInfo {
|
93 | 98 |
|
94 | 99 | export const TableError = observer<Props>(function TableError({ model, loading, className }) {
|
95 | 100 | const translate = useTranslate();
|
| 101 | + |
| 102 | + const connectionSchemaManagerService = useService(ConnectionSchemaManagerService); |
| 103 | + const sqlDataSourceService = useService(SqlDataSourceService); |
| 104 | + const navigationTabsService = useService(NavigationTabsService); |
| 105 | + |
96 | 106 | const errorInfo = useObservableRef<ErrorInfo>(
|
97 | 107 | () => ({
|
98 | 108 | error: null,
|
@@ -122,6 +132,24 @@ export const TableError = observer<Props>(function TableError({ model, loading,
|
122 | 132 | const errorHidden = errorInfo.error === null;
|
123 | 133 | const quote = internalServerError?.errorType === ServerErrorType.QUOTE_EXCEEDED;
|
124 | 134 |
|
| 135 | + const onCreateWorkflowNavigate = () => { |
| 136 | + const [projectName, instanceName] = connectionSchemaManagerService.currentConnection?.name.split(':') ?? []; |
| 137 | + const schema = connectionSchemaManagerService.currentObjectCatalog?.name; |
| 138 | + const sql = sqlDataSourceService.get(navigationTabsService.getView()?.context.id ?? '')?.script; |
| 139 | + |
| 140 | + const data = { |
| 141 | + instanceName, |
| 142 | + schema, |
| 143 | + sql, |
| 144 | + }; |
| 145 | + |
| 146 | + window.open( |
| 147 | + `/transit?from=cloudbeaver&to=create_workflow&project_name=${projectName}&compression_data=${compressToEncodedURIComponent( |
| 148 | + JSON.stringify(data), |
| 149 | + )}`, |
| 150 | + ); |
| 151 | + }; |
| 152 | + |
125 | 153 | let icon = '/icons/error_icon.svg';
|
126 | 154 |
|
127 | 155 | if (quote) {
|
@@ -157,6 +185,9 @@ export const TableError = observer<Props>(function TableError({ model, loading,
|
157 | 185 | <Button type="button" mod={['unelevated']} onClick={onRetry}>
|
158 | 186 | {translate('ui_processing_retry')}
|
159 | 187 | </Button>
|
| 188 | + <Button type="button" mod={['unelevated']} onClick={onCreateWorkflowNavigate}> |
| 189 | + {translate('ui_create_workflow')} |
| 190 | + </Button> |
160 | 191 | </controls>
|
161 | 192 | </error>,
|
162 | 193 | );
|
|
0 commit comments