Extending the Dev UI

A library contributes a page or a module to the Arconia Dev UI by defining a bean. The Dev UI picks it up automatically, so the developer of the application has nothing to configure. The library describes what to show, and the Dev UI decides how to show it, so a library writes no frontend code.

Contribute a page, listed in the navigation, for something that concerns the application as a whole, like its configuration properties or its Dev Services. Contribute a module, shown as a card on the Modules page, for something that concerns one technology, such as your library (see Modules).

The Dev UI is incubating, and its APIs may change in future releases.

Dependencies

Add the Dev UI API as an optional dependency of your library. It is the only dependency on Arconia you need: the API is on the class path of an application only when the Dev UI is, during development, and never in the packaged application.

  • Gradle

  • Maven

dependencies {
    compileOnly 'io.arconia:arconia-dev-ui-api'
}
<dependency>
    <groupId>io.arconia</groupId>
    <artifactId>arconia-dev-ui-api</artifactId>
    <optional>true</optional>
</dependency>

Defining a Page

Define the page in an auto-configuration that is only active when the Dev UI API is on the class path, with @ConditionalOnClass(DevUiPage.class) on the class. Spring Boot reads that condition without loading the class, so the auto-configuration is skipped when the Dev UI is absent, as in production. Put the condition on the class, never on a @Bean method only, where the JVM would load the classes of the API before the condition applies. The following example contributes a page for FancyDB, a fictional database by Acme, with one card for each database:

@AutoConfiguration
@ConditionalOnClass(DevUiPage.class)
public final class FancyDbDevUiAutoConfiguration {

    @Bean
    CardsPage fancyDbDevUiPage(FancyDbClient client) {
        return CardsPage.builder()
                .id("fancydb")
                .title("FancyDB")
                .icon("database")
                .cards(() -> client.databases().stream()
                        .map(database -> Card.builder()
                                .id(database.name())
                                .title(database.displayName())
                                .description(database.description())
                                .status(Status.success("Online"))
                                .items(
                                        InfoItem.of("Tables", String.valueOf(database.tableCount())),
                                        InfoItem.builder().label("Engine").value(database.engine()).icon("cpu").code(true).build(),
                                        LinkItem.of("Console", database.consoleUrl()),
                                        LogItem.of("Logs", database::followLog))
                                .build())
                        .toList())
                .build();
    }

}

There are two kinds of pages. A CardsPage is for a handful of items with a few facts each, such as the services of an application. A TablePage is for long lists, such as configuration properties. Both have the following attributes:

Attribute Description

id

Required. Identifies the page in its address. It can only contain lowercase letters, digits, and single hyphens between them, and a page listed in the navigation cannot be overview or modules, which the Overview and the Modules page use: such a page is left out, and reported in the application log. A page of a module can have either. When two pages have the same identifier, only the first one in the navigation is shown, and the other is reported in the application log.

title

Required. The title of the page, shown in the navigation.

icon

The name of an icon of the Lucide icon set, shown next to the title (see Icons). Defaults to layout-grid for a cards page and table for a table page.

order

Positions the page in the navigation. Pages with a lower value come first, and pages with the same value are sorted by title. Defaults to 0, which lists the page before the Configuration section, with the other pages that are not in a section.

section

A section of the navigation to list the page in, with the other pages about the same subject. The sections are the ones DevUiSection defines, such as DevUiSection.CONFIGURATION. Inside a section, the order positions the page among the pages of the section.

Cards Pages

A cards page shows a set of cards, in as many columns as the page has room for. Set cardWidth to CardWidth.WIDE for cards with a lot of content, which then get more room each, in fewer columns.

A Card has:

  • an identifier, required, which must be unique on the page. It can be any text, such as the name of what the card is about;

  • a title, required;

  • an icon, shown next to the title;

  • a description, shown below the title, in a sentence;

  • a status, shown next to the title (see Status);

  • its tags, shown before the status: a word or two each for what makes the card different from others of its kind, such as new Tag("Shared", "Other applications can connect to this container."), with a description shown when the developer points at the tag. Leave a card without tags unless something is worth noticing;

  • a link to its documentation, an HTTP or HTTPS URL, shown as an icon in the footer of the card;

  • a prefix of the configuration properties about its subject, shown as an icon in the footer of the card that opens the Properties page with those properties;

  • its items, in the order they are shown (see Items).

