Skip to content

Sort scenarios in comparisons consistently wherever displayed#178

Open
david-mears-2 wants to merge 3 commits intomainfrom
sort-options
Open

Sort scenarios in comparisons consistently wherever displayed#178
david-mears-2 wants to merge 3 commits intomainfrom
sort-options

Conversation

@david-mears-2
Copy link
Copy Markdown
Contributor

@david-mears-2 david-mears-2 commented Nov 18, 2025

When parameter metadata specifies an ordering, we should use that to determine the order in which scenarios display, in three places:

  • Costs chart
  • Costs table
  • Time series legend

Summary by CodeRabbit

  • Improvements

    • Scenarios in comparison views—charts, legends, and tables—now consistently display in a sorted order for clearer, aligned side-by-side comparisons.
  • Tests

    • Unit tests updated to assert exact scenario ordering in comparison components, tightening expectations to ensure consistent rendered sequence.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 38.05%. Comparing base (e3d51ca) to head (1ab9421).

Files with missing lines Patch % Lines
composables/useSortedScenarios.ts 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
+ Coverage   38.04%   38.05%   +0.01%     
==========================================
  Files         100      101       +1     
  Lines      148323   148348      +25     
  Branches      964      972       +8     
==========================================
+ Hits        56424    56449      +25     
- Misses      91884    91885       +1     
+ Partials       15       14       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f8208906-e251-431f-a857-c19ad12214a3

📥 Commits

Reviewing files that changed from the base of the PR and between a216ad8 and 1ab9421.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • composables/useSortedScenarios.ts

📝 Walkthrough

Walkthrough

Adds a new useSortedScenarios composable to produce a consistently ordered scenario list (based on axis metadata). Three UI components (costs chart, time-series legend, costs table) now consume sortedScenarios. Unit tests were tightened to assert exact scenario ordering.

Changes

Cohort / File(s) Summary
New Sorting Composable
composables/useSortedScenarios.ts
Adds default-export composable that accepts a reactive Scenario[] and returns sortedScenarios computed by ranking each scenario's axis value against sorted axis options; falls back to original order when single scenario or metadata missing.
Charts — Costs Chart
components/Charts/Compare/CompareCostsChart.client.vue
Replaces direct use of raw scenarios with sortedScenarios for series construction, second-level cost breakdown discovery, per-scenario data mapping, and xAxis.categories (initial and on diff toggle).
Charts — Legend
components/Charts/Compare/CompareTimeSeriesLegend.vue
Derives legend items from sortedScenarios (via useSortedScenarios) and maps colors/labels using the sorted index; baseline labeling logic preserved.
Table — Costs
components/CostsTable.vue
Uses sortedScenarios for rendering scenario columns (headers and body loops); replaces prior local scenariosToDisplay with a filtered scenarios passed into the sorter.
Unit Tests Updated
tests/unit/components/Charts/Compare/CompareCostsChart.spec.ts, tests/unit/components/Charts/Compare/CompareTimeSeriesLegend.spec.ts, tests/unit/components/CostsTable.spec.ts
Tightened assertions to require exact category/column ordering and exact series point ordering; test fixtures reordered to match expected sorted scenario sequences.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through scenarios, tidy and neat,
Sorted by axes, each column in seat.
Charts and tables now march in line,
Baseline and breakouts all looking fine.
A little rabbit clap, for order divine!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing consistent scenario sorting across comparison displays based on parameter metadata ordering.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sort-options

Review rate limit: 2/3 reviews remaining, refill in 20 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@components/Charts/Compare/CompareCostsChart.client.vue`:
- Around line 40-41: The chart currently only reacts to changes in costBasis and
diffing, but sortedScenarios (from useSortedScenarios) is the new source of
truth for ordering — add sortedScenarios as a reactive dependency so the chart
rebuilds when order changes: update the watcher/effect that constructs
categories and series (the logic that reads costBasis/diffing to build
categories/series and calls the chart update) to also subscribe to
sortedScenarios (or add a separate watcher on sortedScenarios) and trigger the
same rebuild/update routine; reference sortedScenarios, useSortedScenarios, and
the chart update function so categories/series never become stale when scenario
order updates.

In `@composables/useSortedScenarios.ts`:
- Around line 8-22: The code currently mutates the derived scens array in-place
(scens.sort) and treats missing axis values as indexOf == -1 which places them
before valid options; fix by working on a shallow copy of toValue(scenarios)
(e.g., const sorted = [...toValue(scenarios)]) and sort that copy instead of
scens, and change the comparator around appStore.getScenarioAxisValue to handle
undefined explicitly by mapping missing values to a defined rank (e.g., const
missingRank = sortedOptions.length and use sortedOptions.indexOf(value) >= 0 ?
sortedOptions.indexOf(value) : missingRank) or build a lookup map from
sortedOptions to ranks to avoid indexOf, then return the copied sorted array
(not mutating the original scenarios).
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f49cb12f-a664-4c4c-9d2b-8740c2b9b442

📥 Commits

Reviewing files that changed from the base of the PR and between e3d51ca and a216ad8.

📒 Files selected for processing (7)
  • components/Charts/Compare/CompareCostsChart.client.vue
  • components/Charts/Compare/CompareTimeSeriesLegend.vue
  • components/CostsTable.vue
  • composables/useSortedScenarios.ts
  • tests/unit/components/Charts/Compare/CompareCostsChart.spec.ts
  • tests/unit/components/Charts/Compare/CompareTimeSeriesLegend.spec.ts
  • tests/unit/components/CostsTable.spec.ts

Comment thread components/Charts/Compare/CompareCostsChart.client.vue
Comment thread composables/useSortedScenarios.ts Outdated
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 1 unresolved review comment.

Files modified:

  • composables/useSortedScenarios.ts
  • package-lock.json

Commit: 1ab9421cbc7611f1112b42283e093dc7df1957b7

The changes have been pushed to the sort-options branch.

Time taken: 5m 44s

Fixed 2 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant