GitHub

If / Else

A breakdown table for a conditional routing step — every branch and its verdict up top, then a per-branch breakdown of each comparison (field, operator, expected, actual, result), with the branch that was taken highlighted.

An if/else block routes a run down one of several branches by evaluating conditions against the data. The If / Else component renders that evaluation as a breakdown table: a summary of every branch (IF, ELSE IF, ELSE) and its verdict up top, then a per-branch breakdown of each comparison — the field, the operator, the expected and actual values, and whether it held. The branch that was taken is highlighted, and branches skipped because an earlier one matched are dimmed.

Sub-conditions are combined with the branch's logical operator (AND / OR), shown inline in the formula and colored green or red by outcome.

Usage

Pass a run describing the branches and which one was taken. Everything is presentation only — wire it to whatever your evaluation data looks like.

import { ConditionalBreakdownTable } from "@/registry/new-york-v4/blocks/conditional-block"
 
export function Example() {
  return (
    <div className="h-[520px] overflow-hidden rounded-xl border">
      <ConditionalBreakdownTable
        run={{
          selectedBranchId: "if",
          branches: [
            {
              id: "if",
              kind: "if",
              logicalOperator: "and",
              matched: true,
              subConditions: [
                {
                  path: "data.total_amount",
                  operator: "is_greater_than",
                  expected: 10000,
                  actual: 13541.34,
                  matched: true,
                },
              ],
            },
            { id: "else", kind: "else", matched: true, skipped: true },
          ],
        }}
      />
    </div>
  )
}

The ConditionalBlock export wraps the table with a sample evaluation so it renders on its own with no props.

API

ConditionalRun

FieldTypeDescription
branchesBranchEval[]The branches, in evaluation order.
selectedBranchIdstring | nullThe id of the branch that was taken — highlighted in the table.

BranchEval

FieldTypeDescription
idstringStable identifier, matched against selectedBranchId.
kind"if" | "else_if" | "else"Drives the branch badge and label.
logicalOperator"and" | "or"How sub-conditions combine. Ignored for else.
subConditionsSubConditionEval[]The comparisons in this branch. Omit/empty for else.
matchedbooleanWhether the branch evaluated to true.
skippedbooleanTrue when a prior branch matched first — the row is dimmed and no breakdown is shown.

SubConditionEval

FieldTypeDescription
pathstringField path read from the input (a leading data. / likelihoods. prefix is stripped for display).
operatorstringOperator key such as is_greater_than, is_equal_to, contains, exists — rendered with a readable symbol/label.
expectedunknownValue compared against. Hidden for unary operators (exists, is_empty, is_true, …).
actualunknownValue found in the input.
matchedbooleanWhether this comparison held — shown as a true/false pill.

Components

ExportPropsDescription
ConditionalBreakdownTable{ run: ConditionalRun }The full breakdown table.
ConditionalBlock{ run?: ConditionalRun }The table preloaded with a sample evaluation; pass run to override.