53aae016f7
* setup * handle current billing period * handle billing period selection * clean up * clean up * turn serializer to class * change to classes * placeholding, handles timezone issues for this.startTime * put in depen * fixing timezone issues for endTime * clean up * move formating on Get to the adapter. Still need to return formating from Get on serializer * fix current billing period * move all inside queryRecord to hit serilaizer * move to serializer * clean up * calendar clean up * clean up * fix styling * small fixes * small fixes Co-authored-by: Claire Bontempo <cbontempo@hashicorp.com>
58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
import ApplicationSerializer from '../application';
|
|
import { formatISO } from 'date-fns';
|
|
|
|
export default class MonthlySerializer extends ApplicationSerializer {
|
|
flattenDataset(payload) {
|
|
let topTen = payload ? payload.slice(0, 10) : [];
|
|
|
|
return topTen.map((ns) => {
|
|
// 'namespace_path' is an empty string for root
|
|
if (ns['namespace_id'] === 'root') ns['namespace_path'] = 'root';
|
|
let label = ns['namespace_path'];
|
|
let flattenedNs = {};
|
|
// we don't want client counts nested within the 'counts' object for stacked charts
|
|
Object.keys(ns['counts']).forEach((key) => (flattenedNs[key] = ns['counts'][key]));
|
|
|
|
// homogenize client naming for all namespaces
|
|
if (Object.keys(flattenedNs).includes('distinct_entities', 'non_entity_tokens')) {
|
|
flattenedNs.entity_clients = flattenedNs.distinct_entities;
|
|
flattenedNs.non_entity_clients = flattenedNs.non_entity_tokens;
|
|
delete flattenedNs.distinct_entities;
|
|
delete flattenedNs.non_entity_tokens;
|
|
}
|
|
|
|
// if mounts attribution unavailable, mounts will be undefined
|
|
flattenedNs.mounts = ns.mounts?.map((mount) => {
|
|
let flattenedMount = {};
|
|
flattenedMount.label = mount['path'];
|
|
Object.keys(mount['counts']).forEach((key) => (flattenedMount[key] = mount['counts'][key]));
|
|
return flattenedMount;
|
|
});
|
|
|
|
return {
|
|
label,
|
|
...flattenedNs,
|
|
};
|
|
});
|
|
}
|
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
let { data } = payload;
|
|
let { clients, distinct_entities, non_entity_tokens } = data;
|
|
let response_timestamp = formatISO(new Date());
|
|
let transformedPayload = {
|
|
...payload,
|
|
response_timestamp,
|
|
by_namespace: this.flattenDataset(data.by_namespace),
|
|
// nest within 'total' object to mimic /activity response shape
|
|
total: {
|
|
clients,
|
|
entityClients: distinct_entities,
|
|
nonEntityClients: non_entity_tokens,
|
|
},
|
|
};
|
|
delete payload.data.by_namespace;
|
|
return super.normalizeResponse(store, primaryModelClass, transformedPayload, id, requestType);
|
|
}
|
|
}
|