Skip to content

Add Taxon tree query button preference for Taxon or Preferred Taxon#7837

Open
acwhite211 wants to merge 5 commits into
mainfrom
issue-3724
Open

Add Taxon tree query button preference for Taxon or Preferred Taxon#7837
acwhite211 wants to merge 5 commits into
mainfrom
issue-3724

Conversation

@acwhite211
Copy link
Copy Markdown
Member

@acwhite211 acwhite211 commented Mar 24, 2026

Fixes #3724

Add a user preference that controls which determination field the Taxon tree Query button uses when building a query.

Not sure if this is all that is needed to solve #3724 and maybe #4677, need to investigate some more.

Also, need to fix failing unit tests.

Checklist

  • Self-review the PR after opening it to make sure the changes look good and
    self-explanatory (or properly documented)
  • Add relevant issue to release milestone
  • Add pr to documentation list
  • Add automated tests
  • Add a reverse migration if a migration is present in the PR

Testing instructions

  • Open /specify/user-preferences/treeEditor.
  • In Tree Editor > Taxon, confirm there is a preference named Field used by Taxon Query button with Preferred Taxon and Taxon options.
  • Set the preference to Preferred Taxon. Do not reload the page.
  • Open /specify/tree/taxon, select an accepted Taxon node whose tree count includes synonymized determinations, and click the Query/magnifying-glass button.
  • Confirm the generated Collection Object query runs and filters through Determinations > Preferred Taxon > [rank] > Taxon ID.
  • Confirm the query result count matches the count shown in the Taxon tree for that accepted node.
  • Select the synonymized/non-preferred Taxon node and run the Query button again. Confirm the result count matches that node’s tree count, usually 0 when the record’s Preferred Taxon is the accepted node.
  • Return to user preferences and set Field used by Taxon Query button to Taxon.
  • Run the Query button for the same synonymized/non-preferred Taxon node.
  • Confirm the generated query now filters through Determinations > Taxon > [rank] > Taxon ID and returns records originally determined to that taxon.
  • Refresh the browser and confirm the selected preference persists.
  • Spot check a non-Taxon tree query, such as Geography or Storage, and confirm the Query button still opens and runs as before.

Summary by CodeRabbit

  • New Features
    • Added a configurable preference for Taxon tree query filtering, allowing users to choose between "Preferred Taxon" and "Taxon" fields when using the Query button.

Review Change Stack

@grantfitzsimmons grantfitzsimmons added this to the 7.12.2 milestone Apr 26, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e86d7f9-3b3c-49e7-ad68-b31b6a997a5d

📥 Commits

Reviewing files that changed from the base of the PR and between 1fc0f04 and d7e48c9.

📒 Files selected for processing (4)
  • specifyweb/backend/stored_queries/tests/tests_legacy.py
  • specifyweb/frontend/js_src/lib/components/Preferences/UserDefinitions.tsx
  • specifyweb/frontend/js_src/lib/components/QueryBuilder/fromTree.ts
  • specifyweb/frontend/js_src/lib/localization/preferences.ts
💤 Files with no reviewable changes (1)
  • specifyweb/backend/stored_queries/tests/tests_legacy.py

📝 Walkthrough

Walkthrough

This PR adds a new user preference that allows selection between preferredTaxon and taxon for filtering taxon tree Query button results. The preference is defined in UserDefinitions, initialized with schema labels, used by the query builder to construct field paths dynamically, exposed through localization strings, and accompanied by a test fixture update.

Changes

Taxon Query Field Preference

Layer / File(s) Summary
Preference definition and schema initialization
specifyweb/frontend/js_src/lib/components/Preferences/UserDefinitions.tsx
Introduces a new queryField preference under the taxon tree editor category with preferredTaxon and taxon options (default preferredTaxon). Extends post-load schema initialization to hydrate the preference's value titles from tables.Determination field labels.
Query builder preference-driven field selection
specifyweb/frontend/js_src/lib/components/QueryBuilder/fromTree.ts
Imports userPreferences and refactors the defaultFields.Taxon builder to dynamically insert the selected preference value (queryField) into the determination filter field path instead of using a fixed taxon key.
Preference localization
specifyweb/frontend/js_src/lib/localization/preferences.ts
Adds queryButtonTaxonField label and queryButtonTaxonFieldDescription description strings for the new preference.
Test fixture update
specifyweb/backend/stored_queries/tests/tests_legacy.py
Removes "projects" from the Collection model's not_found expected errors list.
🚥 Pre-merge checks | ✅ 4 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Automatic Tests ⚠️ Warning PR adds new preference for Taxon query field but only has one snapshot test scenario (default 'taxon' value). Missing tests for the 'preferredTaxon' preference option and edge cases. Add tests to fromTree.test.ts covering both preference values ('taxon' and 'preferredTaxon'), and test UserDefinitions preference schema validation with proper mocking of userPreferences.
Testing Instructions ⚠️ Warning No testing instructions are documented. PR objectives mention testing instructions exist, but none are found in commits, PR sections, or code. Add testing instructions documenting: (1) preference location at /specify/user-preferences/treeEditor, (2) verifying queries use preferredTaxon or taxon based on preference, (3) confirming counts/queries align for synonymized taxon nodes.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a user preference to select between Taxon or Preferred Taxon for the tree Query button.
Linked Issues check ✅ Passed The PR addresses #3724 by implementing the preference to switch between Taxon and Preferred Taxon determination fields, enabling queries to use the appropriate field and potentially resolving count misalignment issues.
Out of Scope Changes check ✅ Passed All changes directly support the preference feature: test fixture update, preference definition, localization strings, and query builder integration. No unrelated modifications detected.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-3724

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 and usage tips.

@acwhite211 acwhite211 marked this pull request as ready for review May 22, 2026 21:43
@acwhite211 acwhite211 requested review from a team May 22, 2026 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

Synonymized nodes are not counted in the tree

2 participants