Skip to content

feat(trees): sort Chronostrat tree by period instead of name, add ranges#8254

Open
grantfitzsimmons wants to merge 12 commits into
mainfrom
issue-6049
Open

feat(trees): sort Chronostrat tree by period instead of name, add ranges#8254
grantfitzsimmons wants to merge 12 commits into
mainfrom
issue-6049

Conversation

@grantfitzsimmons

@grantfitzsimmons grantfitzsimmons commented Jul 3, 2026

Copy link
Copy Markdown
Member

Fixes #6049

This PR hardcodes the Chronostratigraphy (GeologicTimePeriod) tree to always sort nodes by startPeriod, independent of the user's orderByField preference under User Preferences → Tree Editor → Behavior. This a pretty big QoL update for paleo and geo users.

Currently, the orderByField preference controls sorting for all tree types. However, Chronostratigraphy should be using chronological ordering by startPeriod, which should take precedence over user-configurable sort fields.

OrderChronostratByPeriod

This also adds a new Show start and end periods toggle preference has been added under User Preferences → Tree Editor → Chronostratigraphy (enabled by default). When enabled, each node displays its geologic time range in ICS format: (298.9 ± 0.15 – 251.902 ± 0.024). Trailing zeros are trimmed. Hovering over the range shows a tooltip with full details using schema field labels.

image image Screenshot 2026-07-03 at 5 59 52 PM

Testing instructions

Compare against the Chronostrat chart: https://stratigraphy.org/ICSchart/ChronostratChart2026-06.pdf

  • Open the Chronostratigraphy tree
  • Expand nodes at various levels and verify that children are ordered by startPeriod (ascending geologic time).
  • Verify the displayed time ranges match the chart (e.g., Campanian (83.6 ± 0.2 – 72.2 ± 0.2)).
  • Hover over a time range and verify the tooltip shows the schema field labels with values.
  • Toggle the Show start and end periods preference off and verify the ranges disappear.
  • Change the Tree Editor → Behavior → Sort by field preference to different values (name, fullName, rankId, nodeNumber).
  • Verify that the Chronostrat tree is unaffected by this preference change since it always sorts by startPeriod.
  • Open a different tree (Taxon, Storage, Geography, etc.) and verify the orderByField preference still works correctly there

Summary by CodeRabbit

  • Bug Fixes
    • Improved geologic time tree row loading to preserve server-provided ordering for geologic time periods.
    • Refreshed tree row fetching URLs and results when geologic time display settings change.
  • New Features
    • Added a toggle to display geologic time start/end period values alongside uncertainties, including enhanced tooltip details.
  • Preferences
    • Introduced a “Show start and end periods” preference for geologic time period rows.
  • Localization
    • Added new localized strings for the preference label and tooltip content.

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The changes add GeologicTimePeriod support for carrying start/end period data from the backend through tree-row fetching and into row rendering, with a new preference and localized labels controlling chrono-period display.

Changes

GeologicTimePeriod chrono-period display

Layer / File(s) Summary
Backend returns period bounds
specifyweb/backend/trees/views.py
tree_view forwards a GeologicTimePeriod-only include flag into get_tree_rows, and get_tree_rows conditionally projects start and end period fields or NULL values.
Row payload includes period fields
specifyweb/frontend/js_src/lib/components/TreeView/helpers.ts
fetchRows extends its tuple typing, destructuring, and mapped row objects to carry startPeriod, startUncertainty, endPeriod, and endUncertainty.
TreeView requests period fields
specifyweb/frontend/js_src/lib/components/TreeView/index.tsx
getRows switches the GeologicTimePeriod URL path segment to startPeriod, adds the include-start-end-periods query flag, and updates its callback dependencies.
Chrono-period label rendering and ordering
specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx
Tree rows skip client-side sorting for GeologicTimePeriod, read the new display preference, and render formatted chrono-period text and tooltip labels using the new row fields.
Preference and tooltip text
specifyweb/frontend/js_src/lib/components/Preferences/UserDefinitions.tsx, specifyweb/frontend/js_src/lib/localization/preferences.ts, specifyweb/frontend/js_src/lib/localization/tree.ts
displayChronoPeriods is added to user preference definitions and localization, and geologic time tooltip strings plus megaAnnum are added to tree localization.

Compact metadata

  • Related issues: #6049 — Add support for sorting by time period in the Chronostrat tree
  • Suggested labels: frontend, backend, tree-view, localization
  • Suggested reviewers: none specified
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: Chronostrat tree sorting by period plus range display.
Linked Issues check ✅ Passed The Chronostrat tree now requests time-based ordering and skips name-based client sorting, matching the issue's time-first ordering requirement.
Out of Scope Changes check ✅ Passed The added range display, preferences toggle, and tooltip text all support the Chronostrat tree change and appear in scope.
Automatic Tests ✅ Passed PASS: The PR updates backend automatic tests in test_synonyms_concat for the new get_tree_rows signature and payload shape, covering the backend API change.
Testing Instructions ✅ Passed The steps are user-facing, specific, and map to the changed Chronostrat tree, preference toggle, tooltip/range display, and sort override.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-6049

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
specifyweb/frontend/js_src/lib/components/TreeView/index.tsx (1)

158-174: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update stale comment to reflect the new conditional sort logic.

