Esc
Documentation
On this page

A page is a route in your adapter. When someone opens a URL under a service, DSUI finds the page whose path matches, calls its render function, and sends the resulting tree of components to the browser. A page composes builtin components and binds them to resources and actions.

Define a page#

path must start with /. render returns one component or an array of them:

ts
import {
  definePage,
  PageHeader,
  Table,
} from "@northgraindata/dsui-adapter-sdk";
import { status } from "./resources.js";

export const overview = definePage({
  path: "/",
  render: () => [
    PageHeader({ title: "Overview" }),
    Table({ source: status() }),
  ],
});

Register the page in pages of defineAdapter.

Route params#

A segment that starts with : is a param. TypeScript infers the params from the path, DSUI decodes them, and every value is a string:

ts
export const hello = definePage({
  path: "/hello/:name",
  render: ({ params }) => [PageHeader({ title: params.name })],
});

For /hello/Ada%20Lovelace, params.name is Ada Lovelace. A URL matches only when it has the same number of segments as the path, and a path can’t have wildcards. When no page matches, DSUI answers No page matches URL: <path>.

Query values#

query is a standard URLSearchParams for the query string of the URL:

ts
export const search = definePage({
  path: "/search",
  render: ({ query }) => [
    PageHeader({ title: `Search: ${query.get("q") ?? ""}` }),
    Table({ source: results({ text: query.get("q") ?? "" }) }),
  ],
});

Compose components#

Components take resources as source and actions as action:

ts
definePage({
  path: "/warehouses",
  render: () => [
    PageHeader({
      title: "Warehouses",
      actions: [Button({ label: "Refresh", action: flush() })],
    }),
    Section({
      title: "Compute",
      content: Table({ source: warehouses() }),
    }),
  ],
});

Add actions to table rows#

A row action names an action and maps the action’s input from the row’s columns. Pass the action definition, or its ID as a string, and an input object whose keys are the action’s input fields and whose values are column names:

ts
Table({
  source: warehouses(),
  rowActions: [
    {
      label: "Suspend",
      variant: "danger",
      action: suspendWarehouse,
      input: { warehouse: "name" },
      when: { field: "status", equals: "RUNNING" },
      confirmation: {
        title: "Suspend warehouse?",
        description: "Running queries will be cancelled.",
      },
    },
  ],
});

Use stores in a page#

render also receives a stores accessor. stores.use(store) returns the state and the actions of a store, and it makes the page render again when the state changes. stores.get(store) returns only the current state and doesn’t subscribe the page.

ts
definePage({
  path: "/warehouses",
  stores: [filterStore],
  render: ({ stores }) => {
    const { status } = stores.use(filterStore);
    return [Table({ source: warehousesFiltered({ status }) })];
  },
});

Listing a store in stores creates a page-scoped instance of it, which lasts while the page is open. See stores for scopes and persistence.