* One cost block, built from sections that are already there. * * `undefined` when the lens behind it is off, which is how a facet keeps * subtracting on this level too. An empty block is not the same thing: a lens * that is on and found nothing renders its heading and the sentence saying so.
(
sections: readonly TwinSection[],
name: string,
title: string,
lead: string,
emptyText: string,
from: readonly string[]
)
| 950 | * that is on and found nothing renders its heading and the sentence saying so. |
| 951 | */ |
| 952 | function costBlock( |
| 953 | sections: readonly TwinSection[], |
| 954 | name: string, |
| 955 | title: string, |
| 956 | lead: string, |
| 957 | emptyText: string, |
| 958 | from: readonly string[] |
| 959 | ): TwinReaderBlock | undefined { |
| 960 | const used = from |
| 961 | .map((sectionName) => sections.find((section) => section.name === sectionName)) |
| 962 | .filter((section): section is TwinSection => section !== undefined); |
| 963 | if (used.length === 0) { |
| 964 | return undefined; |
| 965 | } |
| 966 | // Rows from more than one family keep the family name as their group, so a |
| 967 | // reader can see that "what moves" is three questions answered together. |
| 968 | const rows: TwinRow[] = used.flatMap((section) => section.rows.map((row) => ({ |
| 969 | ...row, |
| 970 | id: `${section.name}-${row.id}`, |
| 971 | group: used.length > 1 ? section.title : row.group |
| 972 | }))); |
| 973 | return { |
| 974 | name, |
| 975 | title, |
| 976 | lead, |
| 977 | rows, |
| 978 | emptyText, |
| 979 | ...(rows.length > 0 ? { weight: costWeight(rows.length) } : {}) |
| 980 | }; |
| 981 | } |
| 982 | |
| 983 | function senior(ir: SemanticIR, presentation: ResolvedPresentation): TwinViewModel { |
| 984 | const sections = visibleSections(ir, presentation); |