The content of a card usually comes from the running application, where an unknown text is often empty. An optional text that is empty is left out, so the supplier doesn’t have to check each one. A link is different: a link without a valid URL makes the page fail, so leave the link out when there is no URL to give it.

Status

A Status is a word or two shown next to the title of a card, or in a cell of a table, with a level that decides its color: SUCCESS, WARNING, ERROR, or NEUTRAL. It is created with the method named after its level. For example, Status.success("Running").

Items

A card shows these kinds of items:

  • An InfoItem shows a piece of information with a label, as one value or as several, such as the profiles of an application. Create it with InfoItem.of("Size", "12 MB"), or with InfoItem.code("Class", "com.example.Product") when its values are code, which is shown in a fixed-width font. With InfoItem.builder(), you can also give it an icon, shown before the label. Code means anything you would type as is in code or in a command: the name of a class or of a bean, a URL, a path, a statement, the name of a property or of a container image. The name of a product, such as Hibernate, and a plain value, such as a number or a port, are not. Several code values are shown side by side, and other values are shown one per line. A value that is null is left out, and an item without any value is shown with a dash.

  • A LinkItem links to a page outside the Dev UI. Create it with LinkItem.of("Grafana", url), where the URL is an HTTP or HTTPS URL, or a path of the application that starts with a slash, such as /swagger-ui.html. A path is relative to the context path of the application. A link is shown with the same icon as every other link, unless you give it one of its own with LinkItem.of("Grafana", url, "chart-spline").

  • A MappingItem shows a few mappings, such as the ports of a container and the ports of the local machine they are published to. Add each mapping to MappingItem.builder() with mapping("5432", "54321"): first what is mapped, which is shown toned down, then what it is mapped to, which stands out. A mapping to the same thing is shown once. You can also give the item an icon and a description, shown when the developer points at its label.

  • A LogItem opens a log in a dialog and follows it live. Web addresses in its lines are links, except local ones such as http://localhost:3000. The log of a card is assumed to come from somewhere else, such as a container, where a local address points to something different. Create it with LogItem.of("Logs", source). The logs of a card must have different labels.

  • An ActionItem is a button that runs an action. Buttons are reserved for things that change something. What a card can open, its links and its logs, is shown as a list of rows, in the order of the items. Only the card of a module can have one (see Modules).

A LogSource provides the log. Its follow method passes each line to the Dev UI as it is written, and returns when the log ends. It is called on a thread of its own each time someone opens the log, and that thread is interrupted when they close it. The LogSource must then return, or let the InterruptedException through. Otherwise, the thread keeps running for as long as the log goes on. When follow throws an exception, the Dev UI shows its message in the dialog.

Table Pages

A table page has the titles of its columns and a supplier of rows. Put the subject of a row in the first column, which gets the most room and is always shown in full.

A TableRow has:

  • an identifier, required, which must be unique in the table. It can be any text;

  • one cell for each column (see Cells);

  • a description, a sentence or two about what the row is, shown first when the developer clicks the row, without a label;

  • its details, shown below the row after the description. Each detail is an InfoItem. Details are shown without icons: in a column of labels, the labels are enough.

The developer can sort the rows by any column and filter them by the text they contain. Set filterColumn to the title of a column to also let the developer choose one of its values and see the matching rows only, which works well for a column with a few values shared by many rows.

Rows are sorted by their text, whatever its case, and by their value in a column of whole numbers, so that 10 comes after 9. Any other number, such as a size with its unit, is sorted as text. A text too long to be read in the table is shown in full in the details of its row. The first column is never cut: its text continues on the next line.

When the rows together form something worth copying, such as the statements of a script, name the column to copy with copyColumn(…​). The table then has a Copy button, which copies the text of that column for the rows shown, one row per line.

The following example lists the tables of a database:

@Bean
TablePage fancyDbTablesDevUiPage(FancyDbClient client) {
    return TablePage.builder()
            .id("fancydb-tables")
            .title("FancyDB Tables")
            .columns("Table", "Database", "Owner")
            .filterColumn("Database")
            .rows(() -> client.tables().stream()
                    .map(table -> TableRow.builder()
                            .id(table.qualifiedName())
                            .cells(table.name(), table.database(), table.owner())
                            .details(List.of(InfoItem.of("Rows", String.valueOf(table.rowCount()))))
                            .build())
                    .toList())
            .build();
}

Cells

Create each cell of a row with one of the methods of TableCell:

Method What the cell shows

text(…​)

A text.

code(…​)

A text shown as code, such as a statement or a command.

secret(…​)

