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

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

Browse files
src/ui/app_factory.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import csv
3
  import hashlib
 
4
  import json
5
  import os
6
  import re
@@ -1707,6 +1708,8 @@ def _species_status_dropdown_script() -> str:
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 || "{}";
@@ -1727,8 +1730,22 @@ def _species_status_dropdown_script() -> str:
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";
@@ -1738,6 +1755,30 @@ def _species_status_dropdown_script() -> str:
1738
  return String(value || "").replace(/^\\s*✓\\s*/, "").trim();
1739
  }
1740
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1741
  function applySpeciesStatusStyles() {
1742
  const dropdown = document.getElementById(DROPDOWN_ID);
1743
  if (!dropdown) return;
@@ -1748,7 +1789,11 @@ def _species_status_dropdown_script() -> str:
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";
@@ -2595,7 +2640,9 @@ def _extract_species_options_from_queue(
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]]:
@@ -5355,10 +5402,8 @@ def create_app() -> gr.Blocks:
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
 
@@ -5507,7 +5552,7 @@ def create_app() -> gr.Blocks:
5507
  gr.update(choices=["Noise", "Undetermined"], value=None),
5508
  [],
5509
  {},
5510
- "{}",
5511
  )
5512
 
5513
  if not _can_access_project(session, project_slug):
@@ -5523,7 +5568,7 @@ def create_app() -> gr.Blocks:
5523
  gr.update(choices=["Noise", "Undetermined"], value=None),
5524
  [],
5525
  {},
5526
- "{}",
5527
  )
5528
 
5529
  warning = _ensure_project_queue_loaded(project_slug, session)
 
1
  import gradio as gr
2
  import csv
3
  import hashlib
4
+ import html as html_lib
5
  import json
6
  import os
7
  import re
 
1708
  function payloadText() {
1709
  const root = document.getElementById(PAYLOAD_ID);
1710
  if (!root) return "{}";
1711
+ const dataNode = root.querySelector("[data-json]");
1712
+ if (dataNode && typeof dataNode.dataset.json === "string") return dataNode.dataset.json || "{}";
1713
  const field = root.querySelector("textarea, input");
1714
  if (field && typeof field.value === "string") return field.value || "{}";
1715
  return root.textContent || "{}";
 
1730
  return "unvalidated";
1731
  }
1732
 
1733
+ function normalizedSpeciesName(value) {
1734
+ return cleanOptionText(value).normalize("NFKC").replace(/\\s+/g, " ").trim().toLowerCase();
1735
+ }
1736
+
1737
+ function speciesEntry(map, speciesName) {
1738
+ const directName = cleanOptionText(speciesName);
1739
+ if (Object.prototype.hasOwnProperty.call(map, directName)) return map[directName];
1740
+ const normalizedName = normalizedSpeciesName(directName);
1741
+ for (const [key, value] of Object.entries(map)) {
1742
+ if (normalizedSpeciesName(key) === normalizedName) return value;
1743
+ }
1744
+ return undefined;
1745
+ }
1746
+
1747
  function speciesStatus(map, speciesName) {
1748
+ const entry = speciesEntry(map, speciesName);
1749
  if (typeof entry === "string") return normalizeStatus(entry);
1750
  if (entry && typeof entry === "object") return normalizeStatus(entry.status);
1751
  return "unvalidated";
 
1755
  return String(value || "").replace(/^\\s*✓\\s*/, "").trim();
1756
  }
1757
 
1758
+ const STATUS_STYLES = {
1759
+ unvalidated: {
1760
+ "--bn-species-status-border": "#cbd5e1",
1761
+ "--bn-species-status-accent": "#94a3b8",
1762
+ "--bn-species-status-bg": "#f8fafc",
1763
+ "--bn-species-status-hover": "#eef2f7",
1764
+ "--bn-species-status-text": "#243348",
1765
+ },
1766
+ partial: {
1767
+ "--bn-species-status-border": "#f59e0b",
1768
+ "--bn-species-status-accent": "#f59e0b",
1769
+ "--bn-species-status-bg": "#fff7ed",
1770
+ "--bn-species-status-hover": "#ffedd5",
1771
+ "--bn-species-status-text": "#7c2d12",
1772
+ },
1773
+ complete: {
1774
+ "--bn-species-status-border": "#16a34a",
1775
+ "--bn-species-status-accent": "#16a34a",
1776
+ "--bn-species-status-bg": "#ecfdf3",
1777
+ "--bn-species-status-hover": "#dcfce7",
1778
+ "--bn-species-status-text": "#14532d",
1779
+ },
1780
+ };
1781
+
1782
  function applySpeciesStatusStyles() {
1783
  const dropdown = document.getElementById(DROPDOWN_ID);
1784
  if (!dropdown) return;
 
1789
  const status = speciesStatus(map, speciesName);
1790
  option.classList.remove(...STATUS_CLASSES);
1791
  option.classList.add(`bn-species-option-${status}`);
1792
+ option.dataset.speciesStatus = status;
1793
+ Object.entries(STATUS_STYLES[status] || STATUS_STYLES.unvalidated).forEach(([property, value]) => {
1794
+ option.style.setProperty(property, value);
1795
+ });
1796
+ const entry = speciesEntry(map, speciesName) || {};
1797
  const reviewed = typeof entry === "object" ? Number(entry.reviewed || 0) : 0;
1798
  const total = typeof entry === "object" ? Number(entry.total || 0) : 0;
1799
  option.title = total ? `${reviewed}/${total} reviewed` : "No reviewed segments yet";
 
2640
 
2641
 
2642
  def _species_status_payload(status_map: dict[str, dict[str, object]] | None) -> str:
2643
+ payload = json.dumps(status_map or {}, ensure_ascii=False, sort_keys=True)
2644
+ escaped_payload = html_lib.escape(payload, quote=True)
2645
+ return f'<span class="bn-species-status-data" data-json="{escaped_payload}"></span>'
2646
 
2647
 
2648
  def _coerce_species_status_map(raw_map: object) -> dict[str, dict[str, object]]:
 
5402
  interactive=False,
5403
  elem_id="bn-species-filter",
5404
  )
