1
+ import { QwcHotReloadElement , html , css } from 'qwc-hot-reload-element' ;
2
+ import { unsafeHTML } from 'lit/directives/unsafe-html.js' ;
3
+ import { JsonRpc } from 'jsonrpc' ;
4
+
5
+ import { Graphviz } from "@hpcc-js/wasm/graphviz.js" ;
6
+
7
+ import '@vaadin/details' ;
8
+ import '@vaadin/tabs' ;
9
+ import '@vaadin/vertical-layout' ;
10
+ import 'qui-badge' ;
11
+ import 'qui-code-block' ;
12
+
13
+ /**
14
+ * This component shows the Kafka Streams Topology
15
+ */
16
+ export class QwcKafkaStreamsTopology extends QwcHotReloadElement {
17
+
18
+ jsonRpc = new JsonRpc ( this ) ;
19
+
20
+ static styles = css `
21
+ .codeBlock {
22
+ width: 100%;
23
+ height: auto;
24
+ }
25
+ ` ;
26
+
27
+ static properties = {
28
+ _topology : { state : true } ,
29
+ _graphviz : { state : true } ,
30
+ _tabContent : { state : true }
31
+ } ;
32
+
33
+ constructor ( ) {
34
+ super ( ) ;
35
+ this . _topology = null ;
36
+ this . _graphviz = null ;
37
+ this . _tabContent = '' ;
38
+ }
39
+
40
+ connectedCallback ( ) {
41
+ super . connectedCallback ( ) ;
42
+ Graphviz . load ( ) . then ( r => this . _graphviz = r ) ;
43
+ this . hotReload ( )
44
+ }
45
+
46
+ render ( ) {
47
+ if ( this . _topology ) {
48
+ return html `< vaadin-tabs @selected-changed ="${ ( e ) => this . _tabSelectedChanged ( e . detail . value ) } ">
49
+ < vaadin-tab id ="graphTab "> Graph</ vaadin-tab >
50
+ < vaadin-tab id ="detailsTab "> Details</ vaadin-tab >
51
+ < vaadin-tab id ="describeTab "> Describe</ vaadin-tab >
52
+ < vaadin-tab id ="graphvizTab "> Graphviz</ vaadin-tab >
53
+ < vaadin-tab id ="mermaidTab "> Mermaid</ vaadin-tab >
54
+ </ vaadin-tabs >
55
+ < vaadin-vertical-layout theme ="padding "> < p > ${ this . _tabContent } </ p > </ vaadin-vertical-layout > ` ;
56
+ }
57
+
58
+ return html `< qwc-no-data message ="You do not have any Topology. "
59
+ link ="https://quarkus.io/guides/kafka-streams "
60
+ linkText ="Learn how to write Kafka Streams ">
61
+ </ qwc-no-data > ` ;
62
+ }
63
+
64
+ hotReload ( ) {
65
+ this . _topology = null ;
66
+ this . jsonRpc . getTopology ( ) . then ( jsonRpcResponse => {
67
+ this . _topology = jsonRpcResponse . result ;
68
+ } ) ;
69
+ }
70
+
71
+ _tabSelectedChanged ( n ) {
72
+ switch ( n ) {
73
+ case 1 : this . _selectDetailsTab ( ) ; break ;
74
+ case 2 : this . _selectDescribeTab ( ) ; break ;
75
+ case 3 : this . _selectGraphvizTab ( ) ; break ;
76
+ case 4 : this . _selectMermaidTab ( ) ; break ;
77
+ default : this . _selectGraphTab ( ) ;
78
+ }
79
+ }
80
+
81
+ _selectGraphTab ( ) {
82
+ if ( this . _graphviz ) {
83
+ let g = this . _graphviz . dot ( this . _topology . graphviz ) ;
84
+ this . _tabContent = html `${ unsafeHTML ( g ) } ` ;
85
+ } else {
86
+ this . _tabContent = html `Graph engine not started.` ;
87
+ }
88
+ }
89
+
90
+ _selectDetailsTab ( ) {
91
+ this . _tabContent = html `< table >
92
+ < tr >
93
+ < td > Sub-topologies</ td > < td > < qui-badge > ${ this . _topology . subTopologies . length } </ qui-badge > </ td >
94
+ < td > ${ this . _topology . subTopologies . map ( ( subTopology ) => html `< qui-badge level ="contrast " icon ="font-awesome-solid:diagram-project " style ="margin-right:5px "> ${ subTopology } </ qui-badge > ` ) } </ td >
95
+ </ tr >
96
+ < tr >
97
+ < td > Sources</ td > < td > < qui-badge > ${ this . _topology . sources . length } </ qui-badge > </ td >
98
+ < td > ${ this . _topology . sources . map ( ( source ) => html `< qui-badge level ="contrast " icon ="font-awesome-solid:right-to-bracket " style ="margin-right:5px "> ${ source } </ qui-badge > ` ) } </ td >
99
+ </ tr >
100
+ < tr >
101
+ < td > Sinks</ td > < td > < qui-badge > ${ this . _topology . sinks . length } </ qui-badge > </ td >
102
+ < td > ${ this . _topology . sinks . map ( ( sink ) => html `< qui-badge level ="contrast " icon ="font-awesome-solid:right-from-bracket " style ="margin-right:5px "> ${ sink } </ qui-badge > ` ) } </ td >
103
+ </ tr >
104
+ < tr >
105
+ < td > Stores</ td > < td > < qui-badge > ${ this . _topology . stores . length } </ qui-badge > </ td >
106
+ < td > ${ this . _topology . stores . map ( ( store ) => html `< qui-badge level ="contrast " icon ="font-awesome-solid:database " style ="margin-right:5px "> ${ store } </ qui-badge > ` ) } </ td >
107
+ </ tr >
108
+ </ table > ` ;
109
+ }
110
+
111
+ _selectDescribeTab ( ) {
112
+ this . _tabContent = html `< qui-code-block mode ='text ' content ='${ this . _topology . describe } ' class ="codeBlock "> </ qui-code-block > ` ;
113
+ }
114
+
115
+ _selectGraphvizTab ( ) {
116
+ this . _tabContent = html `< qui-code-block mode ='gv ' content ='${ this . _topology . graphviz } ' class ="codeBlock "> </ qui-code-block > ` ;
117
+ }
118
+
119
+ _selectMermaidTab ( ) {
120
+ this . _tabContent = html `< qui-code-block mode ='mermaid ' content ='${ this . _topology . mermaid } ' class ="codeBlock "> </ qui-code-block > ` ;
121
+ }
122
+ }
123
+ customElements . define ( 'qwc-kafka-streams-topology' , QwcKafkaStreamsTopology ) ;
0 commit comments