jrrribeiro commited on
Commit
8f6e983
·
verified ·
1 Parent(s): 5e3e3bc

Sync app from GitHub Actions (feature/project-state-security-privacy-review)

Browse files
src/ui/app_factory.py CHANGED
@@ -1686,6 +1686,93 @@ def _validation_shortcuts_script() -> str:
1686
  """
1687
 
1688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1689
  def _validate_hf_admin_storage_source_dataset(
1690
  *,
1691
  project: Project,
@@ -2507,6 +2594,121 @@ def _extract_species_options_from_queue(
2507
  return sorted(species_set)
2508
 
2509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2510
  def _row_confidence(row: list[object]) -> float:
2511
  try:
2512
  return float(row[3]) if len(row) > 3 else 0.0
@@ -3312,7 +3514,7 @@ def create_app() -> gr.Blocks:
3312
  with gr.Blocks(
3313
  title="BirdNET-Validator-App",
3314
  css=APP_CSS,
3315
- head=CRITICAL_HEAD_HTML,
3316
  fill_width=False,
3317
  elem_classes=["bn-shell"],
3318
  ) as wrapper:
@@ -5079,6 +5281,7 @@ def create_app() -> gr.Blocks:
5079
 
5080
  page_state = gr.State(value=1)
5081
  project_species_state = gr.State(value=[])
 
5082
  custom_corrected_species_state = gr.State(value={})
5083
  favorite_detection_state = gr.State(value={})
5084
 
@@ -5150,6 +5353,13 @@ def create_app() -> gr.Blocks:
5150
  choices=[],
5151
  value=None,
5152
  interactive=False,
 
 
 
 
 
 
 
5153
  )
5154
 
5155
  gr.Markdown("### Queue navigation")
@@ -5285,18 +5495,47 @@ def create_app() -> gr.Blocks:
5285
 
5286
  def refresh_for_selected_project(project_slug: str, session):
5287
  if not project_slug:
5288
- return gr.update(choices=[], value=None, interactive=False), [], "", 1, None, None, _spectrogram_title(None, None), _build_validation_summary_cards([]), gr.update(choices=["Noise", "Undetermined"], value=None), []
 
 
 
 
 
 
 
 
 
 
 
 
 
5289
 
5290
  if not _can_access_project(session, project_slug):
5291
- return gr.update(choices=[], value=None, interactive=False), [], "Access denied. Select an assigned project.", 1, None, None, _spectrogram_title(None, None), _build_validation_summary_cards([]), gr.update(choices=["Noise", "Undetermined"], value=None), []
 
 
 
 
 
 
 
 
 
 
 
 
 
5292
 
5293
  warning = _ensure_project_queue_loaded(project_slug, session)
5294
 
5295
- species_options = _extract_species_options_from_queue(
5296
  queue_service=service_ref["queue"],
 
5297
  project_slug=project_slug,
5298
  page_size=max(32, runtime_config.page_size),
 
5299
  )
 
5300
  corrected_choices = species_options + ["Noise", "Undetermined"]
5301
  return (
5302
  gr.update(choices=species_options, value=None, interactive=True),
@@ -5309,6 +5548,8 @@ def create_app() -> gr.Blocks:
5309
  _build_validation_summary_cards([]),
5310
  gr.update(choices=corrected_choices, value=None),
5311
  species_options,
 
 
5312
  )
5313
 
5314
  def save_for_project(
@@ -5540,6 +5781,27 @@ def create_app() -> gr.Blocks:
5540
  actor_username=_validator_name_from_session(session),
5541
  )
5542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5543
  refresh_event = refresh_btn.click(
5544
  fn=refresh,
5545
  inputs=[
@@ -5594,7 +5856,20 @@ def create_app() -> gr.Blocks:
5594
  project_change_event = selected_project_state.change(
5595
  fn=refresh_for_selected_project,
5596
  inputs=[selected_project_state, session_state],
5597
- outputs=[species_filter, table, status, page_state, audio_player, spectrogram_image, spectrogram_title, validation_summary_cards, corrected_species_input, project_species_state],
 
 
 
 
 
 
 
 
 
 
 
 
 
5598
  )
5599
 
5600
  species_filter.change(
@@ -5927,6 +6202,10 @@ def create_app() -> gr.Blocks:
5927
  fn=build_species_summary,
5928
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
5929
  outputs=[validation_summary_cards],
 
 
 
 
5930
  )
5931
 
5932
  reject_event.then(
@@ -5953,6 +6232,10 @@ def create_app() -> gr.Blocks:
5953
  fn=build_species_summary,
5954
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
5955
  outputs=[validation_summary_cards],
 
 
 
 
5956
  )
5957
 
5958
  uncertain_event.then(
@@ -5979,6 +6262,10 @@ def create_app() -> gr.Blocks:
5979
  fn=build_species_summary,
5980
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
5981
  outputs=[validation_summary_cards],
 
 
 
 
5982
  )
5983
 
5984
  skip_event.then(
@@ -6005,6 +6292,10 @@ def create_app() -> gr.Blocks:
6005
  fn=build_species_summary,
6006
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
6007
  outputs=[validation_summary_cards],
 
 
 
 
6008
  )
6009
 
6010
  session_state.change(
 
1686
  """
