Untitled
unknown
javascript
a year ago
1.6 kB
12
Indexable
const mergedDataReportResponse = useMemo(
() =>
reportResponseTime.reduce(
(accumulator: IReport[], currentData: IReport) => {
const existingEntry = accumulator.find(
(entry) => entry.username === currentData.username
);
if (existingEntry) {
if (currentData.avg_seconds > existingEntry.oldest_agent_inbox) {
existingEntry.oldest_agent_inbox = currentData.avg_seconds;
}
if (existingEntry.oldest_agent_inbox === currentData.avg_seconds) {
existingEntry.oldest_inbox_id = Math.max(currentData.inbox_id);
}
existingEntry.avg_seconds += currentData.avg_seconds;
existingEntry.inbox_reassign_sequence +=
currentData.inbox_reassign_sequence;
existingEntry.inbox_reopen_sequence +=
currentData.inbox_reopen_sequence;
if (Array.isArray(existingEntry.inbox_id)) {
existingEntry.inbox_count += 1;
existingEntry.inbox_id.push(currentData.inbox_id);
}
} else {
accumulator.push({
...currentData,
inbox_count: 1,
oldest_agent_inbox: currentData.avg_seconds || 0,
oldest_inbox_id: currentData.inbox_id || 0,
inbox_id: [currentData.inbox_id] as any,
total_average:
Math.abs(currentData.avg_seconds) / currentData.inbox_count,
});
}
return accumulator;
},
[]
),
[reportResponseTime]
);Editor is loading...
Leave a Comment