Skip to content

Commit

Permalink
Merge pull request #39459 from phillip-kruger/dev-ui-hotkeys
Browse files Browse the repository at this point in the history
Add key listeners to the log in Dev UI
  • Loading branch information
phillip-kruger authored Mar 15, 2024
2 parents d30f161 + 3658016 commit 5a38253
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bom/dev-ui/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<description>Dependency management for dev-ui. Importable by third party extension developers.</description>

<properties>
<vaadin.version>24.3.7</vaadin.version>
<vaadin.version>24.3.8</vaadin.version>
<lit.version>3.1.2</lit.version>
<lit-element.version>4.0.4</lit-element.version>
<lit-html.version>3.1.2</lit-html.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ public static <T> void register(String name, Function<Map<String, String>, T> ac
actions.put(name, action);
}

/**
* Invokes a registered action
*
* @param name the name of the action
* @return the result of the invocation. An empty map is returned for action not returning any result.
*/
@SuppressWarnings("unchecked")
public static <T> T invoke(String name) {
return DevConsoleManager.invoke(name, Map.of());
}

/**
* Invokes a registered action
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ InternalImportMapBuildItem createKnownInternalImportMap(NonApplicationRootPathBu
internalImportMapBuildItem.add("qwc/", contextRoot + "qwc/");
internalImportMapBuildItem.add("qwc-no-data", contextRoot + "qwc/qwc-no-data.js");
internalImportMapBuildItem.add("qwc-hot-reload-element", contextRoot + "qwc/qwc-hot-reload-element.js");
internalImportMapBuildItem.add("qwc-abstract-log-element", contextRoot + "qwc/qwc-abstract-log-element.js");
internalImportMapBuildItem.add("qwc-server-log", contextRoot + "qwc/qwc-server-log.js");
internalImportMapBuildItem.add("qwc-extension-link", contextRoot + "qwc/qwc-extension-link.js");
// Quarkus UI
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.devui.deployment.logstream;

import java.util.Map;
import java.util.Optional;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
Expand All @@ -8,7 +9,12 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.StreamingLogHandlerBuildItem;
import io.quarkus.deployment.dev.RuntimeUpdatesProcessor;
import io.quarkus.deployment.dev.testing.TestSupport;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.dev.spi.DevModeType;
import io.quarkus.devui.runtime.logstream.LogStreamBroadcaster;
import io.quarkus.devui.runtime.logstream.LogStreamJsonRPCService;
import io.quarkus.devui.runtime.logstream.LogStreamRecorder;
Expand Down Expand Up @@ -38,8 +44,97 @@ public void handler(BuildProducer<StreamingLogHandlerBuildItem> streamingLogHand
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem createJsonRPCService() {
JsonRPCProvidersBuildItem createJsonRPCService(LaunchModeBuildItem launchModeBuildItem) {
Optional<TestSupport> ts = TestSupport.instance();

DevConsoleManager.register("logstream-force-restart", ignored -> {
RuntimeUpdatesProcessor.INSTANCE.doScan(true, true);
return Map.of();
});

DevConsoleManager.register("logstream-rerun-all-tests", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
if (ts.get().isStarted()) {
ts.get().runAllTests();
return Map.of();
} else {
ts.get().start();
return Map.of("running", ts.get().isRunning());
}
});

DevConsoleManager.register("logstream-rerun-failed-tests", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
ts.get().runFailedTests();
return Map.of();
});

DevConsoleManager.register("logstream-toggle-broken-only", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
boolean brokenOnlyMode = ts.get().toggleBrokenOnlyMode();
return Map.of("brokenOnlyMode", brokenOnlyMode);
});

DevConsoleManager.register("logstream-print-failures", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
ts.get().printFullResults();
return Map.of();
});

DevConsoleManager.register("logstream-toggle-test-output", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
boolean isTestOutput = ts.get().toggleTestOutput();
return Map.of("isTestOutput", isTestOutput);
});

DevConsoleManager.register("logstream-toggle-instrumentation-reload", ignored -> {
boolean instrumentationEnabled = RuntimeUpdatesProcessor.INSTANCE.toggleInstrumentation();
return Map.of("instrumentationEnabled", instrumentationEnabled);
});

DevConsoleManager.register("logstream-pause-tests", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
if (ts.get().isStarted()) {
ts.get().stop();
return Map.of("running", ts.get().isRunning());
}
return Map.of();
});

DevConsoleManager.register("logstream-toggle-live-reload", ignored -> {
if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
boolean liveReloadEnabled = ts.get().toggleLiveReloadEnabled();
return Map.of("liveReloadEnabled", liveReloadEnabled);
});

DevConsoleManager.register("logstream-toggle-live-reload", ignored -> {

if (testsDisabled(launchModeBuildItem, ts)) {
return Map.of();
}
boolean liveReloadEnabled = ts.get().toggleLiveReloadEnabled();
return Map.of("liveReloadEnabled", liveReloadEnabled);
});

return new JsonRPCProvidersBuildItem("devui-logstream", LogStreamJsonRPCService.class);
}

private boolean testsDisabled(LaunchModeBuildItem launchModeBuildItem, Optional<TestSupport> ts) {
return ts.isEmpty() || launchModeBuildItem.getDevModeType().orElse(null) != DevModeType.LOCAL;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class LogController {
}

_createItem(icon, title, color) {
var style = `font-size: small;cursor: pointer;color: ${color};`;
var style = `font-size: small;cursor: pointer;color: ${color};background-color: transparent;`;
const item = document.createElement('vaadin-context-menu-item');
const vaadinicon = document.createElement('vaadin-icon');
item.setAttribute('aria-label', `${title}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { QwcHotReloadElement, html, css} from 'qwc-hot-reload-element';
export * from 'lit';

/**
* This is an abstract component that handle some common event for logs
*/
class QwcAbstractLogElement extends QwcHotReloadElement {

constructor() {
super();
}

connectedCallback() {
super.connectedCallback();
this.setAttribute('tabindex', '0');
this.bindKeyHandler = this._handleKeyPress.bind(this);
this.bindScrollHandler = this._handleScroll.bind(this);
this.addEventListener('keydown', this.bindKeyHandler);
this.addEventListener('wheel', this.bindScrollHandler, { passive: false });
}

disconnectedCallback() {
this.removeEventListener('keydown', this.bindKeyHandler);
this.removeEventListener('wheel', this.bindScrollHandler);
super.disconnectedCallback();
}

_handleScroll(event){
if (event.ctrlKey) {
// Prevent the default zoom action when Ctrl + scroll is detected
event.preventDefault();
if (event.deltaY < 0) {
this._handleZoomIn(event);
} else if (event.deltaY > 0) {
this._handleZoomOut(event);
}
}
}

_handleKeyPress(event) {
throw new Error("Method '_handleKeyPress(event)' must be implemented.");
}

_handleZoomIn(event){
throw new Error("Method '_handleZoomIn(event)' must be implemented.");
}

_handleZoomOut(event){
throw new Error("Method '_handleZoomOut(event)' must be implemented.");
}

}

