Skip to content

Commit 885291b

Browse files
authored
Merge pull request #31674 from phillip-kruger/dev-ui-hotreload
Dev UI: added a way to react on hot reload
2 parents a2463b3 + dea75f6 commit 885291b

File tree

8 files changed

+53
-14
lines changed

8 files changed

+53
-14
lines changed

extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/resources/dev-ui/resteasy-reactive/qwc-resteasy-reactive-card.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { LitElement, html, css} from 'lit';
1+
import { QwcHotReloadElement, html, css} from 'qwc-hot-reload-element';
22
import { pages } from 'resteasy-reactive-data';
33
import { JsonRpc } from 'jsonrpc';
44
import 'echarts-gauge-grade';
55
import '@vaadin/icon';
66

7-
export class QwcResteasyReactiveCard extends LitElement {
7+
export class QwcResteasyReactiveCard extends QwcHotReloadElement {
88
jsonRpc = new JsonRpc("RESTEasy Reactive");
99

1010
static styles = css`
@@ -43,7 +43,7 @@ export class QwcResteasyReactiveCard extends LitElement {
4343
render() {
4444

4545
if(this._latestScores){
46-
return html`<div class="graph" @click=${this._refresh}>
46+
return html`<div class="graph" @click=${this.hotReload}>
4747
<echarts-gauge-grade
4848
percentage="${this._latestScores.score}"
4949
percentageFontSize="14"
@@ -61,7 +61,7 @@ export class QwcResteasyReactiveCard extends LitElement {
6161
</a>`;
6262
}
6363

64-
_refresh(){
64+
hotReload(){
6565
this._latestScores = null;
6666
this.jsonRpc.getEndpointScores().then(endpointScores => {
6767
this._latestScores = endpointScores.result;

extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/main/resources/dev-ui/resteasy-reactive/qwc-resteasy-reactive-endpoint-scores.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LitElement, html, css} from 'lit';
1+
import { QwcHotReloadElement, html, css} from 'qwc-hot-reload-element';
22
import { JsonRpc } from 'jsonrpc';
33

44
import '@vaadin/details';
@@ -9,7 +9,7 @@ import 'qui-badge';
99
/**
1010
* This component shows the Rest Easy Reactive Endpoint scores
1111
*/
12-
export class QwcResteasyReactiveEndpointScores extends LitElement {
12+
export class QwcResteasyReactiveEndpointScores extends QwcHotReloadElement {
1313
jsonRpc = new JsonRpc("RESTEasy Reactive");
1414

1515
static styles = css`
@@ -89,7 +89,7 @@ export class QwcResteasyReactiveEndpointScores extends LitElement {
8989

9090
connectedCallback() {
9191
super.connectedCallback();
92-
this._refresh();
92+
this.hotReload();
9393
}
9494

9595
render() {
@@ -194,7 +194,8 @@ export class QwcResteasyReactiveEndpointScores extends LitElement {
194194
return level;
195195
}
196196

197-
_refresh(){
197+
hotReload(){
198+
this._latestScores = null;
198199
this.jsonRpc.getEndpointScores().then(endpointScores => {
199200
this._latestScores = endpointScores.result;
200201
});

extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/BuildTimeContentProcessor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ InternalImportMapBuildItem createKnownInternalImportMap(NonApplicationRootPathBu
7878
internalImportMapBuildItem.add("devui/", contextRoot + "/");
7979
// Quarkus Web Components
8080
internalImportMapBuildItem.add("qwc/", contextRoot + "qwc/");
81+
internalImportMapBuildItem.add("qwc-hot-reload-element", contextRoot + "qwc/qwc-hot-reload-element.js");
8182
// Quarkus UI
8283
internalImportMapBuildItem.add("qui/", contextRoot + "qui/");
8384
internalImportMapBuildItem.add("qui-badge", contextRoot + "qui/qui-badge.js");
@@ -301,6 +302,7 @@ void loadAllBuildTimeTemplates(BuildProducer<StaticContentBuildItem> buildTimeCo
301302
@BuildStep(onlyIf = IsDevelopment.class)
302303
void createBuildTimeData(BuildProducer<BuildTimeConstBuildItem> buildTimeConstProducer,
303304
BuildProducer<ThemeVarsBuildItem> themeVarsProducer,
305+
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
304306
ExtensionsBuildItem extensionsBuildItem,
305307
List<MenuPageBuildItem> menuPageBuildItems,
306308
List<DevServiceDescriptionBuildItem> devServiceDescriptions,
@@ -395,7 +397,9 @@ void createBuildTimeData(BuildProducer<BuildTimeConstBuildItem> buildTimeConstPr
395397
internalBuildTimeData.addBuildTimeData("footerTabs", footerTabs);
396398

397399
// Add version info
400+
String contextRoot = nonApplicationRootPathBuildItem.getNonApplicationRootPath() + DEV_UI + SLASH;
398401
Map<String, String> applicationInfo = new HashMap<>();
402+
applicationInfo.put("contextRoot", contextRoot);
399403
applicationInfo.put("quarkusVersion", Version.getVersion());
400404
applicationInfo.put("applicationName", config.getOptionalValue("quarkus.application.name", String.class).orElse(""));
401405
applicationInfo.put("applicationVersion",

extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/logstream/LogStreamProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void handler(BuildProducer<StreamingLogHandlerBuildItem> streamingLogHand
3939

4040
@BuildStep(onlyIf = IsDevelopment.class)
4141
JsonRPCProvidersBuildItem createJsonRPCService() {
42-
return new JsonRPCProvidersBuildItem("DevUI", LogStreamJsonRPCService.class);
42+
return new JsonRPCProvidersBuildItem("devui-logstream", LogStreamJsonRPCService.class);
4343
}
4444

4545
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class QwcHeader extends observeState(LitElement) {
242242
}
243243

244244
_reload(e) {
245-
console.log("TODO: Reload");
245+
fetch(devuiState.applicationInfo.contextRoot);
246246
}
247247
}
248248
customElements.define('qwc-header', QwcHeader);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { LitElement } from 'lit';
2+
import { connectionState } from 'connection-state';
3+
export * from 'lit';
4+
5+
/**
6+
* This is an abstract component that monitor hot reload events
7+
*/
8+
class QwcHotReloadElement extends LitElement {
9+
10+
constructor() {
11+
super();
12+
}
13+
14+
connectedCallback() {
15+
super.connectedCallback();
16+
this.connectionStateObserver = () => this._connectionStateChange();
17+
connectionState.addObserver(this.connectionStateObserver);
18+
}
19+
20+
disconnectedCallback() {
21+
connectionState.removeObserver(this.connectionStateObserver);
22+
super.disconnectedCallback();
23+
}
24+
25+
_connectionStateChange(){
26+
if(connectionState.current.isConnected){
27+
this.hotReload();
28+
}
29+
}
30+
31+
hotReload(){
32+
throw new Error("Method 'hotReload()' must be implemented.");
33+
}
34+
35+
}
36+
37+
export { QwcHotReloadElement };

extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/qwc/qwc-server-log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import 'qui-badge';
1616
export class QwcServerLog extends LitElement {
1717

1818
logControl = new LogController(this);
19-
jsonRpc = new JsonRpc("DevUI", false);
19+
jsonRpc = new JsonRpc("devui-logstream", false);
2020

2121
static styles = css`
2222
.log {

extensions/vertx-http/dev-ui-resources/src/main/resources/dev-ui/state/devui-state.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { LitState } from 'lit-element-state';
77

88
/**
99
* This keeps track of the build time data of Dev UI
10-
*
11-
* TODO: Find a way to abstract this so that any build time data can reuse this in an easy way
1210
* TODO: Import map needs to be reloaded too
13-
* TODO: Hot reload should trigger this too (not only ws connection drops)
1411
*/
1512
class DevUIState extends LitState {
1613

0 commit comments

Comments
 (0)