Replaced labels with icons in the SR and Action badges
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivities, requestConsumerTokenServiceOnce, sendRuntimeMessage,
|
||||
appendBackgroundRequestLog, queueProductsTableRender, productsContentState, messageTypes, reportProgress, activityCache, environment }) {
|
||||
appendBackgroundRequestLog, queueProductsTableRender, productsContentState, messageTypes, reportProgress, activityCache, createActionButton, closeActionForm, setBadgeContent, environment }) {
|
||||
let session = newSession();
|
||||
function newSession() { return { enabled: true, records: new Map(), queue: [], running: 0, progress: new Set() }; }
|
||||
function updateProgress(current) {
|
||||
@@ -10,6 +10,7 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
reportProgress(completed < records.length ? "running" : failed ? "complete-with-errors" : "complete", completed, records.length);
|
||||
}
|
||||
function reset(enabled = true) {
|
||||
closeActionForm(false);
|
||||
session.enabled = false;
|
||||
for (const job of session.queue) job.record.resolveCompletion();
|
||||
session.queue.length = 0;
|
||||
@@ -46,6 +47,12 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
for (const products of productsContentState.opptyProductsByNumber.values()) loadProducts(products);
|
||||
queueProductsTableRender();
|
||||
}
|
||||
function blockProducts(products) {
|
||||
if (!allowsCrmActivities()) return;
|
||||
for (const id of idsFor(products)) {
|
||||
session.records.set(id, { status: "error", actions: [], hasNext: false, error: "CRM service requests unavailable." });
|
||||
}
|
||||
}
|
||||
function pump(current) {
|
||||
while (current.enabled && current === session && current.running < 4 && current.queue.length) {
|
||||
const job = current.queue.shift();
|
||||
@@ -66,12 +73,21 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
if (cacheOptions?.cacheOnly) { record.status = "error"; record.error = "No matching activity cache for this product update."; return; }
|
||||
current.progress.add(record);
|
||||
updateProgress(current);
|
||||
const authorizations = await requestConsumerTokenServiceOnce();
|
||||
if (!current.enabled || current !== session || current.records.get(revnId) !== record || !allowsCrmActivities()) return;
|
||||
const result = await sendRuntimeMessage({ type: messageTypes.requestWlActions, revnId, authorization: authorizations?.workloadActions });
|
||||
if (!current.enabled || current !== session || current.records.get(revnId) !== record || !allowsCrmActivities()) return;
|
||||
appendBackgroundRequestLog(result?.debugRequests);
|
||||
if (!result?.ok) throw new Error(result?.error || "Unable to load workload actions.");
|
||||
let result;
|
||||
for (let attempt = 1; attempt <= 5; attempt += 1) {
|
||||
try {
|
||||
if (!current.enabled || current !== session || current.records.get(revnId) !== record || !allowsCrmActivities()) return;
|
||||
const authorizations = await requestConsumerTokenServiceOnce();
|
||||
if (!current.enabled || current !== session || current.records.get(revnId) !== record || !allowsCrmActivities()) return;
|
||||
result = await sendRuntimeMessage({ type: messageTypes.requestWlActions, revnId, authorization: authorizations?.workloadActions });
|
||||
if (!current.enabled || current !== session || current.records.get(revnId) !== record || !allowsCrmActivities()) return;
|
||||
appendBackgroundRequestLog(result?.debugRequests);
|
||||
if (!result?.ok) throw new Error(result?.error || "Unable to load workload actions.");
|
||||
break;
|
||||
} catch (error) {
|
||||
if (attempt === 5) throw error;
|
||||
}
|
||||
}
|
||||
record.actions = result.actions;
|
||||
record.hasNext = result.hasNext;
|
||||
record.status = "ready";
|
||||
@@ -107,7 +123,7 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
const badge = environment.document.createElement("span");
|
||||
badge.className = "opportunities-extension-crm-sr-badge opportunities-extension-wl-actions-badge";
|
||||
badge.setAttribute("data-state", state);
|
||||
badge.textContent = state === "matched" ? "\u2705 Act" : state === "missing" ? "\u26d4 Act" : state === "loading" ? "Act ..." : "Act ?";
|
||||
setBadgeContent(badge, "actions", state === "matched" || state === "missing" ? actions.length : state === "loading" ? "..." : "?");
|
||||
badge.title = actions.length ? actions.map(action => [
|
||||
`Action: ${action.name ?? "N/D"}`, `ID: ${action.id ?? "N/D"}`, `Status: ${action.status ?? "N/D"}`,
|
||||
`Owner: ${action.owner || "N/D"}`, `Email: ${action.ownerEmail || "N/D"}`, `Workload: ${action.workloadName || "N/D"}`,
|
||||
@@ -120,7 +136,8 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
if (actions.length && (pending || uncertain)) badge.title += "\nSome workloads are still loading or could not be fully checked.";
|
||||
badge.tabIndex = 0;
|
||||
badge.setAttribute("aria-label", badge.title);
|
||||
if (state === "missing") badge.append(createActionButton(String(optyNumber)));
|
||||
return badge;
|
||||
}
|
||||
return { reset, reopen, loadProducts, createBadge, getSummary };
|
||||
return { reset, reopen, loadProducts, blockProducts, createBadge, getSummary };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user