concrete/sections/row-projection-list
An unlocked list's `compute()` builds its items from a table's columns, losing each item's row: hold rows `from` the table, the compute returning the rows the list starts with, or declare the list `locked`.
An unlocked list's compute() builds its items from a table's columns, losing each item's row: hold rows from the table, the compute returning the rows the list starts with, or declare the list locked.
Graded by the sections stage of concrete check, in the probe venue. A violation reports this id and the file it failed at — see every rule and concrete check.
Reason
A list whose compute() reads a table's columns and builds its items from them (the
units' labels, the contacts' logos) keeps each member's value and drops the row it came from.
In the editor, the user then sees a list of bare values. They cannot tell which unit or
contact an item stands for, they cannot choose another row in its place, and an edit to
the value changes the copy in the list rather than the member where it lives. A unit
renamed in the list is still named the old way everywhere else.
The rule grades an unlocked list sourced by a compute() that reads a table column
(fact.property.units.label). A locked list offers the user no interface, so it loses
nothing and is exempt, and a list of select items holds options of a closed vocabulary,
never a row's value. Column reads stay legal everywhere else: a compute yielding one value
(a beds range, a "from" price), a select's options, and a fill's reads.
Fix
Hold the rows. Give the list an item holding a row from the table, read the item's
other fields off that row, and make the compute return the rows the list starts with.
The compute is the list's default: it follows the table as rows are added or change,
and each item reads and edits its members where the row stores them.
Where the list is vocabulary nobody arranges (the options of one <select> that must
always name every unit), declare it locked: true instead.
Before and after
import { compute, fact, list, Section, section, Slot, text } from "@homepages/concrete";
// Each option is a unit's label with the unit lost.
export const Visit = section(
{
key: "visit",
label: "Visit",
slots: {
unit_options: list({
label: "Units",
source: compute({ reads: [fact.property.units.label] }, (labels) => labels.map((label) => label ?? "")),
item: text.short({ label: "Unit", cap: 80 }),
}),
},
},
({ slot }) => (
<Section>
<Slot.List slot={slot.unit_options} as="ul" />
</Section>
),
);import { bindItems, compute, fact, list, object, row, Section, section, Slot, text } from "@homepages/concrete";
export const Visit = section(
{
key: "visit",
label: "Visit",
slots: {
// Every unit by default; each item is a unit, named where the unit lives.
unit_options: list({
label: "Units",
source: compute({ reads: [fact.property.units] }, (units) => units),
item: (el) => {
const unit = row({ label: "Unit", from: fact.property.units, source: el });
const name = text.short({ label: "Unit name", cap: 80, source: unit.label });
return object({ label: name, fields: { unit, name } });
},
}),
},
},
({ slot }) => (
<Section>
<Slot.List slot={slot.unit_options} as="ul">
{bindItems(slot.unit_options).map((item) => (
<Slot.Object key={item.index} slot={item} as="li">
<Slot.Text slot={item.name} as="span" />
</Slot.Object>
))}
</Slot.List>
</Section>
),
);concrete/sections/whole-table-read
A `compute()` reads a whole table (`fact.property.units`), which counts every member of the table as used. Where the value needs only some members, reading those columns (`fact.property.units.beds`) narrows what the template asks of a property. A hint: it never fails `check`.
concrete/sections/schema-invalid
A section's materialized schema or fill spec fails to parse.
