Implemented filters for Service Requests and Actions
This commit is contained in:
@@ -11,6 +11,7 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
}
|
||||
function reset(enabled = true) {
|
||||
session.enabled = false;
|
||||
for (const job of session.queue) job.record.resolveCompletion();
|
||||
session.queue.length = 0;
|
||||
session = newSession();
|
||||
session.enabled = enabled;
|
||||
@@ -21,17 +22,24 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
}
|
||||
function loadProducts(products, refresh = false, cacheOptions = null) {
|
||||
if (!session.enabled || !allowsCrmActivities()) return;
|
||||
const pending = [];
|
||||
if ([...session.progress].every(record => record.status !== "loading")) session.progress.clear();
|
||||
for (const revnId of idsFor(products)) {
|
||||
if (!refresh && session.records.has(revnId)) continue;
|
||||
if (!refresh && session.records.has(revnId)) {
|
||||
pending.push(session.records.get(revnId).completion);
|
||||
continue;
|
||||
}
|
||||
session.progress.delete(session.records.get(revnId));
|
||||
const record = { status: "loading", actions: [], hasNext: false };
|
||||
record.completion = new Promise(resolve => { record.resolveCompletion = resolve; });
|
||||
pending.push(record.completion);
|
||||
session.records.set(revnId, record);
|
||||
if (!cacheOptions) session.progress.add(record);
|
||||
session.queue.push({ revnId, record, cacheOptions });
|
||||
}
|
||||
updateProgress(session);
|
||||
pump(session);
|
||||
return Promise.all(pending);
|
||||
}
|
||||
function reopen() {
|
||||
reset();
|
||||
@@ -73,10 +81,11 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
record.status = "error";
|
||||
record.error = error.message || "Unable to load workload actions.";
|
||||
} finally {
|
||||
record.resolveCompletion();
|
||||
if (current.enabled && current === session) { updateProgress(current); queueProductsTableRender(); }
|
||||
}
|
||||
}
|
||||
function createBadge(optyNumber) {
|
||||
function getSummary(optyNumber) {
|
||||
if (!session.enabled || !allowsCrmActivities() || !optyNumber) return null;
|
||||
const products = productsContentState.opptyProductsByNumber.get(String(optyNumber));
|
||||
if (!products) return null;
|
||||
@@ -89,6 +98,12 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
const principal = authSessionState.principal;
|
||||
const owned = Boolean(principal) && actions.some(action => typeof action.owner === "string" && action.owner.trim() === principal);
|
||||
const state = owned ? "matched" : pending ? "loading" : uncertain || !principal ? "error" : "missing";
|
||||
return { state, actions, records, principal, pending, uncertain };
|
||||
}
|
||||
function createBadge(optyNumber) {
|
||||
const summary = getSummary(optyNumber);
|
||||
if (!summary) return null;
|
||||
const { state, actions, records, principal, pending, uncertain } = summary;
|
||||
const badge = environment.document.createElement("span");
|
||||
badge.className = "opportunities-extension-crm-sr-badge opportunities-extension-wl-actions-badge";
|
||||
badge.setAttribute("data-state", state);
|
||||
@@ -107,5 +122,5 @@ function createOpportunityWorkloadActions({ authSessionState, allowsCrmActivitie
|
||||
badge.setAttribute("aria-label", badge.title);
|
||||
return badge;
|
||||
}
|
||||
return { reset, reopen, loadProducts, createBadge };
|
||||
return { reset, reopen, loadProducts, createBadge, getSummary };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user