# Rows and checklists

### One action per checklist row

A [checklist](https://legatobar.com/docs/card-lists.md#checklist) whose `items` are mapped with `each` can carry an `itemAction` next to its `actions`: one action object, with the same fields as a button, that runs for the row you tick. Its `path`, `body` strings and `headers` are templates filled from that row of the source's answer, so `{id}` is the task's own id. This is the Todoist page's checklist, which closes a task:

```json
{ "id": "due-now", "type": "checklist", "label": "Next up", "items": [],
  "source": { "ref": "todoist", "map": { "items": { "each": "due.results", "sort": "due.date", "limit": 4,
    "lookup": { "from": "projects.results", "by": "id", "on": "project_id", "as": "project" },
    "fields": { "text": "content", "detail": { "template": "{due.date|day} · {project.name}" }, "done": "checked" } } } },
  "itemAction": { "label": "Complete", "icon": "checkmark", "method": "POST", "path": "/api/v1/tasks/{id}/close" } }
```

A repeating task closed this way moves to its next date, which Todoist works out, and leaves the list once that date is ahead. Closing a parent task closes its subtasks too.

- A row that isn't done shows an empty circle; click it and the request goes out with that row's values. Done rows don't fire. The `label` names the action for VoiceOver and the row's tooltip.
- A value filled into the `path` is percent-encoded, so an id holding `/` or `?` can't name another route. Body strings and header values are filled as they are. The filled path must still start with `/`.
- `when` tests the row rather than the whole answer: `{ "path": "priority", "gt": 1 }` leaves low-priority rows plain.
- With [`graphql`](https://legatobar.com/docs/buttons.md#buttons-that-send-graphql) in place of `body`, a tick sends a GraphQL mutation: the row fills its `variables`, and there a string that is one placeholder alone keeps its type, as on a row's button.
- A row the answer leaves without a value for a placeholder gets no request; the Source Preview window lists such rows under Issues, so you can see it before a tick does nothing.
- The row spins until the source answers again (at most a minute), then shows whatever the service now says: the task gone, or ticked. Success, failure reasons, cooldowns and sign-in all work as for a button.

With `"mark": "switch"`, the rows are things that are on or off, and a press acts on a row that's on as well as one that's off, so one toggle request serves both. This is a Home Assistant card of the lights that are on, each with a bulb that turns it off; its source's template answers `lights_on` as a list of `{ "name", "id", "on" }`:

```json
{ "id": "lights", "type": "checklist", "label": "Lights on", "mark": "switch", "items": [],
  "source": { "ref": "home-assistant", "map": { "items": { "each": "lights_on", "limit": 20,
    "fields": { "text": "name", "done": "on", "icon": { "template": "lightbulb" } } } } },
  "itemAction": { "label": "Turn off", "method": "POST", "path": "/api/services/light/toggle",
    "body": { "entity_id": "{id}" } } }
```

### Sending the row back

Some services replace a whole item with whatever you send: Mealie's shopping items take a `PUT` of the full item, and a body of just `{ "checked": true }` empties its note and quantity. For those, add `"body_from": "row"`. The tick then sends the row's element as the service sent it, with the fields in `body` laid over it:

```json
"itemAction": { "label": "Tick", "icon": "checkmark", "method": "PUT",
  "path": "/api/households/shopping/items/{id}", "body_from": "row", "body": { "checked": true } }
```

- The element goes back as it came, nulls and nested objects included. Fields Legato added to the row (a `lookup`) aren't sent, and nothing copied from the row is read for placeholders, so a note that says `{id}` stays as written.
- `body` is an object, and each of its fields replaces the element's field of the same name. Its strings are filled from the row as usual, and `{action.id}` there is the press's id.
- `map.items` must read a request's answer with `each`, not a `derive`d value, and without `entries`, `zip`, `flatten` or `group`, which make new rows. The page won't load otherwise.
- The method is `PUT`, `PATCH` or `POST`. It can't go with `form` or `graphql`, and only a checklist's `itemAction` takes it.
- The element is as the source last answered. If someone changed the item in the service since then, the tick puts back what Legato saw, so give the source a short `every`.
- A body over 256 KB isn't sent: the tick says so.

### Buttons on each row

A [list](https://legatobar.com/docs/card-lists.md#list) or [pacing](https://legatobar.com/docs/card-numbers.md#pacing) card whose `items` are mapped with `each` can carry `row_actions`: up to three places for buttons at the end of every row's first line, each filled from that row. A pacing row's bar and detail line, and a list row's grey line, run the card's full width under them. This is a media server's Now playing card, with Message and Stop on each stream:

```json
{ "id": "now", "type": "pacing", "label": "Now playing", "items": [],
  "source": { "ref": "media", "map": { "items": { "each": "streams",
    "fields": { "key": "id", "label": "title", "value": "minutes", "target": "length" } } } },
  "row_actions": [
    { "label": "Message", "icon": "bubble.left.and.bubble.right", "method": "POST", "path": "/Sessions/{id}/Message",
      "body": { "Header": "Legato", "Text": "{input.text}", "TimeoutMs": 10000 },
      "inputs": [ { "name": "text", "label": "Message", "required": true, "max": 120 } ], "submit": "Send" },
    { "label": "Stop", "icon": "stop.fill", "method": "POST", "path": "/Sessions/{id}/Playing/Stop",
      "confirm": { "message": "Stop {title} for {user}?", "button": "Stop" },
      "when": { "path": "can_control", "equals": true } } ] }
```

- Each button has a button's fields: `label`, `icon`, `method`, `path`, `body`, `headers`, `when`, `success`, `error`, `completion`, `confirm` (`true`, or `message` and `button`), `graphql`, `form` and `inputs` (a [form](https://legatobar.com/docs/button-input.md#buttons-that-ask-for-text)). It needs an SF Symbol `icon`, which is what the row draws; the `label` is its tooltip and what VoiceOver says.
- A bare `{x}` reads that row of the source's answer, as `itemAction` does, so `{id}` is the stream's own id. `{answer.…}` reads the card's whole answer, `{input.…}` what the form sends, and `{action.id}` the press's own id. A row field called `answer`, `input` or `action` is never read: those names come first.
- A value filled into the `path` is percent-encoded and must be a single value: an empty one, `.` or `..` can't go there. In the `body`, a string that is one placeholder alone keeps its type, so a number stays a number, as on a button. **This differs from `itemAction`**, which fills every body value as text.
- `headers` take fixed values only: a row's values never go in a header.
- A row's button can send a GraphQL mutation with [`graphql`](https://legatobar.com/docs/buttons.md#buttons-that-send-graphql) in place of `body`. The row's values go in its `variables`, as in `"variables": { "id": "{id}" }`, and the query goes as written.
- `when` tests the row. A row it fails has no button there, and the button's place stays empty, so the others don't move.
- `"alternate": true` puts a button in the place of the one before it, for the other half of an on/off pair such as Stop and Start. Give the two `when`s that never hold on the same row; if both do, the first one shows. A card can list four buttons this way, in three places: Stop, Start (its alternate), Remove and Delete files. The first button can't be an alternate, and an alternate can't follow another. A row that lacks a value the button needs (a stream with no `user` for Stop's question) shows the button dimmed, saying why, and the Source Preview window lists it under Issues.
- The buttons show under the pointer, with keyboard focus and while one runs; the first line keeps their room the rest of the time, so nothing moves. Give the card `"row_actions_shown": "always"` to show them on every row all the time, as a download queue does. When no row on the card has a button now (no stream can be controlled), the rows take the full width instead. VoiceOver offers them as the row's actions.
- On a list, `"row_actions_place": "detail"` draws the buttons as one small group over the row's detail, such as its amount, and only under the pointer or with keyboard focus. The rows keep no room for them, so the list reads like any list until you point at a row, as in a mail app. It suits rows you mostly read and sometimes answer, such as an agent's questions. The group sits in one white capsule, as a mail app's hover actions do: plain icons, the one under the pointer in a soft round highlight. It can't go with `row_actions_shown` set to `always`, and a pacing card keeps its buttons at the end of the first line.
- On a list, `"row_actions_place": "row"` draws no buttons at all: a click on a row presses the first button that row offers, which usually opens its form, as clicking a message opens it in a mail app. The row lights under the pointer as a link does, and a row that offers no button keeps its `url`. It takes no `row_actions_shown`.
- On a list with `"row_actions_place": "detail"`, put `"|"` between two buttons to draw a thin line. `"row_actions": [{ "label": "Accept", … }, "|", { "label": "Reject", … }, { "label": "Choose category", … }]` sets Accept apart. It goes only between two buttons, never between an alternate and its partner, and takes no place of its own.
- `confirm` asks in the row: its question takes the row's text, and ✕ and ✓ take the icons' place. A form opens in the page's place, titled with the button and the row. Only one question or form is open at a time.
- A question or form acts only on the row it was opened for. When the row changes what it shows (another episode in the same session), the question closes with a note; when the row leaves (the stream ended), it closes quietly. A form's Send says so instead.
- The button spins until the source answers again (at most a minute), as a checklist row does.
- `done_note` (1–12 characters, such as `"Passed"`) is what the row says after the service accepts a press. The words sit where the row's icons were, for two minutes, whenever the pointer is elsewhere, and the row keeps its size. Use it when a press changes nothing else on the row, as with a test that passes. A refused press shows its reason under the card instead, and pressing again clears the words.
- Rows come and go, so row buttons are never offered to Spotlight, Shortcuts or notifications. The card's own `actions` are, as always.
- Not on a checklist (which has `itemAction`), a `shelf` list, a `ring` or `rings` pacing card, or a list with `ask` or `copyable`.

