github.com/hernad/nomad@v1.6.112/ui/app/components/evaluation-sidebar/detail.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { action } from '@ember/object'; 7 import Component from '@glimmer/component'; 8 import { tracked } from '@glimmer/tracking'; 9 import d3 from 'd3'; 10 import { matchesState } from 'ember-statecharts'; 11 12 export default class Detail extends Component { 13 get statechart() { 14 return this.args.statechart; 15 } 16 17 @matchesState({ sidebar: 'open' }) 18 isSideBarOpen; 19 20 @matchesState({ sidebar: { open: 'success' } }) 21 isSuccess; 22 23 @matchesState({ sidebar: { open: 'busy' } }) 24 isLoading; 25 26 @matchesState({ sidebar: { open: 'error' } }) 27 isError; 28 29 @tracked width = null; 30 @tracked height = null; 31 32 @action 33 handleResize({ target: { scrollWidth: width, scrollHeight: height } }) { 34 if (width === this.width || height === this.height) return; 35 this.height = height; 36 this.width = width; 37 } 38 39 get currentEvalDetail() { 40 return this.statechart.state.context.evaluation; 41 } 42 43 get hierarchy() { 44 try { 45 const data = this.currentEvalDetail?.relatedEvals; 46 47 if (data) { 48 return d3 49 .stratify() 50 .id((d) => { 51 return d.id; 52 }) 53 .parentId((d) => d.previousEval)([ 54 ...data.toArray(), 55 this.currentEvalDetail, 56 ]); 57 } 58 } catch (e) { 59 console.error(`\n\nRelated Evaluation Error: ${e.message}`); 60 } 61 return null; 62 } 63 64 get descendentsMap() { 65 return this.hierarchy 66 ?.descendants() 67 .map((d) => d.children) 68 .compact(); 69 } 70 71 get parentEvaluation() { 72 return this.hierarchy?.data; 73 } 74 75 get error() { 76 return this.statechart.state.context.error; 77 } 78 79 @action 80 closeSidebar() { 81 return this.statechart.send('MODAL_CLOSE'); 82 } 83 84 keyCommands = [ 85 { 86 label: 'Close Evaluations Sidebar', 87 pattern: ['Escape'], 88 action: () => this.closeSidebar(), 89 }, 90 ]; 91 }