1687
 
1688
 
1689
+ def _species_status_dropdown_script() -> str:
1690
+ """Apply lightweight per-species progress styling to the Gradio dropdown."""
1691
+ return """
1692
+ <script>
1693
+ (() => {
1694
+ const DROPDOWN_ID = "bn-species-filter";
1695
+ const PAYLOAD_ID = "bn-species-status-payload";
1696
+ const STATUS_CLASSES = [
1697
+ "bn-species-option-unvalidated",
1698
+ "bn-species-option-partial",
1699
+ "bn-species-option-complete",
1700
+ ];
1701
+ const SELECTED_CLASSES = [
1702
+ "bn-species-selected-unvalidated",
1703
+ "bn-species-selected-partial",
1704
+ "bn-species-selected-complete",
1705
+ ];
1706
+
1707
+ function payloadText() {
1708
+ const root = document.getElementById(PAYLOAD_ID);
1709
+ if (!root) return "{}";
1710
+ const field = root.querySelector("textarea, input");
1711
+ if (field && typeof field.value === "string") return field.value || "{}";
1712
+ return root.textContent || "{}";
1713
+ }
1714
+
1715
+ function statusMap() {
1716
+ try {
1717
+ const parsed = JSON.parse(payloadText());
1718
+ return parsed && typeof parsed === "object" ? parsed : {};
1719
+ } catch (_) {
1720
+ return {};
1721
+ }
1722
+ }
1723
+
1724
+ function normalizeStatus(value) {
1725
+ const status = String(value || "").trim().toLowerCase();
1726
+ if (status === "complete" || status === "partial" || status === "unvalidated") return status;
1727
+ return "unvalidated";
1728
+ }
1729
+
1730
+ function speciesStatus(map, speciesName) {
1731
+ const entry = map[String(speciesName || "").trim()];
1732
+ if (typeof entry === "string") return normalizeStatus(entry);
1733
+ if (entry && typeof entry === "object") return normalizeStatus(entry.status);
1734
+ return "unvalidated";
1735
+ }
1736
+
1737
+ function cleanOptionText(value) {
1738
+ return String(value || "").replace(/^\\s*✓\\s*/, "").trim();
1739
+ }
1740
+
1741
+ function applySpeciesStatusStyles() {
1742
+ const dropdown = document.getElementById(DROPDOWN_ID);
1743
+ if (!dropdown) return;
1744
+ const map = statusMap();
1745
+
1746
+ dropdown.querySelectorAll('li[data-testid="dropdown-option"]').forEach((option) => {
1747
+ const speciesName = cleanOptionText(option.getAttribute("aria-label") || option.textContent || "");
1748
+ const status = speciesStatus(map, speciesName);
1749
+ option.classList.remove(...STATUS_CLASSES);
1750
+ option.classList.add(`bn-species-option-${status}`);
1751
+ const entry = map[speciesName] || {};
1752
+ const reviewed = typeof entry === "object" ? Number(entry.reviewed || 0) : 0;
1753
+ const total = typeof entry === "object" ? Number(entry.total || 0) : 0;
1754
+ option.title = total ? `${reviewed}/${total} reviewed` : "No reviewed segments yet";
1755
+ });
1756
+
1757
+ dropdown.classList.remove(...SELECTED_CLASSES);
1758
+ const input = dropdown.querySelector('input[role="listbox"]');
1759
+ const selected = cleanOptionText(input ? input.value : "");
1760
+ if (selected) {
1761
+ dropdown.classList.add(`bn-species-selected-${speciesStatus(map, selected)}`);
1762
+ }
1763
+ }
1764
+
1765
+ const observer = new MutationObserver(applySpeciesStatusStyles);
1766
+ observer.observe(document.body, { childList: true, subtree: true });
1767
+ window.addEventListener("focus", applySpeciesStatusStyles);
1768
+ document.addEventListener("click", () => window.setTimeout(applySpeciesStatusStyles, 0), true);
1769
+ window.setInterval(applySpeciesStatusStyles, 700);
1770
+ applySpeciesStatusStyles();
1771
+ })();
1772
+ </script>
1773
+ """
1774
+
1775
+
1776
  def _validate_hf_admin_storage_source_dataset(
1777
  *,
1778
  project: Project,
 
2594
  return sorted(species_set)
2595
 
2596
 
2597
+ def _species_status_payload(status_map: dict[str, dict[str, object]] | None) -> str:
2598
+ return json.dumps(status_map or {}, ensure_ascii=False, sort_keys=True)
2599
+
2600
+
2601
+ def _coerce_species_status_map(raw_map: object) -> dict[str, dict[str, object]]:
2602
+ if isinstance(raw_map, str):
2603
+ try:
2604
+ parsed = json.loads(raw_map)
2605
+ except Exception:
2606
+ parsed = {}
2607
+ else:
2608
+ parsed = raw_map
2609
+
2610
+ if not isinstance(parsed, dict):
2611
+ return {}
2612
+
2613
+ normalized: dict[str, dict[str, object]] = {}
2614
+ for key, value in parsed.items():
2615
+ species = str(key).strip()
2616
+ if not species:
2617
+ continue
2618
+ if isinstance(value, dict):
2619
+ status = str(value.get("status", "unvalidated")).strip().lower()
2620
+ total = int(value.get("total") or 0)
2621
+ reviewed = int(value.get("reviewed") or 0)
2622
+ else:
2623
+ status = str(value or "unvalidated").strip().lower()
2624
+ total = 0
2625
+ reviewed = 0
2626
+ if status not in {"unvalidated", "partial", "complete"}:
2627
+ status = "unvalidated"
2628
+ normalized[species] = {"status": status, "total": total, "reviewed": reviewed}
2629
+ return normalized
2630
+
2631
+
2632
+ def _list_detection_items_for_status(
2633
+ queue_service: _QueueServiceProtocol,
2634
+ project_slug: str,
2635
+ page_size: int,
2636
+ scientific_name: str | None = None,
2637
+ ) -> list[object]:
2638
+ list_all = getattr(queue_service, "list_all_detections", None)
2639
+ if callable(list_all):
2640
+ return list(
2641
+ list_all(
2642
+ project_slug=project_slug,
2643
+ scientific_name=scientific_name,
2644
+ min_confidence=None,
2645
+ max_confidence=None,
2646
+ )
2647
+ )
2648
+
2649
+ items: list[object] = []
2650
+ page = 1
2651
+ while True:
2652
+ page_result = queue_service.get_page(
2653
+ project_slug=project_slug,
2654
+ page=page,
2655
+ page_size=page_size,
2656
+ scientific_name=scientific_name,
2657
+ min_confidence=None,
2658
+ max_confidence=None,
2659
+ )
2660
+ items.extend(list(page_result.items))
2661
+ if not page_result.has_next:
2662
+ break
2663
+ page += 1
2664
+ return items
2665
+
2666
+
2667
+ def _build_species_status_map(
2668
+ queue_service: _QueueServiceProtocol,
2669
+ snapshot_reader: _ValidationReadRepositoryProtocol,
2670
+ project_slug: str,
2671
+ page_size: int,
2672
+ actor_username: str = "",
2673
+ scientific_name: str | None = None,
2674
+ ) -> dict[str, dict[str, object]]:
2675
+ if not project_slug:
2676
+ return {}
2677
+
2678
+ items = _list_detection_items_for_status(
2679
+ queue_service=queue_service,
2680
+ project_slug=project_slug,
2681
+ page_size=page_size,
2682
+ scientific_name=(scientific_name or "").strip() or None,
2683
+ )
2684
+ snapshot = snapshot_reader.load_current_snapshot(project_slug=project_slug, actor_username=actor_username)
2685
+ counters: dict[str, dict[str, int]] = {}
2686
+
2687
+ for item in items:
2688
+ species = str(getattr(item, "scientific_name", "")).strip()
2689
+ if not species:
2690
+ continue
2691
+ detection_key = str(getattr(item, "detection_key", "")).strip()
2692
+ status_value = str(snapshot.get(detection_key, {}).get("status", "pending")).strip().lower()
2693
+ species_counter = counters.setdefault(species, {"total": 0, "reviewed": 0})
2694
+ species_counter["total"] += 1
2695
+ if status_value and status_value != "pending":
2696
+ species_counter["reviewed"] += 1
2697
+
2698
+ status_map: dict[str, dict[str, object]] = {}
2699
+ for species, counter in sorted(counters.items()):
2700
+ total = int(counter["total"])
2701
+ reviewed = int(counter["reviewed"])
2702
+ if reviewed <= 0:
2703
+ status = "unvalidated"
2704
+ elif reviewed >= total:
2705
+ status = "complete"
2706
+ else:
2707
+ status = "partial"
2708
+ status_map[species] = {"status": status, "total": total, "reviewed": reviewed}
2709
+ return status_map
2710
+
2711
+
2712
  def _row_confidence(row: list[object]) -> float:
2713
  try:
2714
  return float(row[3]) if len(row) > 3 else 0.0
 
3514
  with gr.Blocks(
3515
  title="BirdNET-Validator-App",
3516
  css=APP_CSS,
3517
+ head=CRITICAL_HEAD_HTML + _species_status_dropdown_script(),
3518
  fill_width=False,
3519
  elem_classes=["bn-shell"],
3520
  ) as wrapper:
 
5281
 
5282
  page_state = gr.State(value=1)
5283
  project_species_state = gr.State(value=[])
5284
+ project_species_status_state = gr.State(value={})
5285
  custom_corrected_species_state = gr.State(value={})
5286
  favorite_detection_state = gr.State(value={})
5287
 
 
5353
  choices=[],
5354
  value=None,
5355
  interactive=False,
5356
+ elem_id="bn-species-filter",
5357
+ )
5358
+ species_status_payload = gr.Textbox(
5359
+ value="{}",
5360
+ interactive=False,
5361
+ label="Species validation status",
5362
+ elem_id="bn-species-status-payload",
5363
  )