A text that is hidden until the developer asks to see it, such as a password. It is neither sorted nor searched.

status(…​)

A Status, in the color of its level, as on a card (see Status). It is sorted and searched by its text.

badge(…​)

A short text set apart as a badge, such as TableCell.badge("GET", BadgeEmphasis.LOW). The emphasis sets how much the badge stands out, from NONE, the default, to HIGHEST. A badge doesn’t indicate whether something is wrong. Use a status for that.

link(…​)

A link that opens in a new tab. It takes the text and the target: an HTTP or HTTPS URL, or a path of the application that starts with a slash, as for a link on a card.

choice(…​)

A text the developer can change by choosing another option (see Actions).

button(…​)

A button that runs an action on the row (see Actions).

When all the cells are plain text, cells("server.port", "8080") is a shortcut. A null text gives an empty cell, with the shortcut, text(…​), code(…​), and secret(…​).

Actions

A table page can let the developer change something about a row, such as the level of a logger. The page declares an action with a name, and the cells that offer a choice refer to it:

@Bean
TablePage fancyDbTablesDevUiPage(FancyDbClient client) {
    List<String> modes = List.of("Read-write", "Read-only");
    return TablePage.builder()
            .id("fancydb-tables")
            .title("FancyDB Tables")
            .columns("Table", "Mode")
            .rows(() -> client.tables().stream()
                    .map(table -> TableRow.builder()
                            .id(table.qualifiedName())
                            .cells(List.of(
                                    TableCell.text(table.name()),
                                    TableCell.choice("mode", table.readOnly() ? "Read-only" : "Read-write", modes)))
                            .build())
                    .toList())
            .action("mode", (rowId, value) -> client.setReadOnly(rowId, value.equals("Read-only")))
            .build();
}

A cell created with TableCell.choice(…​) shows the selected option and lets the developer choose another one. It takes the name of the action, the selected option, and all the options, which are texts. When the developer chooses one, the Dev UI calls the action with the identifier of the row and the chosen option, then loads the page again, so that it shows the effect of the change on that row and on any other.

A cell created with TableCell.button("clear", "Clear") shows a button instead. It takes the name of the action and the label of the button. When the developer clicks it, the Dev UI calls the action with the identifier of the row and an empty value, then loads the page again.

An action is a RowAction. When you write one:

  • Check what it receives. The identifier and the option come from a request, and the page that sent it may have been loaded a while ago: the row may be gone, and the option may no longer be offered.

  • Throw an IllegalArgumentException for input the action cannot accept. The Dev UI shows its message to the developer and restores the cell. Any other exception is shown as a failure of the action and reported in the application log.

  • Keep it quick and safe to call from several threads, as for the suppliers. It runs on the thread of the request.

  • Explain on the page, or in your documentation, how long the change lasts. The level of a logger set from the Loggers page, for example, is lost when the application restarts.

The Dev UI only performs an action for a request that comes from the Dev UI itself (see Accessing the Dev UI). A page fails, as described below, when one of its cells refers to an action that the page doesn’t declare.

Modules

A module is a technology the application uses, shown as a card on the Modules page. Contribute one for your library when it has something to show about the application as it runs: a state, a few facts, pages of its own, a tool it comes with, or something the developer can do with it. A card that only shows that the library is present, with a link to its documentation, is better left out.

Define a DevUiModule bean, the same way as a page (see Defining a Page):

@AutoConfiguration
@ConditionalOnClass(DevUiModule.class)
public final class FancyDbDevUiAutoConfiguration {

    @Bean
    DevUiModule fancyDbDevUiModule(FancyDbClient client) {
        return DevUiModule.builder()
                .id("fancydb")
                .title("FancyDB")
                .description("The FancyDB server this application stores its orders in.")
                .icon("database")
                .documentation("https://docs.acme.example/fancydb")
                .propertiesPrefix("acme.fancydb")
                .library("FancyDB Client", FancyDbClient.class)
                .status(() -> client.isReachable() ? Status.success("Connected") : Status.error("Unreachable"))
                .items(() -> List.of(
                        InfoItem.of("Server", client.serverUrl()),
                        LinkItem.of("Console", client.consoleUrl()),
                        ActionItem.builder().label("Reconnect").action("reconnect").message("Reconnected to FancyDB").build()))
                .action("reconnect", client::reconnect)
                .page(tablesPage(client), () -> client.tables().size())
                .build();
    }

}

