jrrribeiro commited on
Commit
a4375f8
·
verified ·
1 Parent(s): 9ec1e58

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

Browse files
src/ui/app_factory.py CHANGED
@@ -2676,6 +2676,27 @@ def _coerce_species_status_map(raw_map: object) -> dict[str, dict[str, object]]:
2676
  return normalized
2677
 
2678
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2679
  def _list_detection_items_for_status(
2680
  queue_service: _QueueServiceProtocol,
2681
  project_slug: str,
@@ -5581,9 +5602,10 @@ def create_app() -> gr.Blocks:
5581
  actor_username=_validator_name_from_session(session),
5582
  )
5583
  species_options = sorted(species_status_map)
 
5584
  corrected_choices = species_options + ["Noise", "Undetermined"]
5585
  return (
5586
- gr.update(choices=species_options, value=None, interactive=True),
5587
  [],
5588
  warning or "Select a species to start validation",
5589
  1,
@@ -5835,7 +5857,7 @@ def create_app() -> gr.Blocks:
5835
  status_map = _coerce_species_status_map(current_status_map)
5836
  species_name = (species or "").strip()
5837
  if not project_slug or not species_name or not _can_access_project(session, project_slug):
5838
- return status_map, _species_status_payload(status_map)
5839
  updated_species = _build_species_status_map(
5840
  queue_service=service_ref["queue"],
5841
  snapshot_reader=validation_repository,
@@ -5845,7 +5867,7 @@ def create_app() -> gr.Blocks:
5845
  scientific_name=species_name,
5846
  )
5847
  status_map.update(updated_species)
5848
- return status_map, _species_status_payload(status_map)
5849
 
5850
  refresh_event = refresh_btn.click(
5851
  fn=refresh,
@@ -6250,7 +6272,7 @@ def create_app() -> gr.Blocks:
6250
  ).then(
6251
  fn=refresh_species_status_for_current_species,
6252
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6253
- outputs=[project_species_status_state, species_status_payload],
6254
  )
6255
 
6256
  reject_event.then(
@@ -6280,7 +6302,7 @@ def create_app() -> gr.Blocks:
6280
  ).then(
6281
  fn=refresh_species_status_for_current_species,
6282
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6283
- outputs=[project_species_status_state, species_status_payload],
6284
  )
6285
 
6286
  uncertain_event.then(
@@ -6310,7 +6332,7 @@ def create_app() -> gr.Blocks:
6310
  ).then(
6311
  fn=refresh_species_status_for_current_species,
6312
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6313
- outputs=[project_species_status_state, species_status_payload],
6314
  )
6315
 
6316
  skip_event.then(
@@ -6340,7 +6362,7 @@ def create_app() -> gr.Blocks:
6340
  ).then(
6341
  fn=refresh_species_status_for_current_species,
6342
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6343
- outputs=[project_species_status_state, species_status_payload],
6344
  )
6345
 
6346
  session_state.change(
 
2676
  return normalized
2677
 
2678
 
2679
+ def _species_status_label(species: str, status_entry: object) -> str:
2680
+ if isinstance(status_entry, dict):
2681
+ status = str(status_entry.get("status", "unvalidated")).strip().lower()
2682
+ else:
2683
+ status = str(status_entry or "unvalidated").strip().lower()
2684
+ marker = {
2685
+ "complete": "🟢",
2686
+ "partial": "🟡",
2687
+ "unvalidated": "⚪",
2688
+ }.get(status, "⚪")
2689
+ return f"{marker} {species}"
2690
+
2691
+
2692
+ def _species_dropdown_choices(status_map: object) -> list[tuple[str, str]]:
2693
+ normalized = _coerce_species_status_map(status_map)
2694
+ return [
2695
+ (_species_status_label(species, normalized.get(species, {})), species)
2696
+ for species in sorted(normalized)
2697
+ ]
2698
+
2699
+
2700
  def _list_detection_items_for_status(
2701
  queue_service: _QueueServiceProtocol,
2702
  project_slug: str,
 
5602
  actor_username=_validator_name_from_session(session),
5603
  )
5604
  species_options = sorted(species_status_map)
5605
+ species_choices = _species_dropdown_choices(species_status_map)
5606
  corrected_choices = species_options + ["Noise", "Undetermined"]
5607
  return (
5608
+ gr.update(choices=species_choices, value=None, interactive=True),
5609
  [],
5610
  warning or "Select a species to start validation",
5611
  1,
 
5857
  status_map = _coerce_species_status_map(current_status_map)
5858
  species_name = (species or "").strip()
5859
  if not project_slug or not species_name or not _can_access_project(session, project_slug):
5860
+ return status_map, _species_status_payload(status_map), gr.update(choices=_species_dropdown_choices(status_map), value=species_name or None)
5861
  updated_species = _build_species_status_map(
5862
  queue_service=service_ref["queue"],
5863
  snapshot_reader=validation_repository,
 
5867
  scientific_name=species_name,
5868
  )
5869
  status_map.update(updated_species)
5870
+ return status_map, _species_status_payload(status_map), gr.update(choices=_species_dropdown_choices(status_map), value=species_name)
5871
 
5872
  refresh_event = refresh_btn.click(
5873
  fn=refresh,
 
6272
  ).then(
6273
  fn=refresh_species_status_for_current_species,
6274
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6275
+ outputs=[project_species_status_state, species_status_payload, species_filter],
6276
  )
6277
 
6278
  reject_event.then(
 
6302
  ).then(
6303
  fn=refresh_species_status_for_current_species,
6304
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6305
+ outputs=[project_species_status_state, species_status_payload, species_filter],
6306
  )
6307
 
6308
  uncertain_event.then(
 
6332
  ).then(
6333
  fn=refresh_species_status_for_current_species,
6334
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6335
+ outputs=[project_species_status_state, species_status_payload, species_filter],
6336
  )
6337
 
6338
  skip_event.then(
 
6362
  ).then(
6363
  fn=refresh_species_status_for_current_species,
6364
  inputs=[selected_project_state, project_species_status_state, species_filter, session_state],
6365
+ outputs=[project_species_status_state, species_status_payload, species_filter],
6366
  )
6367
 
6368
  session_state.change(
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -46,6 +46,7 @@ from src.ui.app_factory import (
46
  _validation_shortcuts_script,
47
  _species_status_dropdown_script,
48
  _species_status_payload,
 
49
  )
50
  from src.auth.auth_service import AuthService
51
  from src.config.runtime_config import RuntimeConfig
@@ -794,6 +795,22 @@ def test_species_status_payload_is_hidden_json_carrier() -> None:
794
  assert ""complete"" in payload
795
 
796
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  def test_page_to_table_marks_conflict_row() -> None:
798
  rows, _, _ = _page_to_table(
799
  service=FakeQueueService(),
 
46
  _validation_shortcuts_script,
47
  _species_status_dropdown_script,
48
  _species_status_payload,
49
+ _species_dropdown_choices,
50
  )
51
  from src.auth.auth_service import AuthService
52
  from src.config.runtime_config import RuntimeConfig
 
795
  assert ""complete"" in payload
796
 
797
 
798
+ def test_species_dropdown_choices_keep_clean_backend_values() -> None:
799
+ choices = _species_dropdown_choices(
800
+ {
801
+ "Species A": {"status": "partial", "total": 2, "reviewed": 1},
802
+ "Species B": {"status": "complete", "total": 1, "reviewed": 1},
803
+ "Species C": {"status": "unvalidated", "total": 1, "reviewed": 0},
804
+ }
805
+ )
806
+
807
+ assert choices == [
808
+ ("🟡 Species A", "Species A"),
809
+ ("🟢 Species B", "Species B"),
810
+ ("⚪ Species C", "Species C"),
811
+ ]
812
+
813
+
814
  def test_page_to_table_marks_conflict_row() -> None:
815
  rows, _, _ = _page_to_table(
816
  service=FakeQueueService(),