UI/client history binary bug (#15714)

* fix null mapping bug

* add test

* add test
This commit is contained in:
claire bontempo
2022-06-01 07:14:07 -07:00
committed by GitHub
parent d78c99e358
commit 1549b442fc
2 changed files with 76 additions and 12 deletions

View File

@@ -4,8 +4,9 @@ import { compareAsc } from 'date-fns';
export const formatByMonths = (monthsArray) => {
// the months array will always include a timestamp of the month and either new/total client data or counts = null
if (!Array.isArray(monthsArray)) return monthsArray;
const sortedPayload = sortMonthsByTimestamp(monthsArray);
return sortedPayload.map((m) => {
return sortedPayload?.map((m) => {
const month = parseAPITimestamp(m.timestamp, 'M/yy');
let totalClientsByNamespace = formatByNamespace(m.namespaces);
let newClientsByNamespace = formatByNamespace(m.new_clients?.namespaces);
@@ -85,8 +86,6 @@ export const flattenDataset = (object) => {
};
export const sortMonthsByTimestamp = (monthsArray) => {
// backend is working on a fix to sort months by date
// right now months are ordered in descending client count number
const sortedPayload = [...monthsArray];
return sortedPayload.sort((a, b) =>
compareAsc(parseAPITimestamp(a.timestamp), parseAPITimestamp(b.timestamp))
@@ -98,12 +97,12 @@ export const namespaceArrayToObject = (totalClientsByNamespace, newClientsByName
// all 'new_client' data resides within a separate key of each month (see data structure below)
// FIRST: iterate and nest respective 'new_clients' data within each namespace and mount object
// note: this is happening within the month object
const nestNewClientsWithinNamespace = totalClientsByNamespace.map((ns) => {
const nestNewClientsWithinNamespace = totalClientsByNamespace?.map((ns) => {
let newNamespaceCounts = newClientsByNamespace?.find((n) => n.label === ns.label);
if (newNamespaceCounts) {
let { label, clients, entity_clients, non_entity_clients } = newNamespaceCounts;
let newClientsByMount = [...newNamespaceCounts?.mounts];
let nestNewClientsWithinMounts = ns.mounts.map((mount) => {
let nestNewClientsWithinMounts = ns.mounts?.map((mount) => {
let new_clients = newClientsByMount?.find((m) => m.label === mount.label) || {};
return {
...mount,
@@ -126,10 +125,9 @@ export const namespaceArrayToObject = (totalClientsByNamespace, newClientsByName
new_clients: {},
};
});
// SECOND: create a new object (namespace_by_key) in which each namespace label is a key
let namespaces_by_key = {};
nestNewClientsWithinNamespace.forEach((namespaceObject) => {
nestNewClientsWithinNamespace?.forEach((namespaceObject) => {
// THIRD: make another object within the namespace where each mount label is a key
let mounts_by_key = {};
namespaceObject.mounts.forEach((mountObject) => {