5405
+ species_status_payload = gr.HTML(
5406
+ value=_species_status_payload({}),
 
 
5407
  elem_id="bn-species-status-payload",
5408
  )
5409
 
 
5552
  gr.update(choices=["Noise", "Undetermined"], value=None),
5553
  [],
5554
  {},
5555
+ _species_status_payload({}),
5556
  )
5557
 
5558
  if not _can_access_project(session, project_slug):
 
5568
  gr.update(choices=["Noise", "Undetermined"], value=None),
5569
  [],
5570
  {},
5571
+ _species_status_payload({}),
5572
  )
5573
 
5574
  warning = _ensure_project_queue_loaded(project_slug, session)
src/ui/theme.py CHANGED
@@ -1642,7 +1642,8 @@ button.bn-report-download-action-blue:hover {
1642
  color: var(--bn-species-status-text, var(--bn-text)) !important;
1643
  }
1644
 
1645
- #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-unvalidated {
 
1646
  --bn-species-status-border: #cbd5e1;
1647
  --bn-species-status-accent: #94a3b8;
1648
  --bn-species-status-bg: #f8fafc;
@@ -1651,7 +1652,8 @@ button.bn-report-download-action-blue:hover {
1651
  border-color: #cbd5e1 !important;
1652
  }
1653
 
1654
- #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-partial {
 
1655
  --bn-species-status-border: #f59e0b;
1656
  --bn-species-status-accent: #f59e0b;
1657
  --bn-species-status-bg: #fff7ed;
@@ -1660,7 +1662,8 @@ button.bn-report-download-action-blue:hover {
1660
  border-color: #f59e0b !important;
1661
  }
1662
 
1663
- #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-complete {
 
1664
  --bn-species-status-border: #16a34a;
1665
  --bn-species-status-accent: #16a34a;
1666
  --bn-species-status-bg: #ecfdf3;
 
1642
  color: var(--bn-species-status-text, var(--bn-text)) !important;
1643
  }
1644
 
1645
+ #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-unvalidated,
1646
+ #bn-species-filter li[data-testid="dropdown-option"][data-species-status="unvalidated"] {
1647
  --bn-species-status-border: #cbd5e1;
1648
  --bn-species-status-accent: #94a3b8;
1649
  --bn-species-status-bg: #f8fafc;
 
1652
  border-color: #cbd5e1 !important;
1653
  }
1654
 
1655
+ #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-partial,
1656
+ #bn-species-filter li[data-testid="dropdown-option"][data-species-status="partial"] {
1657
  --bn-species-status-border: #f59e0b;
1658
  --bn-species-status-accent: #f59e0b;
1659
  --bn-species-status-bg: #fff7ed;
 
1662
  border-color: #f59e0b !important;
1663
  }
1664
 
1665
+ #bn-species-filter li[data-testid="dropdown-option"].bn-species-option-complete,
1666
+ #bn-species-filter li[data-testid="dropdown-option"][data-species-status="complete"] {
1667
  --bn-species-status-border: #16a34a;
1668
  --bn-species-status-accent: #16a34a;
1669
  --bn-species-status-bg: #ecfdf3;
tests/unit/test_app_factory_audio_helpers.py CHANGED
@@ -45,6 +45,7 @@ from src.ui.app_factory import (
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
@@ -784,6 +785,15 @@ def test_species_status_dropdown_script_targets_dropdown_without_changing_choice
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(),
 
45
  _write_validation_export,
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
 
785
  assert "bn-species-option-unvalidated" in script
786
 
787
 
788
+ def test_species_status_payload_is_hidden_json_carrier() -> None:
789
+ payload = _species_status_payload({"Species A": {"status": "complete", "total": 1, "reviewed": 1}})
790
+
791
+ assert 'class="bn-species-status-data"' in payload
792
+ assert "data-json=" in payload
793
+ assert "&quot;Species A&quot;" in payload
794
+ assert "&quot;complete&quot;" in payload
795
+
796
+
797
  def test_page_to_table_marks_conflict_row() -> None:
798
  rows, _, _ = _page_to_table(
799
  service=FakeQueueService(),