A module has:

  • an identifier, required, which is part of the address of its pages. It can only contain lowercase letters, digits, and single hyphens between them;

  • a title, required, which is the name of the technology;

  • a one-sentence description of what the technology does in this application;

  • an icon, and an order: cards are sorted by order (0 by default), then by title;

  • a link to its documentation and a prefix of its configuration properties, shown in the footer of the card, as for a card of a page;

  • the libraries it builds on, each with a name and one of its classes. The Dev UI reads the version of a library from the jar the class comes from, and shows it when the developer asks for the versions of the module, with the information icon of its card. A module can name several, such as an integration and the client it wraps;

  • a supplier of its status and a supplier of its items, called each time the Modules page is shown;

  • its pages and its actions.

Pages of a Module

Add a page to a module with page(…​). It is a TablePage or a CardsPage like any other, with everything such a page can do, but it is not a bean: it is listed on the card of the module and shown under it, not in the navigation. In the example above, tablesPage(client) stands for a method that builds the table of Table Pages and returns it, without declaring it as a bean: a page that is also a bean is shown twice, in the navigation and under the module. Its identifier only has to be unique among the pages of the module, and it cannot have a section.

Give a page a supplier of a number, such as how many rows its table has, to show it next to its link on the card. It is called each time the Modules page is shown, so it should count without building the rows.

Actions of a Module

Declare an action of the module with action(name, code), and put an ActionItem that refers to it among the items of the card, where it is shown as a button. An ActionItem has a label and the name of the action. With ActionItem.builder(), you can also give it an icon, and a message shown to the developer once the action is done. For an action that cannot be undone, give it a confirmation too: a sentence or two on what the action does, which the Dev UI shows in a dialog before it runs the action, with a way to cancel, and with a title of its own if you give it one, such as a question. The button of such an action is shown in red, to tell it apart from the others. When the developer clicks the button, the Dev UI runs the action, then loads the cards again, so that they show what it changed.

An action runs on the thread of the request, possibly several at the same time. When it throws an exception, the Dev UI shows its message to the developer. Since the items are supplied each time, the card can leave a button out when there is nothing for it to do.

An action on a row of a module page is an action of that page, as for any table (see Actions).

Supplying the Content

The cards and the rows of a page, and the status and the items of a module, are supplied whenever the Dev UI needs them, and never when the application starts, so the supplier can read the current state of the application. That can be several times while someone looks at a page, for example when they reload it or open one of its logs, so keep the supplier quick and free of side effects. It can be called for two requests at the same time, so it must be safe to call from several threads.

The Dev UI shows a failure in place of the page, and reports it in the application log, when:

  • the supplier throws an exception, such as one thrown by a builder for content it rejects;

  • the supplier returns null instead of an empty list;

  • two cards of the page, or two rows of the table, have the same identifier. A log is found by the identifier of its card, and an action is performed on a row by its identifier, so it must be unique;

  • a cell of a table offers a choice or a button for an action that the page doesn’t declare.

A row that has more or fewer cells than there are columns is shown as it is, and reported once in the application log.

A module that fails doesn’t break the Modules page. Its card shows the error in place of its content, next to the cards of the other modules. That is the case when one of its suppliers throws an exception or returns null for its items, when one of its items is a button for an action that the module doesn’t declare, and when one of its items is a log, which only a card of a page can have.

The cards are loaded each time the developer opens the Modules page, all at the same time, and the page waits for them for a few seconds. A card that takes longer shows that it took too long, with the links to its pages, and is loaded again the next time the developer opens the page. So keep the suppliers of a module quick.

The status, the items, and the counts of the pages of a card are supplied one after the other each time the card is loaded. When a module reads them all from one costly call, such as a query to a database, it should keep the result of that call for a moment and supply them all from it, as the Health and Flyway modules of Arconia do.

The suppliers of a module are not called as part of a request to the application, so anything the application binds to its requests is missing, such as the security context of a user or a tenant. A supplier that needs one must bind it itself.

Icons

Pages, modules, cards, and items take the name of an icon of the Lucide icon set, such as database or container. A name can only contain lowercase letters, digits, and single hyphens between them. If the icon name doesn’t exist, a page or a module gets a generic icon, a card or an item gets none, and both cases are reported in the application log.

Choose an icon for what the subject is, such as a database or a message broker, or for what its name evokes, such as a rabbit or a telescope. The Dev UI has no way to show an image, such as the logo of a product: icons always come from the icon set, in the colors of the Dev UI.