The comment still says name is unconditionally hard-coded, but the code below now branches to startPeriod for GeologicTimePeriod. Worth a quick update so future readers aren't misled.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@specifyweb/frontend/js_src/lib/components/TreeView/index.tsx` around lines
158 - 174, The comment in TreeView index.tsx is stale and still describes the
sort field as always hard-coded to name, but the nearby sorting logic now
conditionally uses startPeriod for GeologicTimePeriod. Update the comment around
the tree row fetch/sort handling to match the actual behavior in the relevant
TreeView code path, and keep the reference to userPreferences.get if you mention
the preference fallback so future readers aren’t misled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@specifyweb/frontend/js_src/lib/components/TreeView/index.tsx`:
- Around line 158-174: The comment in TreeView index.tsx is stale and still
describes the sort field as always hard-coded to name, but the nearby sorting
logic now conditionally uses startPeriod for GeologicTimePeriod. Update the
comment around the tree row fetch/sort handling to match the actual behavior in
the relevant TreeView code path, and keep the reference to userPreferences.get
if you mention the preference fallback so future readers aren’t misled.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 39f17028-fb57-49b5-ad16-7236ba31ad2e

📥 Commits

Reviewing files that changed from the base of the PR and between f3d4fec and f6cd2cf.

📒 Files selected for processing (2)
  • specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx
  • specifyweb/frontend/js_src/lib/components/TreeView/index.tsx

@grantfitzsimmons grantfitzsimmons changed the title feat(trees): sort Chronostrat tree by period instead of name feat(trees): sort Chronostrat tree by period instead of name, add ranges Jul 3, 2026
Triggered by 0c5d1b4 on branch refs/heads/issue-6049

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@specifyweb/backend/trees/views.py`:
- Line 168: The query flag handling in the tree view is treating a present
string value as truthy, so the `include_start_end_periods` path in
`trees/views.py` is enabled even when the request sends `"false"`. Update the
`include_start_end_periods` assignment in the view logic to explicitly parse the
GET parameter value into a real boolean before combining it with the `tree ==
'geologictimeperiod'` check, using the same pattern as other request-flag
handling in this view so `fetchRows` can actually disable the option.

In `@specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx`:
- Around line 289-348: The visible label in Row’s GeologicTimePeriod rendering
always prints the range separator even when `row.endPeriod` is missing, causing
malformed text like a dangling dash. Update the JSX in `Row.tsx` so the span
content branches the same way as the `title` logic: use the range format only
when `typeof row.endPeriod === 'string'`, otherwise render a single-period label
with no separator or empty end value. Keep the `trimDecimal`,
`treeText.geologicTimePeriodRange`, and `treeText.geologicTimePeriodSingle`
usage aligned with that check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 91121783-ea90-4997-8e25-a8a70222d748

📥 Commits

Reviewing files that changed from the base of the PR and between f6cd2cf and 0c5d1b4.

📒 Files selected for processing (7)
  • specifyweb/backend/trees/views.py
  • specifyweb/frontend/js_src/lib/components/Preferences/UserDefinitions.tsx
  • specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx
  • specifyweb/frontend/js_src/lib/components/TreeView/helpers.ts
  • specifyweb/frontend/js_src/lib/components/TreeView/index.tsx
  • specifyweb/frontend/js_src/lib/localization/preferences.ts
  • specifyweb/frontend/js_src/lib/localization/tree.ts
✅ Files skipped from review due to trivial changes (2)
  • specifyweb/frontend/js_src/lib/localization/tree.ts
  • specifyweb/frontend/js_src/lib/localization/preferences.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • specifyweb/frontend/js_src/lib/components/TreeView/index.tsx

Comment thread specifyweb/backend/trees/views.py
Comment thread specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx
@github-project-automation github-project-automation Bot moved this from 📋Back Log to Dev Attention Needed in General Tester Board Jul 3, 2026
@grantfitzsimmons grantfitzsimmons marked this pull request as draft July 3, 2026 22:23
@grantfitzsimmons grantfitzsimmons requested a review from emenslin July 3, 2026 23:00
@grantfitzsimmons grantfitzsimmons marked this pull request as ready for review July 4, 2026 00:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
specifyweb/backend/trees/tests/test_trees.py (1)

340-403: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

LGTM on signature update, but consider testing the new flag's actual effect.

Both get_tree_rows calls correctly add the new include_start_end_periods positional argument to match the updated signature in views.py. However, both calls pass False, so there's no test coverage confirming that start_period/end_period/etc. are actually populated (vs. "NULL") when the flag is True for a GeologicTimePeriod tree — which is the actual feature this PR introduces.

Consider adding a test case using a GeologicTimePeriod tree with include_start_end_periods=True to verify the projected columns contain real values.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@specifyweb/backend/trees/tests/test_trees.py` around lines 340 - 403, The
updated get_tree_rows signature is covered, but the new
include_start_end_periods behavior is not verified because both existing calls
pass False. Add a test in test_trees using a GeologicTimePeriod tree and call
get_tree_rows with include_start_end_periods=True, then assert the returned rows
populate start_period/end_period and related fields with real values instead of
"NULL". Use the existing get_tree_rows helper and the tree setup patterns in
this test module to locate the new case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@specifyweb/backend/trees/tests/test_trees.py`:
- Around line 340-403: The updated get_tree_rows signature is covered, but the
new include_start_end_periods behavior is not verified because both existing
calls pass False. Add a test in test_trees using a GeologicTimePeriod tree and
call get_tree_rows with include_start_end_periods=True, then assert the returned
rows populate start_period/end_period and related fields with real values
instead of "NULL". Use the existing get_tree_rows helper and the tree setup
patterns in this test module to locate the new case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e6bb22da-ad2a-457b-a410-4c6746d5f887

📥 Commits

Reviewing files that changed from the base of the PR and between 32b81ac and 137f7a5.

📒 Files selected for processing (3)
  • specifyweb/backend/trees/tests/test_trees.py
  • specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx
  • specifyweb/frontend/js_src/lib/localization/tree.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • specifyweb/frontend/js_src/lib/components/TreeView/Row.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Dev Attention Needed

Development

Successfully merging this pull request may close these issues.

Add support for sorting by time period in the Chronostrat tree

1 participant