Links in the column headers

#10
by fzoll - opened
Files changed (1) hide show
  1. app/backend/data_page.py +86 -6
app/backend/data_page.py CHANGED
@@ -7,6 +7,7 @@ import io
7
 
8
  from st_aggrid import AgGrid, JsCode, ColumnsAutoSizeMode
9
  import streamlit as st
 
10
  from utils.st_copy_to_clipboard import st_copy_to_clipboard
11
  from streamlit_theme import st_theme
12
 
@@ -53,7 +54,7 @@ def get_column_state():
53
  get column state from url
54
  """
55
  query_params = st.query_params.get("grid_state", None)
56
- sider_bar_hidden = st.query_params.get("sider_bar_hidden","False")
57
  if query_params:
58
  grid_state = decompress_msgpack(query_params)
59
  st.session_state.grid_state = grid_state
@@ -76,19 +77,18 @@ def render_page(group_name):
76
  [data-testid="stSidebarNav"] {
77
  display: none !important;
78
  }
79
-
80
  [data-testid="stBaseButton-headerNoPadding"] {
81
  display: none !important;
82
  }
83
-
84
  h1#retrieval-embedding-benchmark-rteb {
85
  text-align: center;
86
  }
87
-
88
  </style>
89
  """, unsafe_allow_html=True)
90
 
91
-
92
  # Add theme color and grid styles
93
  st.title("Retrieval Embedding Benchmark (RTEB)")
94
  st.markdown("""
@@ -335,7 +335,87 @@ def render_page(group_name):
335
  'headerStyle': HEADER_STYLE,
336
  'cellStyle': CELL_STYLE,
337
  "headerTooltip": column if "Average" not in column else column.replace("Average",
338
- "").strip().capitalize()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  # 'suppressSizeToFit': True
340
  } for column in column_list if
341
  column not in (avg_column, "Closed average", "Open average")]
 
7
 
8
  from st_aggrid import AgGrid, JsCode, ColumnsAutoSizeMode
9
  import streamlit as st
10
+ import streamlit.components.v1 as components
11
  from utils.st_copy_to_clipboard import st_copy_to_clipboard
12
  from streamlit_theme import st_theme
13
 
 
54
  get column state from url
55
  """
56
  query_params = st.query_params.get("grid_state", None)
57
+ sider_bar_hidden = st.query_params.get("sider_bar_hidden", "False")
58
  if query_params:
59
  grid_state = decompress_msgpack(query_params)
60
  st.session_state.grid_state = grid_state
 
77
  [data-testid="stSidebarNav"] {
78
  display: none !important;
79
  }
80
+
81
  [data-testid="stBaseButton-headerNoPadding"] {
82
  display: none !important;
83
  }
84
+
85
  h1#retrieval-embedding-benchmark-rteb {
86
  text-align: center;
87
  }
88
+
89
  </style>
90
  """, unsafe_allow_html=True)
91
 
 
92
  # Add theme color and grid styles
93
  st.title("Retrieval Embedding Benchmark (RTEB)")
94
  st.markdown("""
 
335
  'headerStyle': HEADER_STYLE,
336
  'cellStyle': CELL_STYLE,
337
  "headerTooltip": column if "Average" not in column else column.replace("Average",
338
+ "").strip().capitalize(),
339
+ 'headerComponent': JsCode(f"""
340
+ class DatasetHeaderRenderer {{
341
+ init(params) {{
342
+ this.eGui = document.createElement('div');
343
+ const columnName = params.displayName;
344
+ const fieldName = params.column.colId;
345
+
346
+ if (fieldName.includes('Average')) {{
347
+ // For group columns (like "Code Average", "English Average"), create clickable link to respective page
348
+ const groupName = fieldName.replace(' Average', '').toLowerCase();
349
+ const link = document.createElement('a');
350
+ link.href = '#';
351
+ link.style.color = 'white';
352
+ link.style.textDecoration = 'underline';
353
+ link.style.cursor = 'pointer';
354
+ link.textContent = columnName;
355
+
356
+ // Prevent event bubbling to avoid sorting trigger and navigate directly
357
+ link.addEventListener('click', function(e) {{
358
+ e.stopPropagation();
359
+ e.preventDefault();
360
+
361
+ // Try multiple navigation approaches
362
+ const targetUrl = '/' + groupName;
363
+
364
+ try {{
365
+ // First try: Navigate the top-level window
366
+ if (window.top && window.top.location && window.top !== window) {{
367
+ window.top.location.assign(targetUrl);
368
+ return;
369
+ }}
370
+ }} catch (ex1) {{
371
+ console.log('Top navigation blocked:', ex1);
372
+ }}
373
+
374
+ try {{
375
+ // Second try: Navigate the parent window
376
+ if (window.parent && window.parent.location && window.parent !== window) {{
377
+ window.parent.location.assign(targetUrl);
378
+ return;
379
+ }}
380
+ }} catch (ex2) {{
381
+ console.log('Parent navigation blocked:', ex2);
382
+ }}
383
+
384
+ try {{
385
+ // Third try: Replace current window location
386
+ window.location.replace(targetUrl);
387
+ }} catch (ex3) {{
388
+ console.log('Current window navigation blocked:', ex3);
389
+ // Last resort: simple assignment
390
+ window.location.href = targetUrl;
391
+ }}
392
+ }});
393
+
394
+ this.eGui.appendChild(link);
395
+ }} else {{
396
+ // For dataset columns, create clickable link to HuggingFace dataset
397
+ const link = document.createElement('a');
398
+ link.href = 'https://huggingface.co/datasets/embedding-benchmark/' + fieldName;
399
+ link.target = '_blank';
400
+ link.style.color = 'white';
401
+ link.style.textDecoration = 'underline';
402
+ link.style.cursor = 'pointer';
403
+ link.textContent = columnName;
404
+
405
+ // Prevent event bubbling to avoid sorting trigger
406
+ link.addEventListener('click', function(e) {{
407
+ e.stopPropagation();
408
+ }});
409
+
410
+ this.eGui.appendChild(link);
411
+ }}
412
+ }}
413
+
414
+ getGui() {{
415
+ return this.eGui;
416
+ }}
417
+ }}
418
+ """)
419
  # 'suppressSizeToFit': True
420
  } for column in column_list if
421
  column not in (avg_column, "Closed average", "Open average")]