github.com/hernad/nomad@v1.6.112/ui/app/components/job-status/allocation-status-row.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 // @ts-check 7 import Component from '@glimmer/component'; 8 import { action } from '@ember/object'; 9 import { tracked } from '@glimmer/tracking'; 10 11 const ALLOC_BLOCK_WIDTH = 32; 12 const ALLOC_BLOCK_GAP = 10; 13 14 export default class JobStatusAllocationStatusRowComponent extends Component { 15 @tracked width = 0; 16 17 get allocBlockSlots() { 18 return Object.values(this.args.allocBlocks) 19 .flatMap((statusObj) => Object.values(statusObj)) 20 .flatMap((healthObj) => Object.values(healthObj)) 21 .reduce( 22 (totalSlots, allocsByCanary) => 23 totalSlots + (allocsByCanary ? allocsByCanary.length : 0), 24 0 25 ); 26 } 27 28 get showSummaries() { 29 return ( 30 this.allocBlockSlots * (ALLOC_BLOCK_WIDTH + ALLOC_BLOCK_GAP) - 31 ALLOC_BLOCK_GAP > 32 this.width 33 ); 34 } 35 36 calcPerc(count) { 37 return (count / this.allocBlockSlots) * this.width; 38 } 39 40 @action reflow(element) { 41 this.width = element.clientWidth; 42 } 43 44 @action 45 captureElement(element) { 46 this.width = element.clientWidth; 47 } 48 }