Saibalaji Namburi commited on
Commit
b19b35f
·
1 Parent(s): a774d8f

fix: simplify session bar — remove token display/copy/refresh, auto-width dropdowns, clean auth badge

Browse files
Files changed (1) hide show
  1. src/api/ui.py +59 -68
src/api/ui.py CHANGED
@@ -245,50 +245,53 @@ HTML_CONTENT = """<!DOCTYPE html>
245
  }
246
 
247
  .control-item select {
248
- width: 130px;
249
- padding: 8px 10px;
 
 
250
  background: rgba(10, 14, 23, 0.9);
251
  border: 1px solid var(--bg-card-border);
252
  border-radius: 8px;
253
  font-size: 12px;
 
 
 
 
 
 
 
 
 
 
 
 
254
  }
255
 
256
- .token-status-badge {
 
 
 
 
 
 
257
  font-size: 11px;
258
  font-weight: 600;
259
- padding: 8px 12px;
260
- border-radius: 8px;
261
  display: inline-flex;
262
  align-items: center;
263
  gap: 6px;
264
- border: 1px solid transparent;
265
  }
266
- .status-green {
267
- background: rgba(16, 185, 129, 0.15);
268
  color: #10b981;
269
- border-color: rgba(16, 185, 129, 0.3);
270
  }
271
- .status-red {
272
- background: rgba(239, 68, 68, 0.15);
273
  color: #ef4444;
274
- border-color: rgba(239, 68, 68, 0.3);
275
- }
276
- .btn-copy-token {
277
- background: rgba(255, 255, 255, 0.05);
278
- border: 1px solid var(--bg-card-border);
279
- color: var(--text-muted);
280
- padding: 8px 12px;
281
- border-radius: 8px;
282
- font-size: 11px;
283
- cursor: pointer;
284
- transition: all 0.2s ease;
285
- display: inline-flex;
286
- align-items: center;
287
- gap: 6px;
288
- }
289
- .btn-copy-token:hover {
290
- background: rgba(255, 255, 255, 0.1);
291
- color: white;
292
  }
293
 
294
  /* Demo Cases / Presets */
@@ -715,40 +718,34 @@ HTML_CONTENT = """<!DOCTYPE html>
715
  </div>
716
  </div>
717
 
718
- <!-- SESSION / AUTHENTICATION CONTROL BAR (REPLACED FROM SIDEBAR) -->
719
  <div class="top-session-bar">
720
  <div class="session-info">
721
- <span class="session-status"></span>
722
  <span class="session-title">Active Session Context</span>
723
  </div>
724
  <div class="session-controls">
725
  <div class="control-item">
726
- <label>Tenant Scope</label>
727
  <select id="widget-tenant" onchange="generateToken()">
728
- <option value="acme-corp" selected>acme-corp (Tenant A)</option>
729
- <option value="globex">globex (Tenant B)</option>
730
- <option value="hooli">hooli (Tenant C)</option>
731
- <option value="test-tenant">test-tenant</option>
732
  </select>
733
  </div>
734
  <div class="control-item">
735
- <label>Operator Role</label>
736
  <select id="widget-role" onchange="generateToken()">
737
  <option value="support_agent">Support Agent</option>
738
- <option value="manager" selected>Manager (HITL access)</option>
739
  <option value="admin">Administrator</option>
740
  </select>
741
  </div>
742
- <div class="token-status-badge status-green" id="token-status">
743
- <span style="width: 8px; height: 8px; border-radius: 50%; background-color: currentColor; display: inline-block;"></span>
744
- <span id="token-status-text">Active (Generated)</span>
745
- </div>
746
- <button class="btn-copy-token" id="btn-copy-jwt" onclick="copyJWTToClipboard()" title="Copy JWT Token" style="display: none;">
747
- 📋 Copy Token
748
- </button>
749
- <button class="btn btn-success" style="padding: 8px 14px; font-size: 12px; border-radius: 8px;" onclick="generateToken()">
750
- 🔄 Refresh Token
751
- </button>
752
  </div>
753
  </div>
754
 
@@ -1091,23 +1088,13 @@ HTML_CONTENT = """<!DOCTYPE html>
1091
  }, 3000);
1092
  }
1093
 
1094
- function copyJWTToClipboard() {
1095
- if (!currentToken) return;
1096
- navigator.clipboard.writeText(currentToken).then(() => {
1097
- showToast("JWT Token copied to clipboard!");
1098
- }).catch(err => {
1099
- console.error('Failed to copy token: ', err);
1100
- showToast("Copy failed", true);
1101
- });
1102
- }
1103
-
1104
  async function generateToken() {
1105
  const tenant = document.getElementById('widget-tenant').value;
1106
  const role = document.getElementById('widget-role').value;
1107
 
1108
- const statusBadge = document.getElementById('token-status');
1109
- const statusText = document.getElementById('token-status-text');
1110
- const copyBtn = document.getElementById('btn-copy-jwt');
1111
 
1112
  try {
1113
  const response = await fetch(`/api/v1/test-token?tenant_id=${tenant}&role=${role}`);
@@ -1117,9 +1104,10 @@ HTML_CONTENT = """<!DOCTYPE html>
1117
  const data = await response.json();
