Files
nomad/ui/app/components/scale-events-chart.js
Buck Doyle e47ce42548 Update Ember/Ember CLI to 3.20 (#9641)
This doesn’t include Ember Data, as we are still back on 3.12.

Most changes are deprecation updates, linting fixes, and dependencies. It can
be read commit-by-commit, though many of them are mechanical and skimmable.
For the new linting exclusions, I’ve added them to the Tech Debt list.

The decrease in test count is because linting is no longer included in ember test.

There’s a new deprecation warning in the logs that can be fixed by updating Ember
Power Select but when I tried that it caused it to render incorrectly, so I decided to
ignore it for now and address it separately.
2021-02-17 15:01:44 -06:00

57 lines
1.4 KiB
JavaScript

import Component from '@ember/component';
import { copy } from 'ember-copy';
import { computed, get } from '@ember/object';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('')
export default class ScaleEventsChart extends Component {
events = [];
activeEvent = null;
@computed('annotations', 'events.[]')
get data() {
const data = this.events.filterBy('hasCount').sortBy('time');
// Extend the domain of the chart to the current time
data.push({
time: new Date(),
count: data.lastObject.count,
});
// Make sure the domain of the chart includes the first annotation
const firstAnnotation = this.annotations.sortBy('time')[0];
if (firstAnnotation && firstAnnotation.time < data[0].time) {
data.unshift({
time: firstAnnotation.time,
count: data[0].count,
});
}
return data;
}
@computed('events.[]')
get annotations() {
return this.events.rejectBy('hasCount').map(ev => ({
type: ev.error ? 'error' : 'info',
time: ev.time,
event: copy(ev),
}));
}
toggleEvent(ev) {
if (this.activeEvent && get(this.activeEvent, 'event.uid') === get(ev, 'event.uid')) {
this.closeEventDetails();
} else {
this.set('activeEvent', ev);
}
}
closeEventDetails() {
this.set('activeEvent', null);
}
}