forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new DevUI for Reactive REST Client
Closes: quarkusio#32596 (cherry picked from commit 0ec681b)
- Loading branch information
Showing
3 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...tive/rest-client-reactive/deployment/src/main/resources/dev-ui/qwc-rest-client-clients.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
35 changes: 35 additions & 0 deletions
35
...in/java/io/quarkus/rest/client/reactive/runtime/devconsole/RestClientsJsonRPCService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |