Adjustment to the request debug view functionality
This commit is contained in:
@@ -8,6 +8,27 @@ function createDebugContentView({
|
||||
environment
|
||||
}) {
|
||||
const { document } = environment;
|
||||
const categories = [
|
||||
["all", "All"], ["authentication", "Authentication"],
|
||||
["opportunities", "Opportunities"], ["products", "Products"],
|
||||
["ai", "AI"], ["consumption", "Consumption"], ["other", "Other"]
|
||||
];
|
||||
let selectedCategory = "all";
|
||||
const expandedIds = new Set();
|
||||
|
||||
function getRequestCategory(entry) {
|
||||
if (/^request(?:TokenRelay|ConsumerTokenService|CustomerTokenService)/.test(entry.name)) return "authentication";
|
||||
if (entry.name === "requestOpportunities") return "opportunities";
|
||||
if (entry.name === "requestOpptyProducts") return "products";
|
||||
if (entry.name === "requestGenerateAiSummary") return "ai";
|
||||
if (/^request(?:AccountSummary|AccountPlans|ConsumptionService)/.test(entry.name)) return "consumption";
|
||||
return "other";
|
||||
}
|
||||
|
||||
function getChronologicalRequests() {
|
||||
return [...debugState.requestLog].sort((a, b) =>
|
||||
(new Date(a.startedAt).getTime() || 0) - (new Date(b.startedAt).getTime() || 0) || a.id - b.id);
|
||||
}
|
||||
function toggleDebugPanel() {
|
||||
const modal = document.getElementById(MODAL_ID);
|
||||
|
||||
@@ -32,6 +53,13 @@ function createDebugContentView({
|
||||
return;
|
||||
}
|
||||
|
||||
for (const item of panel.querySelectorAll("details[data-request-id]")) {
|
||||
const id = item.getAttribute("data-request-id");
|
||||
if (item.open) expandedIds.add(id);
|
||||
else expandedIds.delete(id);
|
||||
}
|
||||
const focusedCategory = document.activeElement && document.activeElement.getAttribute("data-debug-category");
|
||||
const scrollTop = panel.scrollTop;
|
||||
panel.textContent = "";
|
||||
|
||||
const panelHeader = document.createElement("header");
|
||||
@@ -43,6 +71,8 @@ function createDebugContentView({
|
||||
|
||||
const summary = document.createElement("p");
|
||||
summary.textContent = `${debugState.requestLog.length} request${debugState.requestLog.length === 1 ? "" : "s"} since modal opened.`;
|
||||
const running = debugState.requestLog.filter(entry => entry.status === "pending").length;
|
||||
if (running) summary.textContent += ` ${running} running.`;
|
||||
heading.append(title, summary);
|
||||
|
||||
const visibilityButton = document.createElement("button");
|
||||
@@ -58,8 +88,51 @@ function createDebugContentView({
|
||||
});
|
||||
panelHeader.append(heading, visibilityButton);
|
||||
|
||||
const entries = getChronologicalRequests();
|
||||
const availableCategories = categories.filter(([key]) => key === "all" || entries.some(entry => getRequestCategory(entry) === key));
|
||||
if (!availableCategories.some(([key]) => key === selectedCategory)) selectedCategory = "all";
|
||||
const tabs = document.createElement("div");
|
||||
tabs.className = "opportunities-extension-debug-tabs";
|
||||
tabs.setAttribute("role", "tablist");
|
||||
tabs.setAttribute("aria-label", "Request categories");
|
||||
const tabButtons = [];
|
||||
availableCategories.forEach(([key, label], index) => {
|
||||
const categoryEntries = key === "all" ? entries : entries.filter(entry => getRequestCategory(entry) === key);
|
||||
const pending = categoryEntries.filter(entry => entry.status === "pending").length;
|
||||
const button = document.createElement("button");
|
||||
button.type = "button";
|
||||
button.id = `${DEBUG_PANEL_ID}-tab-${key}`;
|
||||
button.setAttribute("role", "tab");
|
||||
button.setAttribute("data-debug-category", key);
|
||||
button.setAttribute("aria-selected", String(key === selectedCategory));
|
||||
button.setAttribute("aria-controls", `${DEBUG_PANEL_ID}-requests`);
|
||||
button.tabIndex = key === selectedCategory ? 0 : -1;
|
||||
button.textContent = `${label} (${categoryEntries.length})${pending ? ` / ${pending} running` : ""}`;
|
||||
button.addEventListener("click", () => {
|
||||
selectedCategory = key;
|
||||
renderDebugPanel();
|
||||
});
|
||||
button.addEventListener("keydown", event => {
|
||||
let nextIndex;
|
||||
if (event.key === "ArrowRight") nextIndex = (index + 1) % availableCategories.length;
|
||||
else if (event.key === "ArrowLeft") nextIndex = (index + availableCategories.length - 1) % availableCategories.length;
|
||||
else if (event.key === "Home") nextIndex = 0;
|
||||
else if (event.key === "End") nextIndex = availableCategories.length - 1;
|
||||
else return;
|
||||
event.preventDefault();
|
||||
selectedCategory = availableCategories[nextIndex][0];
|
||||
renderDebugPanel();
|
||||
});
|
||||
tabs.append(button);
|
||||
tabButtons.push(button);
|
||||
});
|
||||
|
||||
const list = document.createElement("div");
|
||||
list.className = "opportunities-extension-debug-list";
|
||||
list.id = `${DEBUG_PANEL_ID}-requests`;
|
||||
list.setAttribute("role", "tabpanel");
|
||||
list.setAttribute("aria-labelledby", `${DEBUG_PANEL_ID}-tab-${selectedCategory}`);
|
||||
list.tabIndex = 0;
|
||||
|
||||
if (debugState.requestLog.length === 0) {
|
||||
const empty = document.createElement("div");
|
||||
@@ -68,15 +141,20 @@ function createDebugContentView({
|
||||
list.append(empty);
|
||||
}
|
||||
|
||||
debugState.requestLog.forEach((entry) => {
|
||||
entries.filter(entry => selectedCategory === "all" || getRequestCategory(entry) === selectedCategory).forEach((entry) => {
|
||||
const item = document.createElement("details");
|
||||
item.className = `opportunities-extension-debug-item opportunities-extension-debug-item-${entry.status}`;
|
||||
item.setAttribute("data-request-id", String(entry.id));
|
||||
item.open = expandedIds.has(String(entry.id));
|
||||
|
||||
const heading = document.createElement("summary");
|
||||
heading.className = "opportunities-extension-debug-heading";
|
||||
|
||||
const name = document.createElement("strong");
|
||||
name.textContent = `${entry.id}. ${entry.name}`;
|
||||
if (entry.name === "requestOpptyProducts" && entry.metadata.optyNumber) {
|
||||
name.textContent += ` (${entry.metadata.optyNumber}, offset ${entry.metadata.offset})`;
|
||||
}
|
||||
|
||||
const httpStatus = document.createElement("span");
|
||||
httpStatus.className = "opportunities-extension-debug-http-status";
|
||||
@@ -84,11 +162,15 @@ function createDebugContentView({
|
||||
|
||||
const status = document.createElement("span");
|
||||
status.className = "opportunities-extension-debug-status";
|
||||
status.textContent = entry.status;
|
||||
status.textContent = entry.status === "pending" ? "running" : entry.status;
|
||||
|
||||
const summaryMeta = document.createElement("span");
|
||||
summaryMeta.className = "opportunities-extension-debug-summary-meta";
|
||||
summaryMeta.append(httpStatus, status);
|
||||
const startedTime = document.createElement("time");
|
||||
startedTime.className = "opportunities-extension-debug-time";
|
||||
startedTime.textContent = formatDebugTime(entry.startedAt);
|
||||
startedTime.title = `Started: ${entry.startedAt.toLocaleString()}`;
|
||||
summaryMeta.append(startedTime, httpStatus, status);
|
||||
|
||||
heading.append(name, summaryMeta);
|
||||
|
||||
@@ -114,7 +196,9 @@ function createDebugContentView({
|
||||
list.append(item);
|
||||
});
|
||||
|
||||
panel.append(panelHeader, list);
|
||||
panel.append(panelHeader, tabs, list);
|
||||
if (focusedCategory) tabButtons.find(button => button.getAttribute("data-debug-category") === selectedCategory).focus({ preventScroll: true });
|
||||
panel.scrollTop = scrollTop;
|
||||
}
|
||||
|
||||
function createDebugVisibilityIcon(secretsVisible) {
|
||||
@@ -170,5 +254,5 @@ function createDebugContentView({
|
||||
});
|
||||
}
|
||||
|
||||
return { toggleDebugPanel, renderDebugPanel, createDebugVisibilityIcon, appendDebugBlock, formatDebugTime };
|
||||
return { toggleDebugPanel, renderDebugPanel, createDebugVisibilityIcon, appendDebugBlock, formatDebugTime, getRequestCategory, getChronologicalRequests };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user