Skip to content

Commit a6f45f3

Browse files
Dev UI Fix labels not clearing out
Signed-off-by: Phillip Kruger <[email protected]>
1 parent 4d393af commit a6f45f3

File tree

1 file changed

+99
-20
lines changed

1 file changed

+99
-20
lines changed

extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-extension-link.js

+99-20
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { LitElement, html, css} from 'lit';
1+
import { QwcHotReloadElement, html, css} from 'qwc-hot-reload-element';
22
import { JsonRpc } from 'jsonrpc';
33
import '@vaadin/icon';
44
import 'qui-badge';
55

66
/**
77
* This component adds a custom link on the Extension card
88
*/
9-
export class QwcExtensionLink extends LitElement {
9+
export class QwcExtensionLink extends QwcHotReloadElement {
1010

1111
static styles = css`
1212
.extensionLink {
@@ -49,9 +49,86 @@ export class QwcExtensionLink extends LitElement {
4949
_effectiveLabel: {state: true},
5050
_observer: {state: false},
5151
};
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+
}
5295

5396
connectedCallback() {
5497
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(){
55132
if(this.streamingLabel){
56133
this.jsonRpc = new JsonRpc(this);
57134
this._observer = this.jsonRpc[this.streamingLabel]().onNext(jsonRpcResponse => {
@@ -71,28 +148,30 @@ export class QwcExtensionLink extends LitElement {
71148
if(this._observer){
72149
this._observer.cancel();
73150
}
74-
super.disconnectedCallback()
151+
super.disconnectedCallback();
75152
}
76153

77154
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+
`;
86174
}
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-
`;
96175
}
97176

98177
_renderBadge() {

0 commit comments

Comments
 (0)