1- import React , { useEffect , useRef , useState } from 'react' ;
1+ import React , { useCallback , useEffect , useRef , useState } from 'react' ;
22import cn from 'bem-cn-lite' ;
33import MonacoEditor from 'react-monaco-editor' ;
44import { Loader , RadioButton } from '@gravity-ui/uikit' ;
@@ -25,20 +25,6 @@ import {disableFullscreen} from '../../../../store/reducers/fullscreen';
2525
2626const b = cn ( 'kv-query-explain' ) ;
2727
28- const DARK_COLORS = {
29- success : 'rgba(59,201,53,0.75)' ,
30- error : '#bf3230' ,
31- warning : '#cc6810' ,
32- mute : 'rgba(255,255,255,0.15)' ,
33- stroke : 'rgba(255,255,255,0.17)' ,
34- fill : '#313037' ,
35- nodeFill : '#3b3a41' ,
36- nodeShadow : 'rgba(0,0,0,0.2)' ,
37- titleColor : 'rgba(255,255,255,0.7)' ,
38- textColor : 'rgba(255,255,255,0.55)' ,
39- buttonBorderColor : 'rgba(255,255,255,0.07)' ,
40- } ;
41-
4228const EDITOR_OPTIONS = {
4329 automaticLayout : true ,
4430 selectOnLineNumbers : true ,
@@ -64,17 +50,23 @@ const explainOptions = [
6450function GraphRoot ( props ) {
6551 const paranoid = useRef ( ) ;
6652
67- const render = ( ) => {
68- const { data, opts, shapes, version} = props ;
53+ const { data, opts, shapes, version, theme} = props ;
54+
55+ const [ componentTheme , updateComponentTheme ] = useState ( theme ) ;
6956
57+ useEffect ( ( ) => {
58+ updateComponentTheme ( theme ) ;
59+ } , [ theme ] ) ;
60+
61+ const render = useCallback ( ( ) => {
7062 if ( version === explainVersions . v2 ) {
7163 paranoid . current = getTopology ( 'graphRoot' , data , opts , shapes ) ;
7264 paranoid . current . render ( ) ;
7365 } else if ( version === explainVersions . v1 ) {
7466 paranoid . current = getCompactTopology ( 'graphRoot' , data , opts ) ;
7567 paranoid . current . renderCompactTopology ( ) ;
7668 }
77- } ;
69+ } , [ data , opts , shapes , version ] ) ;
7870
7971 useEffect ( ( ) => {
8072 render ( ) ;
@@ -94,7 +86,7 @@ function GraphRoot(props) {
9486 graphRoot . innerHTML = '' ;
9587
9688 render ( ) ;
97- } , [ props . opts . colors ] ) ;
89+ } , [ componentTheme , render ] ) ;
9890
9991 useEffect ( ( ) => {
10092 paranoid . current ?. updateData ?. ( props . data ) ;
@@ -200,12 +192,12 @@ function QueryExplain(props) {
200192 } ) }
201193 >
202194 < GraphRoot
195+ theme = { theme }
203196 version = { version }
204197 data = { { links, nodes} }
205198 opts = { {
206199 renderNodeTitle : renderExplainNode ,
207200 textOverflow : TextOverflow . Normal ,
208- colors : theme === 'dark' ? DARK_COLORS : { } ,
209201 initialZoomFitsCanvas : true ,
210202 } }
211203 shapes = { {
0 commit comments