Skip to main content

This is an exploration of how to prototype the GOV.UK app, not something to build on yet.

Lists and the data bank

Looking facts up, and showing and filtering lists of them.

The data bank

A prototype carries no data of its own. It takes facts from the data bank, in bank/, which is made up, so a journey behaves like the real thing without anyone’s details. Each table is checked against its own schema in schema/0/.

A prototype names the tables it uses, with the version of each table’s shape it was written to:

"uses": { "councils": "0" }

The councils table finds the councils, or the addresses, for a postcode. Try RV1 2AB, NM3 5QT or WE7 9LP: bank/README.md says what each finds.

Derived values

derived values are worked out from others, and used by name like any other. Each is worked out again whenever what it depends on changes.

lookup finds a table’s entry by a value, and is missing if there isn’t one:

"derived": {
  "match": { "lookup": { "table": "councils", "key": "postcode", "normalise": ["uppercase", "remove-spaces"] } }
}

pick takes the item of a list at the position another value holds, such as the row chosen from a list:

"picked-council": { "pick": { "from": "match.councils", "at": "chosen-council" } }

condition is whether a condition holds, true or false: see naming a condition.

A derived value is the same wherever it’s used. Inside a group with each, it doesn’t see the group’s item.

Filtering a list

filter keeps the items of a list that a condition holds for, in order. Inside where, item is the item and index its position, from 0. Pages whose keywords are in what was searched for:

"results": { "filter": { "from": "pages", "where": { "contains": { "text": "query", "words": "item.keywords" } } } }

Show them with a group with each, and say when there are none with missing, as an empty list is missing:

{ "type": "group", "each": "results", "children": [{ "type": "link-card", "attributes": { "href": "{{ item.url }}" }, "text": "{{ item.title }}" }] },
{ "type": "text", "text": "No results", "when": { "missing": "results" } }

Showing a list

A group with each shows its children once for each item of a list. Inside it, item is the item and index its position, from 0:

{
  "type": "grouped-list",
  "children": [
    {
      "type": "group",
      "each": "match.councils",
      "children": [
        { "type": "grouped-list-row", "attributes": { "type": "selectable", "value": "{{ index }}" }, "text": "{{ item.name }}", "name": "chosen-council", "chosen": { "icon": "check" }, "validation": [{ "rule": "required" }] }
      ]
    }
  ]
}

Each row is a choice, with its position as its value, and picked-council turns the position chosen back into the council.