Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new DevUI for Reactive REST Client #32614

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}