5364
 
5365
  gr.Markdown("### Queue navigation")
 
5495
 
5496
  def refresh_for_selected_project(project_slug: str, session):
5497
  if not project_slug:
5498
+ return (
5499
+ gr.update(choices=[], value=None, interactive=False),
5500
+ [],
5501
+ "",
5502
+ 1,
5503
+ None,
5504
+ None,
5505
+ _spectrogram_title(None, None),
5506
+ _build_validation_summary_cards([]),
5507
+ gr.update(choices=["Noise", "Undetermined"], value=None),
5508
+ [],
5509
+ {},
5510
+ "{}",
5511
+ )
5512
 
5513
  if not _can_access_project(session, project_slug):
5514
+ return (
5515
+ gr.update(choices=[], value=None, interactive=False),
5516
+ [],
5517
+ "Access denied. Select an assigned project.",
5518
+ 1,
5519
+ None,
5520
+ None,
5521
+ _spectrogram_title(None, None),
5522
+ _build_validation_summary_cards([]),
5523
+ gr.update(choices=["Noise", "Undetermined"], value=None),
5524
+ [],
5525
+ {},
5526
+ "{}",
5527
+ )
5528
 
5529
  warning = _ensure_project_queue_loaded(project_slug, session)
5530
 
5531
+ species_status_map = _build_species_status_map(
5532
  queue_service=service_ref["queue"],
5533
+ snapshot_reader=validation_repository,
5534
  project_slug=project_slug,
5535
  page_size=max(32, runtime_config.page_size),
5536
+ actor_username=_validator_name_from_session(session),
5537
  )
