open-nomad/ui/app/components/allocation-stat.js
Buck Doyle 89136cbf6a Add massaged results of class codemod
Manual interventions:
• decorators on the same line for service and controller
  injections and most computed property macros
• preserving import order when possible, both per-line
  and intra-line
• moving new imports to the bottom
• removal of classic decorator for trivial cases
• conversion of init to constructor when appropriate
2020-06-10 16:18:42 -05:00

49 lines
1.3 KiB
JavaScript

import Component from '@ember/component';
import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import { formatBytes } from 'nomad-ui/helpers/format-bytes';
import { tagName } from '@ember-decorators/component';
import classic from 'ember-classic-decorator';
@classic
@tagName('')
export default class AllocationStat extends Component {
allocation = null;
statsTracker = null;
isLoading = false;
error = null;
metric = 'memory'; // Either memory or cpu
@computed('metric')
get statClass() {
return this.metric === 'cpu' ? 'is-info' : 'is-danger';
}
@alias('statsTracker.cpu.lastObject') cpu;
@alias('statsTracker.memory.lastObject') memory;
@computed('metric', 'cpu', 'memory')
get stat() {
const { metric } = this;
if (metric === 'cpu' || metric === 'memory') {
return this[this.metric];
}
return;
}
@computed('metric', 'stat.used')
get formattedStat() {
if (!this.stat) return;
if (this.metric === 'memory') return formatBytes([this.stat.used]);
return this.stat.used;
}
@computed('metric', 'statsTracker.{reservedMemory,reservedCPU}')
get formattedReserved() {
if (this.metric === 'memory') return `${this.statsTracker.reservedMemory} MiB`;
if (this.metric === 'cpu') return `${this.statsTracker.reservedCPU} MHz`;
return;
}
}