Hide a section when its data is thin
A section has nothing worth showing for some properties — no tour, no units, too few photos — and should disappear rather than render empty.
Goal
Make a section drop out of the page for the properties it has no material for,
by deriving visible or hidden from the property's own facts.
Prerequisites
The workspace from Start, and a section whose value depends on media
the property may not have — a gallery, a tour, a units table. Skim
Facts and provenance: a visibility rule is a
compute() binding like any other, and the facts view it receives is the same
one.
Steps
1. Declare the axis
display.visibility is a select entry, and it is the one display axis whose
vocabulary is fixed: exactly the two cases visible and hidden. Declared
order sets the failure posture — write hidden first for a section that should
stay out unless a fact argues for it.
import { compute, fact, fill, Section, section, select, Slot, text } from "@homepages/concrete";
export const Gallery = section(
{
key: "gallery",
label: "Gallery",
display: {
visibility: select({
from: ["visible", "hidden"],
source: compute({ reads: [fact.property.property_media] }, (media) =>
media.filter((asset) => asset.kind === "image").length >= 3 ? "visible" : "hidden",
),
}),
},
slots: {
caption: text.short({
label: "Caption",
cap: 60,
source: fill.write({
reads: [fact.property.description],
brief: "Name what makes the property worth seeing. Write one sentence. Confident and short.",
}),
}),
},
},
({ slot }) => (
<Section>
<Slot.Text slot={slot.caption} as="p" />
</Section>
),
);Any other vocabulary is refused at contract/display,
as is a second origin beside the compute() one. locked is refused here too:
locking a section into view is the composition's job, not the axis's — that is
required on the section.
2. Write the predicate over facts, not over content
The callback receives the derive-time facts view, so it may read the property's
media and its fields, and nothing a user typed. The media arrives in sorted lists of
media records — fact.property.property_media for what shows the property,
fact.property.floor_plans for its plans — so the predicate reads the list that
holds what it counts and filters it by kind. A few shapes that recur:
import { type Media, compute, fact } from "@homepages/concrete";
const isPhoto = (asset: Media): boolean => asset.kind === "image";
const hasPhotos = compute({ reads: [fact.property.property_media] }, (media) => (media.filter(isPhoto).length >= 3 ? "visible" : "hidden"));
const hasTour = compute({ reads: [fact.property.property_media] }, (media) => (media.some((asset) => asset.kind === "tour") ? "visible" : "hidden"));
const hasPlans = compute({ reads: [fact.property.floor_plans] }, (plans) => (plans.length > 0 ? "visible" : "hidden"));
const hasUnits = compute({ reads: [fact.property.units] }, (units) => (units.length > 0 ? "visible" : "hidden"));Keep the threshold in the predicate rather than in the markup. A section that renders a three-up grid needs three photographs, and a section that renders one needs one: the number belongs where the decision is made, so the editor and the page agree about which properties get the section at all.
A fact the view does not carry fails at
contract/source with the bucket it could not resolve.
3. Let the renderer stay simple
A hidden section does not render, so the markup behind it never has to hold a "nothing here" branch:
import { compute, fact, fill, Section, section, select, Slot, tour } from "@homepages/concrete";
export const Tour = section(
{
key: "tour",
label: "Tour",
display: {
visibility: select({
from: ["visible", "hidden"],
source: compute({ reads: [fact.property.property_media] }, (media) => (media.some((asset) => asset.kind === "tour") ? "visible" : "hidden")),
}),
},
slots: {
walkthrough: tour({
label: "Walkthrough",
from: fact.property.property_media,
source: fill.pick({ brief: "The whole-home walkthrough, not a single-room scan." }),
}),
},
},
({ slot }) => (
<Section>
<Slot.Tour slot={slot.walkthrough} className="aspect-video w-full" />
</Section>
),
);4. Author a fixture that is hidden
Write a second fixture on a bare property — one with no tour, or with fewer
photos than the threshold — so both postures are rendered by the check and both
are one click apart in the playground. A workspace with no fixture at all cannot
be graded here at all (fixtures/none).
Verify
Run concrete dev and switch fixtures: the section is on the page for the rich
property and absent for the thin one, with no empty heading left behind. Then run
concrete check — the contracts stage grades the axis, and the render stage
renders what is left.
Add a display variant
One section draws different fields in different cases — a description for one home, a residences table for several — and the user switches between them, starting from the case the section's own slots suggest.
Follow another section's value
Two sections have to agree — a footer echoing the hero, a gate printing the property's name — so one slot mirrors or derives from the other.