5538
+ species_options = sorted(species_status_map)
5539
  corrected_choices = species_options + ["Noise", "Undetermined"]
5540
  return (
5541
  gr.update(choices=species_options, value=None, interactive=True),
 
5548
  _build_validation_summary_cards([]),
5549
  gr.update(choices=corrected_choices, value=None),
5550
  species_options,
5551
+ species_status_map,
5552
+ _species_status_payload(species_status_map),
5553
  )
5554
 
5555
  def save_for_project(
 
5781
  actor_username=_validator_name_from_session(session),
5782
  )
5783
 
5784
+ def refresh_species_status_for_current_species(
5785
+ project_slug: str,
5786
+ current_status_map: object,
5787
+ species: str,
5788
+ session=None,
5789
+ ):
5790
+ status_map = _coerce_species_status_map(current_status_map)
5791
+ species_name = (species or "").strip()
5792
+ if not project_slug or not species_name or not _can_access_project(session, project_slug):
5793
+ return status_map, _species_status_payload(status_map)
5794
+ updated_species = _build_species_status_map(
5795
+ queue_service=service_ref["queue"],
5796
+ snapshot_reader=validation_repository,
5797
+ project_slug=project_slug,
5798
+ page_size=max(32, runtime_config.page_size),
5799
+ actor_username=_validator_name_from_session(session),
5800
+ scientific_name=species_name,
5801
+ )
5802
+ status_map.update(updated_species)
5803
+ return status_map, _species_status_payload(status_map)
5804
+
5805
  refresh_event = refresh_btn.click(
5806
  fn=refresh,
5807
  inputs=[
 
5856
  project_change_event = selected_project_state.change(
5857
  fn=refresh_for_selected_project,
5858
  inputs=[selected_project_state, session_state],
5859
+ outputs=[
5860
+ species_filter,
5861
+ table,
5862
+ status,
5863
+ page_state,
5864
+ audio_player,
5865
+ spectrogram_image,
5866
+ spectrogram_title,
5867
+ validation_summary_cards,
5868
+ corrected_species_input,
5869
+ project_species_state,
5870
+ project_species_status_state,
5871
+ species_status_payload,
5872
+ ],
5873
  )
5874
 
5875
  species_filter.change(
 
6202
  fn=build_species_summary,
6203
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
6204
  outputs=[validation_summary_cards],
6205
+ ).then(
6206
+ fn=refresh_species_status_for_current_species,
6207
+ inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6208
+ outputs=[project_species_status_state, species_status_payload],
6209
  )
6210
 
6211
  reject_event.then(
 
6232
  fn=build_species_summary,
6233
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
6234
  outputs=[validation_summary_cards],
6235
+ ).then(
6236
+ fn=refresh_species_status_for_current_species,
6237
+ inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6238
+ outputs=[project_species_status_state, species_status_payload],
6239
  )
6240
 
6241
  uncertain_event.then(
 
6262
  fn=build_species_summary,
6263
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
6264
  outputs=[validation_summary_cards],
6265
+ ).then(
6266
+ fn=refresh_species_status_for_current_species,
6267
+ inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6268
+ outputs=[project_species_status_state, species_status_payload],
6269
  )
6270
 
6271
  skip_event.then(
 
6292
  fn=build_species_summary,
6293
  inputs=[selected_project_state, species_filter, min_confidence, session_state],
6294
  outputs=[validation_summary_cards],
6295
+ ).then(
6296
+ fn=refresh_species_status_for_current_species,
6297
+ inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6298
+ outputs=[project_species_status_state, species_status_payload],
6299
  )
6300
 
6301
  session_state.change(
src/ui/theme.py CHANGED
@@ -1614,6 +1614,75 @@ button.bn-report-download-action-blue:hover {
1614
  display: none !important;
1615
  }
1616
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1617
  textarea,
1618
  input,
1619
  select {
 
1614
  display: none !important;
1615
  }
1616
 
1617
+ #bn-species-status-payload {
1618
+ display: none !important;
1619
+ }
1620
+
1621
+ #bn-species-filter li[data-testid="dropdown-option"] {
1622
+ box-sizing: border-box !important;
1623
+ margin: 4px 8px !important;
1624
+ padding: 8px 10px !important;
1625
+ border: 1px solid var(--bn-species-status-border, var(--bn-border)) !important;
1626
+ border-left-width: 5px !important;
1627
+ border-radius: 8px !important;
1628
+ background: var(--bn-species-status-bg, #ffffff) !important;
1629
+ color: var(--bn-species-status-text, var(--bn-text)) !important;
1630
+ font-weight: 650 !important;
1631
+ }
1632
+
1633
+ #bn-species-filter li[data-testid="dropdown-option"] .inner-item {
1634
+ display: none !important;
1635
+ }
1636
+
1637
+ #bn-species-filter li[data-testid="dropdown-option"].active,
1638
+ #bn-species-filter li[data-testid="dropdown-option"].selected,
1639
+ #bn-species-filter li[data-testid="dropdown-option"]:hover {
1640
+ background: var(--bn-species-status-hover, #eff6ff) !important;
1641
+ color: var(--bn-species-status-text, var(--bn-text)) !important;
1642
+ }
1643
+
1644
+ #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-unvalidated {
1645
+ --bn-species-status-border: #cbd5e1;
1646
+ --bn-species-status-bg: #f8fafc;
1647
+ --bn-species-status-hover: #eef2f7;
1648
+ --bn-species-status-text: #243348;
1649
+ border-color: #cbd5e1 !important;
1650
+ border-left-color: #94a3b8 !important;
1651
+ }
1652
+
1653
+ #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-partial {
1654
+ --bn-species-status-border: #f59e0b;
1655
+ --bn-species-status-bg: #fff7ed;
1656
+ --bn-species-status-hover: #ffedd5;
1657
+ --bn-species-status-text: #7c2d12;
1658
+ border-color: #f59e0b !important;
1659
+ border-left-color: #d97706 !important;
1660
+ }
1661
+
1662
+ #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-complete {
1663
+ --bn-species-status-border: #16a34a;
1664
+ --bn-species-status-bg: #ecfdf3;
1665
+ --bn-species-status-hover: #dcfce7;
1666
+ --bn-species-status-text: #14532d;
1667
+ border-color: #16a34a !important;
1668
+ border-left-color: #15803d !important;
1669
+ }
1670
+
1671
+ #bn-species-filter.bn-species-selected-unvalidated .wrap-inner {
1672
+ border-color: #cbd5e1 !important;
1673
+ box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.3) !important;
1674
+ }
1675
+
1676
+ #bn-species-filter.bn-species-selected-partial .wrap-inner {
1677
+ border-color: #f59e0b !important;
1678
+ box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35) !important;
1679
+ }
1680
+
1681
+ #bn-species-filter.bn-species-selected-complete .wrap-inner {
1682
+ border-color: #16a34a !important;
1683
+ box-shadow: 0 0 0 1px rgba(22, 163, 74, 0.35) !important;
1684
+ }
1685
+
1686
  textarea,
