1
- import { LitElement , html , css } from 'lit ' ;
1
+ import { QwcHotReloadElement , html , css } from 'qwc-hot-reload-element ' ;
2
2
import { JsonRpc } from 'jsonrpc' ;
3
3
import '@vaadin/icon' ;
4
4
import 'qui-badge' ;
5
5
6
6
/**
7
7
* This component adds a custom link on the Extension card
8
8
*/
9
- export class QwcExtensionLink extends LitElement {
9
+ export class QwcExtensionLink extends QwcHotReloadElement {
10
10
11
11
static styles = css `
12
12
.extensionLink {
@@ -49,9 +49,86 @@ export class QwcExtensionLink extends LitElement {
49
49
_effectiveLabel : { state : true } ,
50
50
_observer : { state : false } ,
51
51
} ;
52
+
53
+ _staticLabel = null ;
54
+ _dynamicLabel = null ;
55
+ _streamingLabel = null ;
56
+
57
+ set staticLabel ( val ) {
58
+ if ( ! this . _staticLabel || ( this . _staticLabel && this . _staticLabel != val ) ) {
59
+ let oldVal = this . _staticLabel ;
60
+ this . _staticLabel = val ;
61
+ this . requestUpdate ( 'staticLabel' , oldVal ) ;
62
+ this . hotReload ( ) ;
63
+ }
64
+ }
65
+
66
+ get staticLabel ( ) {
67
+ return this . _staticLabel ;
68
+ }
69
+
70
+ set dynamicLabel ( val ) {
71
+ if ( ! this . _dynamicLabel || ( this . _dynamicLabel && this . _dynamicLabel != val ) ) {
72
+ let oldVal = this . _dynamicLabel ;
73
+ this . _dynamicLabel = val ;
74
+ this . requestUpdate ( 'dynamicLabel' , oldVal ) ;
75
+ this . hotReload ( ) ;
76
+ }
77
+ }
78
+
79
+ get dynamicLabel ( ) {
80
+ return this . _dynamicLabel ;
81
+ }
82
+
83
+ set streamingLabel ( val ) {
84
+ if ( ! this . _streamingLabel || ( this . _streamingLabel && this . _streamingLabel != val ) ) {
85
+ let oldVal = this . _streamingLabel ;
86
+ this . _streamingLabel = val ;
87
+ this . requestUpdate ( 'streamingLabel' , oldVal ) ;
88
+ this . hotReload ( ) ;
89
+ }
90
+ }
91
+
92
+ get streamingLabel ( ) {
93
+ return this . _streamingLabel ;
94
+ }
52
95
53
96
connectedCallback ( ) {
54
97
super . connectedCallback ( ) ;
98
+ this . hotReload ( ) ;
99
+ }
100
+
101
+ hotReload ( ) {
102
+ if ( this . _observer ) {
103
+ this . _observer . cancel ( ) ;
104
+ }
105
+ this . _effectiveLabel = null ;
106
+ if ( this . streamingLabel ) {
107
+ this . jsonRpc = new JsonRpc ( this ) ;
108
+ this . _observer = this . jsonRpc [ this . streamingLabel ] ( ) . onNext ( jsonRpcResponse => {
109
+ let oldVal = this . _effectiveLabel ;
110
+ this . _effectiveLabel = jsonRpcResponse . result ;
111
+ this . requestUpdate ( '_effectiveLabel' , oldVal ) ;
112
+ } ) ;
113
+ } else if ( this . dynamicLabel ) {
114
+ this . jsonRpc = new JsonRpc ( this ) ;
115
+ this . jsonRpc [ this . dynamicLabel ] ( ) . then ( jsonRpcResponse => {
116
+ let oldVal = this . _effectiveLabel ;
117
+ this . _effectiveLabel = jsonRpcResponse . result ;
118
+ this . requestUpdate ( '_effectiveLabel' , oldVal ) ;
119
+ } ) ;
120
+ } else if ( this . staticLabel ) {
121
+ let oldVal = this . _effectiveLabel ;
122
+ this . _effectiveLabel = this . staticLabel ;
123
+ this . requestUpdate ( '_effectiveLabel' , oldVal ) ;
124
+ } else {
125
+ let oldVal = this . _effectiveLabel ;
126
+ this . _effectiveLabel = null ;
127
+ this . requestUpdate ( '_effectiveLabel' , oldVal ) ;
128
+ }
129
+ }
130
+
131
+ _getEffectiveLabel ( ) {
55
132
if ( this . streamingLabel ) {
56
133
this . jsonRpc = new JsonRpc ( this ) ;
57
134
this . _observer = this . jsonRpc [ this . streamingLabel ] ( ) . onNext ( jsonRpcResponse => {
@@ -71,28 +148,30 @@ export class QwcExtensionLink extends LitElement {
71
148
if ( this . _observer ) {
72
149
this . _observer . cancel ( ) ;
73
150
}
74
- super . disconnectedCallback ( )
151
+ super . disconnectedCallback ( ) ;
75
152
}
76
153
77
154
render ( ) {
78
- let routerIgnore = false ;
79
-
80
- let p = this . path ;
81
- let t = "_self" ;
82
- if ( ! this . embed ) {
83
- routerIgnore = true ;
84
- p = this . externalUrl ;
85
- t = "_blank" ;
155
+ if ( this . path ) {
156
+ let routerIgnore = false ;
157
+
158
+ let p = this . path ;
159
+ let t = "_self" ;
160
+ if ( ! this . embed ) {
161
+ routerIgnore = true ;
162
+ p = this . externalUrl ;
163
+ t = "_blank" ;
164
+ }
165
+ return html `
166
+ < a class ="extensionLink " href ="${ p } " ?router-ignore =${ routerIgnore } target ="${ t } ">
167
+ < span class ="iconAndName ">
168
+ < vaadin-icon class ="icon " icon ="${ this . iconName } "> </ vaadin-icon >
169
+ ${ this . displayName }
170
+ </ span >
171
+ ${ this . _renderBadge ( ) }
172
+ </ a >
173
+ ` ;
86
174
}
87
- return html `
88
- < a class ="extensionLink " href ="${ p } " ?router-ignore =${ routerIgnore } target ="${ t } ">
89
- < span class ="iconAndName ">
90
- < vaadin-icon class ="icon " icon ="${ this . iconName } "> </ vaadin-icon >
91
- ${ this . displayName }
92
- </ span >
93
- ${ this . _renderBadge ( ) }
94
- </ a >
95
- ` ;
96
175
}
97
176
98
177
_renderBadge ( ) {
0 commit comments