@@ -2,7 +2,7 @@ import React from 'react';
22
33import { ArrowDownToLine , ArrowUpRightFromSquare , ChevronDown } from '@gravity-ui/icons' ;
44import type { ButtonProps } from '@gravity-ui/uikit' ;
5- import { Button , DropdownMenu } from '@gravity-ui/uikit' ;
5+ import { Button , DropdownMenu , Tooltip } from '@gravity-ui/uikit' ;
66
77import { planToSvgApi } from '../../../../../../store/reducers/planToSvg' ;
88import type { QueryPlan , ScriptPlan } from '../../../../../../types/api/query' ;
@@ -40,26 +40,33 @@ export function PlanToSvgButton({plan, database}: PlanToSvgButtonProps) {
4040 return url ;
4141 } )
4242 . catch ( ( err ) => {
43- setError ( JSON . stringify ( err ) ) ;
44- throw err ;
43+ const errorMessage = err . data ?. message || err . message || JSON . stringify ( err ) ;
44+ setError ( errorMessage ) ;
45+ return null ;
4546 } ) ;
4647 } , [ database , getPlanToSvg , plan , blobUrl ] ) ;
4748
4849 const handleOpenInNewTab = React . useCallback ( ( ) => {
4950 handleGetSvg ( ) . then ( ( url ) => {
50- window . open ( url , '_blank' ) ;
51+ if ( url ) {
52+ window . open ( url , '_blank' ) ;
53+ }
5154 } ) ;
55+ return ;
5256 } , [ handleGetSvg ] ) ;
5357
5458 const handleDownload = React . useCallback ( ( ) => {
5559 handleGetSvg ( ) . then ( ( url ) => {
5660 const link = document . createElement ( 'a' ) ;
57- link . href = url ;
58- link . download = 'query-plan.svg' ;
59- document . body . appendChild ( link ) ;
60- link . click ( ) ;
61- document . body . removeChild ( link ) ;
61+ if ( url ) {
62+ link . href = url ;
63+ link . download = 'query-plan.svg' ;
64+ document . body . appendChild ( link ) ;
65+ link . click ( ) ;
66+ document . body . removeChild ( link ) ;
67+ }
6268 } ) ;
69+ return ;
6370 } , [ handleGetSvg ] ) ;
6471
6572 React . useEffect ( ( ) => {
@@ -85,19 +92,21 @@ export function PlanToSvgButton({plan, database}: PlanToSvgButtonProps) {
8592
8693 const renderSwitcher = ( props : ButtonProps ) => {
8794 return (
88- < Button
89- view = { getButtonView ( error , isLoading ) }
90- loading = { isLoading }
91- disabled = { isLoading }
92- { ...props }
93- >
94- { i18n ( 'text_plan-svg' ) }
95- < Button . Icon >
96- < ChevronDown />
97- </ Button . Icon >
98- </ Button >
95+ < Tooltip content = { error ? i18n ( 'text_error-plan-svg' , { error} ) : i18n ( 'text_plan-svg' ) } >
96+ < Button
97+ view = { getButtonView ( error , isLoading ) }
98+ loading = { isLoading }
99+ disabled = { isLoading }
100+ { ...props }
101+ >
102+ { i18n ( 'text_plan-svg' ) }
103+ < Button . Icon >
104+ < ChevronDown />
105+ </ Button . Icon >
106+ </ Button >
107+ </ Tooltip >
99108 ) ;
100109 } ;
101110
102- return < DropdownMenu renderSwitcher = { renderSwitcher } items = { items } /> ;
111+ return < DropdownMenu renderSwitcher = { renderSwitcher } items = { items } disabled = { Boolean ( error ) } /> ;
103112}
0 commit comments