<commit_before>import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, get } from '@ember/object';
import { inject as service } from '@ember/service';

export default class TopologyMetrics extends Component {
  @service('env') env;

  // =attributes
  @tracked centerDimensions;
  @tracked downView;
  @tracked downLines = [];
  @tracked upView;
  @tracked upLines = [];
  @tracked noMetricsReason;

  // =methods
  drawDownLines(items) {
    const order = ['allow', 'deny'];
    const dest = {
      x: this.centerDimensions.x - 7,
      y: this.centerDimensions.y + this.centerDimensions.height / 2,
    };

    return items
      .map(item => {
        const dimensions = item.getBoundingClientRect();
        const src = {
          x: dimensions.x + dimensions.width,
          y: dimensions.y + dimensions.height / 2,
        };

        return {
          id: item.id,
          permission: item.getAttribute('data-permission'),
          dest: dest,
          src: src,
        };
      })
      .sort((a, b) => {
        return order.indexOf(a.permission) - order.indexOf(b.permission);
      });
  }

  drawUpLines(items) {
    const order = ['allow', 'deny'];
    const src = {
      x: this.centerDimensions.x + 5.5,
      y: this.centerDimensions.y + this.centerDimensions.height / 2,
    };

    return items
      .map(item => {
        const dimensions = item.getBoundingClientRect();
        const dest = {
          x: dimensions.x - dimensions.width - 25,
          y: dimensions.y + dimensions.height / 2,
        };

        return {
          id: item.id,
          permission: item.getAttribute('data-permission'),
          dest: dest,
          src: src,
        };
      })
      .sort((a, b) => {
        return order.indexOf(a.permission) - order.indexOf(b.permission);
      });
  }

  emptyColumn() {
    const noDependencies = get(this.args.topology, 'noDependencies');
    return !this.env.var('CONSUL_ACLS_ENABLED') || noDependencies;
  }

  get downstreams() {
    const downstreams = get(this.args.topology, 'Downstreams') || [];
    const items = [...downstreams];
    const noDependencies = get(this.args.topology, 'noDependencies');

    if (!this.env.var('CONSUL_ACLS_ENABLED') && noDependencies) {
      items.push({
        Name: 'Downstreams unknown.',
        Empty: true,
        Datacenter: '',
        Namespace: '',
      });
    } else if (downstreams.length === 0) {
      items.push({
        Name: 'No downstreams, or the downstreams are imported services.',
        Datacenter: '',
        Namespace: '',
      });
    }

    return items;
  }
<commit_msg>Improve peered service empty downstreams message (#13854)<commit_after>import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, get } from '@ember/object';
import { inject as service } from '@ember/service';

export default class TopologyMetrics extends Component {
  @service('env') env;
  @service() abilities;

  // =attributes
  @tracked centerDimensions;
  @tracked downView;
  @tracked downLines = [];
  @tracked upView;
  @tracked upLines = [];
  @tracked noMetricsReason;

  // =methods
  drawDownLines(items) {
    const order = ['allow', 'deny'];
    const dest = {
      x: this.centerDimensions.x - 7,
      y: this.centerDimensions.y + this.centerDimensions.height / 2,
    };

    return items
      .map(item => {
        const dimensions = item.getBoundingClientRect();
        const src = {
          x: dimensions.x + dimensions.width,
          y: dimensions.y + dimensions.height / 2,
        };

        return {
          id: item.id,
          permission: item.getAttribute('data-permission'),
          dest: dest,
          src: src,
        };
      })
      .sort((a, b) => {
        return order.indexOf(a.permission) - order.indexOf(b.permission);
      });
  }

  drawUpLines(items) {
    const order = ['allow', 'deny'];
    const src = {
      x: this.centerDimensions.x + 5.5,
      y: this.centerDimensions.y + this.centerDimensions.height / 2,
    };

    return items
      .map(item => {
        const dimensions = item.getBoundingClientRect();
        const dest = {
          x: dimensions.x - dimensions.width - 25,
          y: dimensions.y + dimensions.height / 2,
        };

        return {
          id: item.id,
          permission: item.getAttribute('data-permission'),
          dest: dest,
          src: src,
        };
      })
      .sort((a, b) => {
        return order.indexOf(a.permission) - order.indexOf(b.permission);
      });
  }

  emptyColumn() {
    const noDependencies = get(this.args.topology, 'noDependencies');
    return !this.env.var('CONSUL_ACLS_ENABLED') || noDependencies;
  }

  get downstreams() {
    const downstreams = get(this.args.topology, 'Downstreams') || [];
    const items = [...downstreams];
    const noDependencies = get(this.args.topology, 'noDependencies');

    if (!this.env.var('CONSUL_ACLS_ENABLED') && noDependencies) {
      items.push({
        Name: 'Downstreams unknown.',
        Empty: true,
        Datacenter: '',
        Namespace: '',
      });
    } else if (downstreams.length === 0) {
      const canUsePeers = this.abilities.can('use peers');

      items.push({
        Name: canUsePeers
          ? 'No downstreams, or the downstreams are imported services.'
          : 'No downstreams.',
        Datacenter: '',
        Namespace: '',
      });
    }

    return items;
  }

{'fraction_non_alphanumeric': 0.13968715896689704, 'fraction_numerical': 0.004547108039287013, 'mean_word_length': 2.2404242781378905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6438995', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1649, 'n_words': 371}