Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI/Add months to activity serializer #14942

Merged
merged 5 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ui/app/models/clients/activity.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Model, { attr } from '@ember-data/model';
export default class Activity extends Model {
@attr('string') responseTimestamp;
@attr('array') byMonthTotalClients;
@attr('array') byMonthNewClients;
@attr('array') byNamespace;
@attr('object') total;
@attr('array') formattedEndTime;
@attr('array') formattedStartTime;
@attr('string') startTime;
@attr('string') endTime;
@attr('object') total;
@attr('string') responseTimestamp;
}
59 changes: 51 additions & 8 deletions ui/app/serializers/clients/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ export default class ActivitySerializer extends ApplicationSerializer {
Object.keys(ns['counts']).forEach((key) => (flattenedNs[key] = ns['counts'][key]));
flattenedNs = this.homogenizeClientNaming(flattenedNs);

// TODO CMB check how this works with actual API endpoint
// if no mounts, mounts will be an empty array
flattenedNs.mounts = ns.mounts
? ns.mounts.map((mount) => {
let flattenedMount = {};
flattenedMount.label = mount['mount_path'];
let label = mount['mount_path'];
Object.keys(mount['counts']).forEach((key) => (flattenedMount[key] = mount['counts'][key]));
return flattenedMount;
flattenedMount = this.homogenizeClientNaming(flattenedMount);
return {
label,
...flattenedMount,
};
})
: [];

Expand All @@ -29,12 +32,50 @@ export default class ActivitySerializer extends ApplicationSerializer {
});
}

// For 1.10 release naming changed from 'distinct_entities' to 'entity_clients' and
// for vault usage - vertical bar chart
flattenByMonths(payload, isNewClients = false) {
if (isNewClients) {
return payload.map((m) => {
return {
month: m.timestamp,
entity_clients: m['new_clients']['counts']['entity_clients'],
non_entity_clients: m['new_clients']['counts']['non_entity_clients'],
total: m['new_clients']['counts']['clients'],
namespaces: this.flattenDataset(m['new_clients']['namespaces']),
};
});
} else {
return payload.map((m) => {
return {
month: m.timestamp,
entity_clients: m['counts']['entity_clients'],
non_entity_clients: m['counts']['non_entity_clients'],
total: m['counts']['clients'],
namespaces: this.flattenDataset(m['namespaces']),
new_clients: {
entity_clients: m['new_clients']['counts']['entity_clients'],
non_entity_clients: m['new_clients']['counts']['non_entity_clients'],
total: m['new_clients']['counts']['clients'],
namespaces: this.flattenDataset(m['new_clients']['namespaces']),
},
};
});
}
}

// In 1.10 'distinct_entities' changed to 'entity_clients' and
// 'non_entity_tokens' to 'non_entity_clients'
// accounting for deprecated API keys here and updating to latest nomenclature
homogenizeClientNaming(object) {
// TODO CMB check with API payload, latest draft includes both new and old key names
// TODO CMB Delete old key names IF correct ones exist?
// if new key names exist, only return those key/value pairs
if (Object.keys(object).includes('entity_clients', 'non_entity_clients')) {
let { clients, entity_clients, non_entity_clients } = object;
return {
clients,
entity_clients,
non_entity_clients,
};
}
// if object only has outdated key names, update naming
if (Object.keys(object).includes('distinct_entities', 'non_entity_tokens')) {
let entity_clients = object.distinct_entities;
let non_entity_clients = object.non_entity_tokens;
Expand All @@ -45,7 +86,6 @@ export default class ActivitySerializer extends ApplicationSerializer {
non_entity_clients,
};
}
return object;
}

parseRFC3339(timestamp) {
Expand All @@ -64,11 +104,14 @@ export default class ActivitySerializer extends ApplicationSerializer {
...payload,
response_timestamp,
by_namespace: this.flattenDataset(payload.data.by_namespace),
by_month_total_clients: this.flattenByMonths(payload.data.months),
by_month_new_clients: this.flattenByMonths(payload.data.months, { isNewClients: true }),
total: this.homogenizeClientNaming(payload.data.total),
formatted_end_time: this.parseRFC3339(payload.data.end_time),
formatted_start_time: this.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);
}
Expand Down
Loading