github.com/hernad/nomad@v1.6.112/ui/app/components/das/recommendation-accordion.js (about)

     1  /**
     2   * Copyright (c) HashiCorp, Inc.
     3   * SPDX-License-Identifier: MPL-2.0
     4   */
     5  
     6  import Component from '@glimmer/component';
     7  import { action } from '@ember/object';
     8  import { tracked } from '@glimmer/tracking';
     9  import { task, timeout } from 'ember-concurrency';
    10  import { htmlSafe } from '@ember/template';
    11  import Ember from 'ember';
    12  import ResourcesDiffs from 'nomad-ui/utils/resources-diffs';
    13  
    14  export default class DasRecommendationAccordionComponent extends Component {
    15    @tracked waitingToProceed = false;
    16    @tracked closing = false;
    17    @tracked animationContainerStyle = htmlSafe('');
    18  
    19    @(task(function* () {
    20      this.closing = true;
    21      this.animationContainerStyle = htmlSafe(
    22        `height: ${this.accordionElement.clientHeight}px`
    23      );
    24  
    25      yield timeout(10);
    26  
    27      this.animationContainerStyle = htmlSafe('height: 0px');
    28  
    29      // The 450ms for the animation to complete, set in CSS as $timing-slow
    30      yield timeout(Ember.testing ? 0 : 450);
    31  
    32      this.waitingToProceed = false;
    33    }).drop())
    34    proceed;
    35  
    36    @action
    37    inserted(element) {
    38      this.accordionElement = element;
    39      this.waitingToProceed = true;
    40    }
    41  
    42    get show() {
    43      return !this.args.summary.isProcessed || this.waitingToProceed;
    44    }
    45  
    46    get diffs() {
    47      const summary = this.args.summary;
    48      const taskGroup = summary.taskGroup;
    49  
    50      return new ResourcesDiffs(
    51        taskGroup,
    52        taskGroup.count,
    53        this.args.summary.recommendations,
    54        this.args.summary.excludedRecommendations
    55      );
    56    }
    57  }