1118
  if(data.token) {
1119
  currentToken = data.token;
1120
- statusBadge.className = "token-status-badge status-green";
1121
- statusText.innerText = "Active (Generated)";
1122
- copyBtn.style.display = "inline-flex";
 
1123
 
1124
  // Reload histories
1125
  if(document.getElementById('dashboard-view').classList.contains('active')) {
@@ -1132,10 +1120,13 @@ HTML_CONTENT = """<!DOCTYPE html>
1132
  }
1133
  } catch(e) {
1134
  console.error("Token generation failed", e);
1135
- statusBadge.className = "token-status-badge status-red";
1136
- statusText.innerText = "Inactive (Error)";
1137
- copyBtn.style.display = "none";
1138
- showToast("Failed to fetch test token", true);
 
 
 
1139
  }
1140
  }
1141
 
 
245
  }
246
 
247
  .control-item select {
248
+ width: auto;
249
+ min-width: 140px;
250
+ max-width: 260px;
251
+ padding: 8px 28px 8px 12px;
252
  background: rgba(10, 14, 23, 0.9);
253
  border: 1px solid var(--bg-card-border);
254
  border-radius: 8px;
255
  font-size: 12px;
256
+ color: var(--text-main);
257
+ appearance: none;
258
+ -webkit-appearance: none;
259
+ background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239ca3af'/%3E%3C/svg%3E");
260
+ background-repeat: no-repeat;
261
+ background-position: right 10px center;
262
+ cursor: pointer;
263
+ transition: border-color 0.2s ease;
264
+ }
265
+
266
+ .control-item select:hover {
267
+ border-color: rgba(99, 102, 241, 0.4);
268
  }
269
 
270
+ .control-item select:focus {
271
+ outline: none;
272
+ border-color: var(--primary);
273
+ box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
274
+ }
275
+
276
+ .auth-status {
277
  font-size: 11px;
278
  font-weight: 600;
279
+ padding: 6px 14px;
280
+ border-radius: 20px;
281
  display: inline-flex;
282
  align-items: center;
283
  gap: 6px;
284
+ transition: all 0.3s ease;
285
  }
286
+ .auth-ok {
287
+ background: rgba(16, 185, 129, 0.12);
288
  color: #10b981;
289
+ border: 1px solid rgba(16, 185, 129, 0.25);
290
  }
291
+ .auth-fail {
292
+ background: rgba(239, 68, 68, 0.12);
293
  color: #ef4444;
294
+ border: 1px solid rgba(239, 68, 68, 0.25);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  }
296
 
297
  /* Demo Cases / Presets */
 
718
  </div>
719
  </div>
720
 
721
+ <!-- SESSION / AUTHENTICATION CONTROL BAR -->
722
  <div class="top-session-bar">
723
  <div class="session-info">
724
+ <span class="session-status" id="session-dot"></span>
725
  <span class="session-title">Active Session Context</span>
726
  </div>
727
  <div class="session-controls">
728
  <div class="control-item">
729
+ <label>Tenant</label>
730
  <select id="widget-tenant" onchange="generateToken()">
731
+ <option value="acme-corp" selected>Acme Corp (Tenant A)</option>
732
+ <option value="globex">Globex Inc (Tenant B)</option>
733
+ <option value="hooli">Hooli Ltd (Tenant C)</option>
734
+ <option value="test-tenant">Test Tenant</option>
735
  </select>
736
  </div>
737
  <div class="control-item">
738
+ <label>Role</label>
739
  <select id="widget-role" onchange="generateToken()">
740
  <option value="support_agent">Support Agent</option>
741
+ <option value="manager" selected>Manager (HITL Access)</option>
742
  <option value="admin">Administrator</option>
743
  </select>
744
  </div>
745
+ <span class="auth-status auth-ok" id="auth-status">
746
+ <span style="width: 7px; height: 7px; border-radius: 50%; background-color: currentColor; display: inline-block; animation: pulse-dot 1.5s infinite;"></span>
747
+ <span id="auth-status-text">Authenticated</span>
748
+ </span>
 
 
 
 
 
 
749
  </div>
750
  </div>
751
 
 
1088
  }, 3000);
1089
  }
1090
 
 
 
 
 
 
 
 
 
 
 
1091
  async function generateToken() {
1092
  const tenant = document.getElementById('widget-tenant').value;
1093
  const role = document.getElementById('widget-role').value;
1094
 
1095
+ const authBadge = document.getElementById('auth-status');
1096
+ const authText = document.getElementById('auth-status-text');
1097
+ const sessionDot = document.getElementById('session-dot');
1098
 
1099
  try {
1100
  const response = await fetch(`/api/v1/test-token?tenant_id=${tenant}&role=${role}`);
 
1104
  const data = await response.json();
1105
  if(data.token) {
1106
  currentToken = data.token;
1107
+ authBadge.className = "auth-status auth-ok";
1108
+ authText.innerText = "Authenticated";
1109
+ sessionDot.style.backgroundColor = "var(--success)";
1110
+ sessionDot.style.boxShadow = "0 0 10px var(--success-glow)";
1111
 
1112
  // Reload histories
1113
  if(document.getElementById('dashboard-view').classList.contains('active')) {
 
1120
  }
1121
  } catch(e) {
1122
  console.error("Token generation failed", e);
1123
+ authBadge.className = "auth-status auth-fail";
1124
+ authText.innerText = "Auth Failed";
1125
+ sessionDot.style.backgroundColor = "var(--danger)";
1126
+ sessionDot.style.boxShadow = "0 0 10px var(--danger-glow)";
1127
+ showToast("Session authentication failed — retrying...", true);
1128
+ // Auto-retry after 3 seconds
1129
+ setTimeout(() => generateToken(), 3000);
1130
  }
1131
  }
1132