Skip to content

Commit

Permalink
Implement new DevUI for Reactive REST Client
Browse files Browse the repository at this point in the history
Closes: quarkusio#32596
(cherry picked from commit 0ec681b)
  • Loading branch information
geoand authored and gsmet committed Apr 18, 2023
1 parent 5821c30 commit d8ab74d
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.rest.client.reactive.runtime.devconsole.RestClientsContainer;
import io.quarkus.rest.client.reactive.runtime.devconsole.RestClientsJsonRPCService;

public class RestClientReactiveDevConsoleProcessor {

Expand All @@ -20,4 +24,20 @@ public DevConsoleRuntimeTemplateInfoBuildItem devConsoleInfo(CurateOutcomeBuildI
public AdditionalBeanBuildItem beans() {
return AdditionalBeanBuildItem.unremovableOf(RestClientsContainer.class);
}

@BuildStep(onlyIf = IsDevelopment.class)
CardPageBuildItem create() {
CardPageBuildItem pageBuildItem = new CardPageBuildItem();
pageBuildItem.addPage(Page.webComponentPageBuilder()
.title("REST Clients")
.componentLink("qwc-rest-client-clients.js")
.icon("font-awesome-solid:server"));

return pageBuildItem;
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem createJsonRPCServiceForCache() {
return new JsonRPCProvidersBuildItem(RestClientsJsonRPCService.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { LitElement, html, css} from 'lit';
import { JsonRpc } from 'jsonrpc';
import '@vaadin/icon';
import '@vaadin/progress-bar';
import '@vaadin/checkbox';
import { until } from 'lit/directives/until.js';
import '@vaadin/grid';
import { columnBodyRenderer } from '@vaadin/grid/lit.js';
import '@vaadin/grid/vaadin-grid-sort-column.js';

export class QwcRestClientClients extends LitElement {

jsonRpc = new JsonRpc(this);

// Component style
static styles = css`
code {
font-size: 85%;
}`;

// Component properties
static properties = {
_clients: {state: true}
}

constructor() {
super();
this._clients = null;
}

// Components callbacks

/**
* Called when displayed
*/
connectedCallback() {
super.connectedCallback();
this.jsonRpc.getAll().then(jsonRpcResponse => {
this._clients = jsonRpcResponse.result;
});
}

/**
* Called when it needs to render the components
* @returns {*}
*/
render() {
return html`${until(this._renderClientsTable(), html`<span>Loading REST Clients...</span>`)}`;
}

// View / Templates

_renderClientsTable() {
if (this._clients) {
return html`
<vaadin-grid .items="${this._clients}" class="datatable" theme="no-border">
<vaadin-grid-column auto-width
header="Client interface"
${columnBodyRenderer(this._clientInterfaceRenderer, [])}
resizable>
</vaadin-grid-column>
<vaadin-grid-column auto-width
header="Config Key"
${columnBodyRenderer(this._configKeyRenderer, [])}
resizable>
</vaadin-grid-column>
<vaadin-grid-column auto-width
header="Is CDI Bean"
${columnBodyRenderer(this._isBeanRenderer, [])}
resizable>
</vaadin-grid-column>
</vaadin-grid>`;
}
}

_clientInterfaceRenderer(client){
return html`
<code>${client.clientInterface}</code>
`;
}

_configKeyRenderer(client){
return html`
<code>${client.configKey}</code>
`;
}

_isBeanRenderer(client){
if(client.isBean !== false){
return html`
<qui-badge level="success" icon="font-awesome-solid:check"></qui-badge>
`;
}
}

}
customElements.define('qwc-rest-client-clients', QwcRestClientClients);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.rest.client.reactive.runtime.devconsole;

import java.util.Comparator;

import jakarta.inject.Singleton;

import io.smallrye.common.annotation.NonBlocking;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

@Singleton
public class RestClientsJsonRPCService {

private final RestClientsContainer restClientsContainer;

public RestClientsJsonRPCService(RestClientsContainer restClientsContainer) {
this.restClientsContainer = restClientsContainer;
}

@NonBlocking
public JsonArray getAll() {
var allClients = restClientsContainer.getClientData().clients;
allClients.sort(Comparator.comparing(rci -> rci.interfaceClass));

var result = new JsonArray();
for (RestClientsContainer.RestClientInfo rci : allClients) {
result.add(new JsonObject()
.put("clientInterface", rci.interfaceClass)
.put("isBean", rci.isBean)
.put("configKey", rci.configKey));
}
return result;
}

}

0 comments on commit d8ab74d

Please sign in to comment.