Skip to content

Commit

Permalink
Add browser callables to each dev-ui card page
Browse files Browse the repository at this point in the history
  • Loading branch information
Dudeplayz committed Nov 26, 2024
1 parent b870a2e commit 1bcf13c
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public EndpointBuildItem(List<EndpointInfo> endpoints) {
public List<EndpointInfo> getEndpoints() {
return endpoints;
}

public int getEndpointMethodCount() {
return endpoints.stream()
.mapToInt(a -> a.children().size())
.sum();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2024 Marco Collovati, Dario Götze
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.mcollovati.quarkus.hilla.deployment.devui;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.devui.deployment.BuildTimeConstBuildItem;
import io.quarkus.devui.deployment.DevUIWebJarBuildItem;
import io.quarkus.maven.dependency.GACT;
import io.quarkus.vertx.http.deployment.webjar.WebJarBuildItem;
import io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.DotName;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

public class QuarkusHillaDevUICommonsProcessor {

private static final GACT UI_JAR = new GACT("com.github.mcollovati", "quarkus-hilla-commons-deployment", null, "jar");
private static final String NAMESPACE = UI_JAR.getGroupId() + "." + UI_JAR.getArtifactId();
private static final String DEV_UI = "dev-ui";

private static final DotName SIGNALS_HANDLER =
DotName.createSimple("com.vaadin.hilla.signals.handler.SignalsHandler");

@BuildStep(onlyIf = IsDevelopment.class)
public EndpointBuildItem collectEndpoints(CombinedIndexBuildItem combinedIndexBuildItem) {
final var endpointAnnotated =
combinedIndexBuildItem.getComputingIndex().getAnnotations(EndpointInfo.ENDPOINT_ANNOTATION);
final var browserCallableAnnotated =
combinedIndexBuildItem.getComputingIndex().getAnnotations(EndpointInfo.BROWSER_CALLABLE_ANNOTATION);
final var endpoints = Stream.concat(endpointAnnotated.stream(), browserCallableAnnotated.stream())
.map(AnnotationInstance::target)
.filter(target -> target.kind().equals(AnnotationTarget.Kind.CLASS))
.map(AnnotationTarget::asClass)
.filter(c -> !SIGNALS_HANDLER.equals(c.name()))
.map(EndpointInfo::from)
.toList();
return new EndpointBuildItem(endpoints);
}

@BuildStep(onlyIf = IsDevelopment.class)
void createShared(
BuildProducer<WebJarBuildItem> webJarBuildProducer,
BuildProducer<DevUIWebJarBuildItem> devUIWebJarProducer,
BuildProducer<BuildTimeConstBuildItem> buildTimeConstProducer,
EndpointBuildItem endpointBuildItem) {

final Map<String, Object> buildTimeData = new HashMap<>();
buildTimeData.put("hillaEndpoints", endpointBuildItem.getEndpoints());
buildTimeConstProducer.produce(new BuildTimeConstBuildItem(NAMESPACE, buildTimeData));

String buildTimeDataImport = NAMESPACE + "-data";

webJarBuildProducer.produce(WebJarBuildItem.builder()
.artifactKey(UI_JAR)
.root(DEV_UI + "/")
.filter((fileName, file) -> {
if (fileName.endsWith(".js")) {
String content = new String(file.readAllBytes(), StandardCharsets.UTF_8);
content = content.replaceAll("build-time-data", buildTimeDataImport);
return new WebJarResourcesFilter.FilterResult(
new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), true);
}
return new WebJarResourcesFilter.FilterResult(file, false);
})
.build());
devUIWebJarProducer.produce(new DevUIWebJarBuildItem(UI_JAR, DEV_UI));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.mcollovati.quarkus.hilla.devui;

import com.github.mcollovati.quarkus.hilla.deployment.devui.EndpointBuildItem;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;

public class QuarkusHillaDevUIProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
public void pages(
BuildProducer<CardPageBuildItem> cardPageProducer,
EndpointBuildItem endpointBuildItem) {
CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();
final var page = Page.webComponentPageBuilder()
.title("Browser callables")
.icon("font-awesome-solid:table-list")
.componentLink("qwc-quarkus-hilla.js")
.staticLabel(String.valueOf(endpointBuildItem.getEndpointMethodCount()));
cardPageBuildItem.addPage(page);
cardPageProducer.produce(cardPageBuildItem);
}
}
12 changes: 12 additions & 0 deletions lit/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { LitElement, html} from 'lit';
import './../com.github.mcollovati.quarkus-hilla-commons/qwc-quarkus-hilla-browser-callables.js';

export class QwcQuarkusHilla extends LitElement {

render() {
return html`
<qwc-quarkus-hilla-browser-callables
namespace='com.github.mcollovati.quarkus-hilla'></qwc-quarkus-hilla-browser-callables>`;
}
}
customElements.define('qwc-quarkus-hilla', QwcQuarkusHilla);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.mcollovati.quarkus.hilla.devui;

import com.github.mcollovati.quarkus.hilla.deployment.devui.EndpointBuildItem;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;

public class QuarkusHillaDevUIProcessor {

@BuildStep(onlyIf = IsDevelopment.class)
public void pages(
BuildProducer<CardPageBuildItem> cardPageProducer,
EndpointBuildItem endpointBuildItem) {
CardPageBuildItem cardPageBuildItem = new CardPageBuildItem();
final var page = Page.webComponentPageBuilder()
.title("Browser callables")
.icon("font-awesome-solid:table-list")
.componentLink("qwc-quarkus-hilla-react.js")
.staticLabel(String.valueOf(endpointBuildItem.getEndpointMethodCount()));
cardPageBuildItem.addPage(page);
cardPageProducer.produce(cardPageBuildItem);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { LitElement, html} from 'lit';
import './../com.github.mcollovati.quarkus-hilla-commons/qwc-quarkus-hilla-browser-callables.js';

export class QwcQuarkusHillaReact extends LitElement {

render() {
return html`
<qwc-quarkus-hilla-browser-callables
namespace='com.github.mcollovati.quarkus-hilla-react'></qwc-quarkus-hilla-browser-callables>`;
}
}
customElements.define('qwc-quarkus-hilla-react', QwcQuarkusHillaReact);

0 comments on commit 1bcf13c

Please sign in to comment.