Skip to content

Commit

Permalink
Dev UI: Allow external links in submenu
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Jun 13, 2023
1 parent 35cb41a commit dc41ac7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.quarkus.devconsole.spi.DevConsoleTemplateInfoBuildItem;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.oidc.deployment.OidcBuildTimeConfig;
import io.quarkus.oidc.deployment.devservices.AbstractDevConsoleProcessor;
import io.quarkus.oidc.deployment.devservices.OidcAuthorizationCodePostHandler;
Expand Down Expand Up @@ -81,7 +82,9 @@ void produceProviderComponent(Optional<KeycloakDevServicesConfigBuildItem> confi
@SuppressWarnings("unchecked")
Map<String, String> users = (Map<String, String>) configProps.get().getProperties().get("oidc.users");

var cardPage = createProviderWebComponent(
String keycloakAdminUrl = configProps.get().getConfig().get("keycloak.url");

CardPageBuildItem cardPageBuildItem = createProviderWebComponent(
recorder,
capabilities,
"Keycloak",
Expand All @@ -97,11 +100,17 @@ void produceProviderComponent(Optional<KeycloakDevServicesConfigBuildItem> confi
oidcConfig.devui.grantOptions,
nonApplicationRootPathBuildItem,
configurationBuildItem,
configProps.get().getConfig().get("keycloak.url"),
keycloakAdminUrl,
users,
configProps.get().getProperties().get("keycloak.realms"),
configProps.get().isContainerRestarted());
cardPageProducer.produce(cardPage);

// Also add Admin page
cardPageBuildItem.addPage(Page.externalPageBuilder("Keycloak Admin")
.icon("font-awesome-solid:key")
.doNotEmbed(true)
.url(keycloakAdminUrl));
cardPageProducer.produce(cardPageBuildItem);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,27 +351,6 @@ export class QwcOidcProvider extends QwcHotReloadElement {
}

_renderProvider() {
const content = this._content();
if (propertiesState.keycloakAdminUrl) {
return html `
<vaadin-horizontal-layout
theme="spacing padding"
style="align-items: center"
>
${content}
<vaadin-button class="keycloak-btn" theme="tertiary"
@click=${() => QwcOidcProvider._goToKeycloakUrl()}>
<vaadin-icon icon="font-awesome-solid:key" slot="prefix" class="btn-icon"></vaadin-icon>
Keycloak Admin
</vaadin-button>
</vaadin-horizontal-layout>
`;
}

return content;
}

_content() {
if (QwcOidcProvider._isServiceOrHybridApp()) {
switch (propertiesState.oidcGrantType) {
case 'password':
Expand Down Expand Up @@ -933,10 +912,6 @@ export class QwcOidcProvider extends QwcHotReloadElement {
return result;
}

static _goToKeycloakUrl() {
window.open(propertiesState.keycloakAdminUrl, '_blank').focus();
}

static _areTokensInUrl() {
return QwcOidcProvider._getHashQueryStringParam('id_token')
&& QwcOidcProvider._getHashQueryStringParam('access_token');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ export class RouterController {
return false;
}

addExternalLink(page){
let path = this.getPageUrlFor(page);
if (!this.isExistingPath(path)) {
RouterController.pageMap.set(path, page);
if(RouterController.namespaceMap.has(page.namespace)){
// Existing
RouterController.namespaceMap.get(page.namespace).push(page);
}else{
// New
let namespacePages = [];
namespacePages.push(page);
RouterController.namespaceMap.set(page.namespace, namespacePages);
}
}
}

addRouteForMenu(page, defaultSelection){
this.addRoute(page.id, page.componentName, page.title, page, defaultSelection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,16 @@ export class QwcExtensionLink extends QwcHotReloadElement {
<vaadin-icon class="icon" icon="${this.iconName}"></vaadin-icon>
${this.displayName}
</span>
${this._renderBadge()}
</a>
${this._renderBadge()}
`;
}else{
return html`<a class="extensionLink" ?router-ignore=true>
<span class="iconAndName">
<vaadin-icon class="icon" icon="font-awesome-solid:spinner"></vaadin-icon>
loading ...
</span>
${this._renderBadge()}
</a>`;
</a>${this._renderBadge()}`;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export class QwcExtensions extends observeState(LitElement) {
if(page.embed){ // we need to register with the router
import(page.componentRef);
this.routerController.addRouteForExtension(page);
}else if(page.includeInSubMenu){ // we need to add the link to the submenu
this.routerController.addExternalLink(page);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public ExternalPageBuilder mimeType(String mimeType) {
}

public ExternalPageBuilder doNotEmbed() {
return doNotEmbed(false);
}

public ExternalPageBuilder doNotEmbed(boolean includeInSubMenu) {
super.embed = false;
super.includeInSubMenu = includeInSubMenu;
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class Page {
private final Map<String, String> metadata; // Key value Metadata

private final boolean embed; // if the component is embedded in the page. true in all cases except maybe external pages
private final boolean includeInSubMenu; // if this link should be added to the submenu. true in all cases except maybe external pages
private final boolean internalComponent; // True if this component is provided by dev-ui (usually provided by the extension)

private String namespace = null; // The namespace can be the extension path or, if internal, qwc
Expand All @@ -36,6 +37,7 @@ protected Page(String icon,
String componentLink,
Map<String, String> metadata,
boolean embed,
boolean includeInSubMenu,
boolean internalComponent,
String namespace,
String namespaceLabel,
Expand All @@ -50,6 +52,7 @@ protected Page(String icon,
this.componentLink = componentLink;
this.metadata = metadata;
this.embed = embed;
this.includeInSubMenu = includeInSubMenu;
this.internalComponent = internalComponent;
this.namespace = namespace;
this.namespaceLabel = namespaceLabel;
Expand Down Expand Up @@ -125,6 +128,10 @@ public boolean isEmbed() {
return embed;
}

public boolean isIncludeInSubMenu() {
return includeInSubMenu;
}

public boolean isInternal() {
return this.internalComponent && this.extensionId == null;
}
Expand All @@ -149,7 +156,8 @@ public String toString() {
+ ", \n\tnamespaceLabel=" + namespaceLabel
+ ", \n\tcomponentName=" + componentName
+ ", \n\tcomponentLink=" + componentLink
+ ", \n\tembed=" + embed + "\n}";
+ ", \n\tembed=" + embed
+ ", \n\tincludeInSubMenu=" + includeInSubMenu + "\n}";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public abstract class PageBuilder<T> {
protected String componentLink;
protected Map<String, String> metadata = new HashMap<>();
protected boolean embed = true; // default
protected boolean includeInSubMenu = true; // default
protected boolean internalComponent = false; // default
protected String namespace = null;
protected String namespaceLabel = null;
Expand Down Expand Up @@ -128,6 +129,7 @@ public Page build() {
componentLink,
metadata,
embed,
includeInSubMenu,
internalComponent,
namespace,
namespaceLabel,
Expand Down

0 comments on commit dc41ac7

Please sign in to comment.