{# Always-open query review surface used by opportunity and job details. The order is deliberately Original -> Suggested -> Diff. Users start from the query that actually ran, then inspect the proposed SQL, then use the diff for a focused review. #} {% macro query_copy_button() %} {% endmacro %} {% macro query_sql_pane(sql) %}
{{ query_copy_button() }}
{% for line in (sql or "").split('\n') %}{{ loop.index }}{{ line }}
{% endfor %}
{% endmacro %} {% macro query_review_card(primary_query_improvement=None, fallback_query="", changes_count=0) %} {% set _original_sql = fallback_query or "" %} {% set _suggested_sql = "" %} {% set _diff_lines = none %} {% set _template_id = "query" %} {% if primary_query_improvement %} {% set _original_sql = primary_query_improvement.before_content or fallback_query or "" %} {% set _suggested_sql = primary_query_improvement.after_content or "" %} {% set _diff_lines = primary_query_improvement.diff_lines %} {% set _template_id = primary_query_improvement.template_id or "query" %} {% endif %} {% set _has_suggested = _suggested_sql | length > 0 %} {% set _has_diff = _diff_lines is not none and (_diff_lines | length > 0) %} {% set _has_alternative_views = _has_suggested or _has_diff %} {% if _original_sql or _suggested_sql or _diff_lines %}

Query

{% if _has_alternative_views %} Review the query body with original, suggested, and diff views. {% else %} No deterministic SQL rewrite is available. Inspect the latest execution here. {% endif %}

{% if changes_count %} {{ changes_count }} SQL {{ "change" if changes_count == 1 else "changes" }} {% endif %}
{% if _has_alternative_views %}
{% if _has_suggested %} {% endif %} {% if _has_diff %} {% endif %}
{% endif %} {% if _has_alternative_views %}
{% endif %}
{% if _original_sql %} {{ query_sql_pane(_original_sql) }} {% else %}

No original SQL is available for this execution.

{% endif %}
{% if _has_suggested %} {% endif %} {% if _has_diff %} {% endif %} {% if _has_alternative_views %}
{% endif %}
{% endif %} {% endmacro %}