Improved the background request loading order
This commit is contained in:
@@ -273,6 +273,7 @@ function createContentApplication(overrides = {}) {
|
||||
setOpportunitiesTableState: (...args) => opportunitiesTable.setOpportunitiesTableState(...args)
|
||||
});
|
||||
const fusionOpportunities = createFusionOpportunities({
|
||||
loadServiceRequests: (token, version) => opportunityCrmServiceRequests.load(token, version),
|
||||
resetDebugRequests: () => debugState.reset(),
|
||||
OPPORTUNITIES_PAGE_LIMIT: contracts.OPPORTUNITIES_PAGE_LIMIT,
|
||||
OPPORTUNITIES_QUERY_URL: contracts.OPPORTUNITIES_QUERY_URL,
|
||||
@@ -352,6 +353,9 @@ function createContentApplication(overrides = {}) {
|
||||
requestPillars: () => requestSrFormLookup(messageTypes.requestSrLookupPrimaryPillar)
|
||||
});
|
||||
const opportunityCrmServiceRequests = createOpportunityCrmServiceRequests({
|
||||
onStateChange: () => {
|
||||
if (environment.document?.getElementById?.(contracts.OPPORTUNITIES_TABLE_ID)) opportunitiesTable.renderOpportunitiesTable();
|
||||
},
|
||||
formatDate: value => opportunitiesFormatters.formatOracleResponseDate(value),
|
||||
createSrButton: number => crmSrForm.createButton(number),
|
||||
closeSrForm: () => { internalSrForm.close(false); crmSrForm.close(false); },
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurrentPeriodRequest, bindPopover, closePopover, createSrButton, closeSrForm, allowsCrmActivities, reportProgress, activityCache, setBadgeContent, formatDate, environment }) {
|
||||
function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurrentPeriodRequest, bindPopover, closePopover, createSrButton, closeSrForm, allowsCrmActivities, reportProgress, activityCache, setBadgeContent, formatDate, environment, onStateChange = () => {} }) {
|
||||
let status = "idle";
|
||||
let byOpportunity = new Map();
|
||||
let pending = null;
|
||||
@@ -20,6 +20,7 @@ function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurre
|
||||
async function run(token, version, currentGeneration, cacheOptions) {
|
||||
const isActive = () => currentGeneration === generation;
|
||||
status = "loading";
|
||||
onStateChange();
|
||||
try {
|
||||
const cached = cacheOptions ? await activityCache.read("sr", "all", cacheOptions.cachedAt) : null;
|
||||
if (!isActive()) return false;
|
||||
@@ -45,9 +46,11 @@ function createOpportunityCrmServiceRequests({ requestCrmServiceRequest, isCurre
|
||||
loadedItems = items;
|
||||
status = "ready";
|
||||
if (!cached) reportProgress("complete", items.length, items.length);
|
||||
// Refresh SR badges, filters and totals independently of product/action jobs.
|
||||
onStateChange();
|
||||
return true;
|
||||
} catch {
|
||||
if (isActive()) { status = "error"; reportProgress("error"); }
|
||||
if (isActive()) { status = "error"; reportProgress("error"); onStateChange(); }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ function createFusionOpportunities({
|
||||
getOpportunityTypeValues,
|
||||
readResponseBodyForDebug,
|
||||
resetDebugRequests = () => {},
|
||||
loadServiceRequests = async () => {},
|
||||
environment
|
||||
}) {
|
||||
const { fetch } = environment;
|
||||
@@ -37,7 +38,13 @@ function createFusionOpportunities({
|
||||
const payload = createOpportunitiesQueryPayload(dateRange, offset, savedSearchNumber);
|
||||
const requestBody = JSON.stringify(payload);
|
||||
// One history per query, preserving all pages of the same result set.
|
||||
if (page === 1) resetDebugRequests();
|
||||
if (page === 1) {
|
||||
resetDebugRequests();
|
||||
// SR queries do not depend on opportunity or product IDs. Keep their
|
||||
// diagnostics in this query's history and reuse the loaded SR state later.
|
||||
try { await loadServiceRequests(token, requestVersion); } catch { /* SR failure must not block opportunities. */ }
|
||||
if (!isCurrentPeriodRequest(requestVersion)) return null;
|
||||
}
|
||||
const requestEntry = logRequestStart({
|
||||
name: "requestOpportunities",
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user