33de0a0a49
* setup * add new clients to attribution * refactor serializers, move to util folder * cleanup export csv generator * fix isDateRange getter * remove new chart from partial/current month * fix export modal text * update version history text * update variable naming, remove new client data from current/partial month * add filtering by namespace to month over month charts * remove filtering for namespace by month, need to change serializer * add checks * update horizontal bar chart test * update tests * cleanup * address comments * fix flakey test * add new counts to export Co-authored-by: Claire Bontempo <cbontempo@hashicorp.com>
70 lines
2 KiB
JavaScript
70 lines
2 KiB
JavaScript
import ApplicationSerializer from '../application';
|
|
import { formatISO } from 'date-fns';
|
|
import { parseRFC3339 } from 'core/utils/date-formatters';
|
|
import { formatByMonths, formatByNamespace, homogenizeClientNaming } from 'core/utils/client-count-utils';
|
|
export default class ActivitySerializer extends ApplicationSerializer {
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
if (payload.id === 'no-data') {
|
|
return super.normalizeResponse(store, primaryModelClass, payload, id, requestType);
|
|
}
|
|
let response_timestamp = formatISO(new Date());
|
|
let transformedPayload = {
|
|
...payload,
|
|
response_timestamp,
|
|
by_namespace: formatByNamespace(payload.data.by_namespace),
|
|
by_month: formatByMonths(payload.data.months),
|
|
total: homogenizeClientNaming(payload.data.total),
|
|
formatted_end_time: parseRFC3339(payload.data.end_time),
|
|
formatted_start_time: parseRFC3339(payload.data.start_time),
|
|
};
|
|
delete payload.data.by_namespace;
|
|
delete payload.data.months;
|
|
delete payload.data.total;
|
|
return super.normalizeResponse(store, primaryModelClass, transformedPayload, id, requestType);
|
|
}
|
|
}
|
|
/*
|
|
SAMPLE PAYLOAD BEFORE/AFTER:
|
|
|
|
payload.data.by_namespace = [
|
|
{
|
|
namespace_id: '5SWT8',
|
|
namespace_path: 'namespacelonglonglong4/',
|
|
counts: {
|
|
entity_clients: 171,
|
|
non_entity_clients: 20,
|
|
clients: 191,
|
|
},
|
|
mounts: [
|
|
{
|
|
mount_path: 'auth/method/uMGBU',
|
|
"counts":{
|
|
"distinct_entities":0,
|
|
"entity_clients":0,
|
|
"non_entity_tokens":0,
|
|
"non_entity_clients":10,
|
|
"clients":10
|
|
}
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
transformedPayload.by_namespace = [
|
|
{
|
|
label: 'namespacelonglonglong4/',
|
|
entity_clients: 171,
|
|
non_entity_clients: 20,
|
|
clients: 191,
|
|
mounts: [
|
|
{
|
|
label: 'auth/method/uMGBU',
|
|
entity_clients: 20,
|
|
non_entity_clients: 15,
|
|
clients: 35,
|
|
},
|
|
],
|
|
},
|
|
]
|
|
*/
|