Skip to content

Commit 208eb0d

Browse files
Compare scale events by their UID instead of reference equality
1 parent 73e7322 commit 208eb0d

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

ui/app/components/scale-events-chart.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Component from '@ember/component';
2-
import { computed } from '@ember/object';
2+
import { copy } from 'ember-copy';
3+
import { computed, get } from '@ember/object';
34
import { tagName } from '@ember-decorators/component';
45
import classic from 'ember-classic-decorator';
56

@@ -37,12 +38,12 @@ export default class ScaleEventsChart extends Component {
3738
return this.events.rejectBy('hasCount').map(ev => ({
3839
type: ev.error ? 'error' : 'info',
3940
time: ev.time,
40-
event: ev,
41+
event: copy(ev),
4142
}));
4243
}
4344

4445
toggleEvent(ev) {
45-
if (this.activeEvent === ev) {
46+
if (this.activeEvent && get(this.activeEvent, 'event.uid') === get(ev, 'event.uid')) {
4647
this.closeEventDetails();
4748
} else {
4849
this.set('activeEvent', ev);

ui/app/helpers/eq-by.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { get } from '@ember/object';
2+
import { helper } from '@ember/component/helper';
3+
4+
/**
5+
* Eq By
6+
*
7+
* Usage: {{eq-by "prop" obj1 obj2}}
8+
*
9+
* Returns true when obj1 and obj2 have the same value for property "prop"
10+
*/
11+
export function eqBy([prop, obj1, obj2]) {
12+
if (!obj1 || !obj2) return false;
13+
return get(obj1, prop) === get(obj2, prop);
14+
}
15+
16+
export default helper(eqBy);

ui/app/models/scale-event.js

+6
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ export default class ScaleEvent extends Fragment {
3131
return Object.keys(this.meta).length > 0;
3232
})
3333
hasMeta;
34+
35+
// Since scale events don't have proper IDs, this UID is a compromise
36+
@computed('time', 'timeNanos', 'message', function() {
37+
return `${+this.time}${this.timeNanos}_${this.message}`;
38+
})
39+
uid;
3440
}

ui/app/templates/components/line-chart.hbs

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
<div data-test-annotation class="chart-annotation {{annotation.iconClass}} {{annotation.staggerClass}}" style={{annotation.style}}>
3232
<button
3333
type="button"
34-
class="indicator {{if (eq annotation.annotation this.activeAnnotation) "is-active"}}"
34+
class="indicator {{if (or
35+
(and this.annotationKey (eq-by this.annotationKey annotation.annotation this.activeAnnotation))
36+
(and (not this.annotationKey) (eq annotation.annotation this.activeAnnotation))
37+
) "is-active"}}"
3538
title={{annotation.label}}
3639
onclick={{action this.annotationClick annotation.annotation}}>
3740
{{x-icon annotation.icon}}

ui/app/templates/components/scale-events-chart.hbs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@data={{this.data}}
77
@annotations={{this.annotations}}
88
@activeAnnotation={{this.activeEvent}}
9+
@annotationKey="event.uid"
910
@onAnnotationClick={{action this.toggleEvent}} />
1011
{{#if this.activeEvent}}
1112
<div data-test-event-details>

0 commit comments

Comments
 (0)