export { QwcAbstractLogElement };
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ export class QwcFooter extends observeState(LitElement) {
}
vaadin-menu-bar-button {
background: var(--lumo-contrast-5pct);
background-color: transparent;
}
vaadin-menu-bar-button:hover {
background-color: transparent;
}
.dragOpen:hover {
background: var(--quarkus-blue);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LitElement, html, css} from 'lit';
import { QwcAbstractLogElement, html, css} from 'qwc-abstract-log-element';
import { repeat } from 'lit/directives/repeat.js';
import { LogController } from 'log-controller';
import { StorageController } from 'storage-controller';

/**
* This component represent the Dev UI Json RPC Message log
*/
export class QwcJsonrpcMessages extends LitElement {
export class QwcJsonrpcMessages extends QwcAbstractLogElement {

logControl = new LogController(this);
storageControl = new StorageController(this);
Expand Down Expand Up @@ -44,7 +44,7 @@ export class QwcJsonrpcMessages extends LitElement {
_zoom: {state:true},
_increment: {state: false},
_followLog: {state: false},
_isOn: {state: false},
_isOn: {state: false}
};

constructor() {
Expand Down Expand Up @@ -83,8 +83,8 @@ export class QwcJsonrpcMessages extends LitElement {
}

disconnectedCallback() {
super.disconnectedCallback();
this._toggleOnOff(false);
super.disconnectedCallback();
}

render() {
Expand All @@ -106,6 +106,8 @@ export class QwcJsonrpcMessages extends LitElement {
_renderLogEntry(message){
if(message.isLine){
return html`<hr class="line"/>`;
}else if(message.isBlank){
return html`<br/>`;
}else{
return html`
${this._renderTimestamp(message.time)}
Expand Down Expand Up @@ -201,6 +203,30 @@ export class QwcJsonrpcMessages extends LitElement {
_zoomIn(){
this._zoom = parseFloat(parseFloat(this._zoom) + parseFloat(this._increment)).toFixed(2);
}

hotReload(){

}

_handleZoomIn(event){
this._zoomIn();
}

_handleZoomOut(event){
this._zoomOut();
}

_handleKeyPress(event) {
if (event.key === 'Enter') {
// Create a blank line in the console.
var blankEntry = new Object();
blankEntry.id = Math.floor(Math.random() * 999999);
blankEntry.isBlank = true;
this._addLogEntry(blankEntry);
}
}


}

customElements.define('qwc-jsonrpc-messages', QwcJsonrpcMessages);
Loading

0 comments on commit 5a38253

Please sign in to comment.