domain/converters/failure.converter.ts

domain/converters/failure.converter.ts is a file in Bane's Lab Site. 45 lines of code and 2 definitions.

import {
    BREAKS_LABEL,
    FAILURE_SHAPE_INTRO,
    FAILURE_SHAPE_TITLE,
    FIX_LABEL,
    SEEN_IN_LABEL,
    SHAPE_LABEL,
} from "#configuration/strings/reason.strings";
import { FACE_SEPARATOR, REASON_FACE } from "@govlab/constants";
import { FAILURE_SHAPE_SECTION_ID, REASON_ANCHOR } from "#core/ids/ontology.ids";
import type { FailureShapeView, ReasonView } from "#types/reason.types";
import type { Section, Subsection } from "#types/document.types";
import { canonOf, checkBlocks } from "#domain/converters/check.converter";
import { glossary, linkOf, linkRow, row } from "#domain/converters/ontology.converter";
import { CANON_LABEL } from "#configuration/strings/ontology.strings";
import { REASON_SECTION_ICON } from "#configuration/icons/ontology.icons";
import type { ResolutionView } from "#types/ontology.types";

const shapeSubsection = function shapeSubsection(shape: FailureShapeView, resolution: ResolutionView): Subsection {
    return {
        blocks: [
            glossary([
                row(SHAPE_LABEL, shape.shape),
                row(FIX_LABEL, shape.fix),
                row(BREAKS_LABEL, linkOf(shape.breaks)),
                ...linkRow(SEEN_IN_LABEL, shape.instances),
                row(CANON_LABEL, canonOf(shape.canon)),
            ]),
            ...checkBlocks(resolution, REASON_FACE + FACE_SEPARATOR + shape.anchor),
        ],
        id: REASON_ANCHOR + shape.anchor,
        title: shape.name,
    };
};

export const failureShapeSection = function failureShapeSection(
    reason: ReasonView,
    resolution: ResolutionView,
): Section {
    return {
        icon: REASON_SECTION_ICON,
        id: FAILURE_SHAPE_SECTION_ID,
        intro: FAILURE_SHAPE_INTRO,
        subsections: reason.failureShapes.map((shape) => shapeSubsection(shape, resolution)),
        title: FAILURE_SHAPE_TITLE,
    };
};