1687
  input,
1688
  select {
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -11,6 +11,7 @@ import pytest
11
  from src.ui.app_factory import (
12
  _build_validation_export_rows,
13
  _build_validation_report,
 
14
  _cleanup_selected_audio,
15
  _advance_to_next_row_with_title,
16
  _autofetch_first_row,
@@ -43,6 +44,7 @@ from src.ui.app_factory import (
43
  _initialize_hf_admin_storage,
44
  _write_validation_export,
45
  _validation_shortcuts_script,
 
46
  )
47
  from src.auth.auth_service import AuthService
48
  from src.config.runtime_config import RuntimeConfig
@@ -741,6 +743,47 @@ def test_page_to_table_prioritizes_pending_then_confidence() -> None:
741
  ]
742
 
743
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
744
  def test_page_to_table_marks_conflict_row() -> None:
745
  rows, _, _ = _page_to_table(
746
  service=FakeQueueService(),
 
11
  from src.ui.app_factory import (
12
  _build_validation_export_rows,
13
  _build_validation_report,
14
+ _build_species_status_map,
15
  _cleanup_selected_audio,
16
  _advance_to_next_row_with_title,
17
  _autofetch_first_row,
 
44
  _initialize_hf_admin_storage,
45
  _write_validation_export,
46
  _validation_shortcuts_script,
47
+ _species_status_dropdown_script,
48
  )
49
  from src.auth.auth_service import AuthService
50
  from src.config.runtime_config import RuntimeConfig
 
743
  ]
744
 
745
 
746
+ def test_build_species_status_map_marks_progress_levels() -> None:
747
+ class QueueWithSpecies:
748
+ def list_all_detections(self, **kwargs: object) -> list[object]:
749
+ _ = kwargs
750
+ return [
751
+ SimpleNamespace(detection_key="sp_a_1", scientific_name="Species A"),
752
+ SimpleNamespace(detection_key="sp_a_2", scientific_name="Species A"),
753
+ SimpleNamespace(detection_key="sp_b_1", scientific_name="Species B"),
754
+ SimpleNamespace(detection_key="sp_c_1", scientific_name="Species C"),
755
+ ]
756
+
757
+ class SnapshotWithSpecies:
758
+ def load_current_snapshot(self, project_slug: str, actor_username: str = "") -> dict[str, dict[str, object]]:
759
+ _ = (project_slug, actor_username)
760
+ return {
761
+ "sp_a_1": {"status": "positive"},
762
+ "sp_b_1": {"status": "negative"},
763
+ }
764
+
765
+ status_map = _build_species_status_map(
766
+ queue_service=QueueWithSpecies(),
767
+ snapshot_reader=SnapshotWithSpecies(),
768
+ project_slug="demo-project",
769
+ page_size=10,
770
+ )
771
+
772
+ assert status_map["Species A"] == {"status": "partial", "total": 2, "reviewed": 1}
773
+ assert status_map["Species B"] == {"status": "complete", "total": 1, "reviewed": 1}
774
+ assert status_map["Species C"] == {"status": "unvalidated", "total": 1, "reviewed": 0}
775
+
776
+
777
+ def test_species_status_dropdown_script_targets_dropdown_without_changing_choices() -> None:
778
+ script = _species_status_dropdown_script()
779
+
780
+ assert "bn-species-filter" in script
781
+ assert "bn-species-status-payload" in script
782
+ assert "bn-species-option-complete" in script
783
+ assert "bn-species-option-partial" in script
784
+ assert "bn-species-option-unvalidated" in script
785
+
786
+
787
  def test_page_to_table_marks_conflict_row() -> None:
788
  rows, _, _ = _page_to_table(
789
  service=FakeQueueService(),