<commit_before>/* Copyright (C) 2017 Canonical Ltd. */

'use strict';

/** Status React component used to display Juju status. */
class Status extends React.Component {
  /**
    Return an element class name suitable for the given value.
    @param {String} value The provided value.
    @returns {String} The class name ('ok', 'error' or '').
  */
  _getClass(value) {
    switch (value) {
      case 'active':
      case 'idle':
      case 'started':
        return 'ok';
      case 'blocked':
      case 'down':
      case 'error':
        return 'error';
    }
    return '';
  }

  /**
    Sort by the key attribute.
    @param {Object} a The first value.
    @param {Object} b The second value.
    @returns {Array} The sorted array.
  */
  _byKey(a, b) {
    if (a.key < b.key)
      return -1;
    if (a.key > b.key)
      return 1;
    return 0;
  }

  /**
    Generate the current model status.
    @returns {Object} The resulting element.
  */
  _generateStatus() {
    const elements = [];
    const db = this.props.db;
    const model = this.props.model;
    if (!model.environmentName) {
      // No need to go further: we are not connected to a model.
      return 'Cannot show the status: the GUI is not connected to a model.';
    }
    elements.push(this._generateModel(model));
    if (db.remoteServices.size()) {
      elements.push(this._generateRemoteApplications(db.remoteServices));
    }
    if (db.services.size()) {
      elements.push(
        this._generateApplications(db.services),
        this._generateUnits(db.services)
      );
    }
    if (db.machines.size()) {
      elements.push(this._generateMachines(db.machines));
    }
    if (db.relations.size()) {
      elements.push(this._generateRelations(db.relations));
    }
    return elements;
  }

  /**
    Generate the model fragment of the status.
    @param {Object} model The model attributes.
    @returns {Object} The resulting element.
  */
  _generateModel(model) {
    return (
      <juju.components.BasicTable
        headers={[{
          content: 'Model',
          columnSize: 3
        }, {
          content: 'Cloud/Region',
          columnSize: 3
        }, {
          content: 'Version',
          columnSize: 3
        }, {
          content: 'SLA',
          columnSize: 3
        }]}
        key="model"
        rows={[{
          columns: [{
            columnSize: 3,
            content: model.environmentName
          }, {
            columnSize: 3,
            content: `${model.cloud}/${model.region}`
          }, {
            columnSize: 3,
            content: model.version
          }, {
            columnSize: 3,
            content: model.sla
          }],
          key: 'model'
        }]} />);
  }

  /**
    Navigate to the chosen application.
    @param appId {String} The id of the application to display.
  */
  _navigateToApplication(appId) {
    // Navigate to the app in the inspector, clearing the state so that the
    // app overview is shown.
    this.props.changeState({
      gui: {
        inspector: {
          id: appId,
          activeComponent: undefined,
          unit: null,
          unitStatus: null
        }
      }
    });
  }

  /**
    Navigate to the chosen charm.
    @param charmURL {String} The id of the charm to display.
  */
  _navigateToCharm(charmURL) {
    this.props.changeState({store: charmURL});
  }

  /**
    Navigate to the chosen unit.
    @param unitId {String} The id of the unit to display in the format
      'app-id/unit-id'.
  */
  _navigateToUnit(unitId) {
    const unitParts = unitId.split('/');
    this.props.changeState({
      gui: {
        inspector: {
          id: unitParts[0],
          unit: unitParts[1],
          activeComponent: 'unit'
        }
      }
    });
  }

  /**
    Navigate to the chosen machine.
    @param machineId {String} The id of the machine to display.
  */
  _navigateToMachine(machineId) {
    this.props.changeState({
      gui: {<commit_msg>Make unit variable name more helpful.<commit_after>/* Copyright (C) 2017 Canonical Ltd. */

'use strict';

/** Status React component used to display Juju status. */
class Status extends React.Component {
  /**
    Return an element class name suitable for the given value.
    @param {String} value The provided value.
    @returns {String} The class name ('ok', 'error' or '').
  */
  _getClass(value) {
    switch (value) {
      case 'active':
      case 'idle':
      case 'started':
        return 'ok';
      case 'blocked':
      case 'down':
      case 'error':
        return 'error';
    }
    return '';
  }

  /**
    Sort by the key attribute.
    @param {Object} a The first value.
    @param {Object} b The second value.
    @returns {Array} The sorted array.
  */
  _byKey(a, b) {
    if (a.key < b.key)
      return -1;
    if (a.key > b.key)
      return 1;
    return 0;
  }

  /**
    Generate the current model status.
    @returns {Object} The resulting element.
  */
  _generateStatus() {
    const elements = [];
    const db = this.props.db;
    const model = this.props.model;
    if (!model.environmentName) {
      // No need to go further: we are not connected to a model.
      return 'Cannot show the status: the GUI is not connected to a model.';
    }
    elements.push(this._generateModel(model));
    if (db.remoteServices.size()) {
      elements.push(this._generateRemoteApplications(db.remoteServices));
    }
    if (db.services.size()) {
      elements.push(
        this._generateApplications(db.services),
        this._generateUnits(db.services)
      );
    }
    if (db.machines.size()) {
      elements.push(this._generateMachines(db.machines));
    }
    if (db.relations.size()) {
      elements.push(this._generateRelations(db.relations));
    }
    return elements;
  }

  /**
    Generate the model fragment of the status.
    @param {Object} model The model attributes.
    @returns {Object} The resulting element.
  */
  _generateModel(model) {
    return (
      <juju.components.BasicTable
        headers={[{
          content: 'Model',
          columnSize: 3
        }, {
          content: 'Cloud/Region',
          columnSize: 3
        }, {
          content: 'Version',
          columnSize: 3
        }, {
          content: 'SLA',
          columnSize: 3
        }]}
        key="model"
        rows={[{
          columns: [{
            columnSize: 3,
            content: model.environmentName
          }, {
            columnSize: 3,
            content: `${model.cloud}/${model.region}`
          }, {
            columnSize: 3,
            content: model.version
          }, {
            columnSize: 3,
            content: model.sla
          }],
          key: 'model'
        }]} />);
  }

  /**
    Navigate to the chosen application.
    @param appId {String} The id of the application to display.
  */
  _navigateToApplication(appId) {
    // Navigate to the app in the inspector, clearing the state so that the
    // app overview is shown.
    this.props.changeState({
      gui: {
        inspector: {
          id: appId,
          activeComponent: undefined,
          unit: null,
          unitStatus: null
        }
      }
    });
  }

  /**
    Navigate to the chosen charm.
    @param charmURL {String} The id of the charm to display.
  */
  _navigateToCharm(charmURL) {
    this.props.changeState({store: charmURL});
  }

  /**
    Navigate to the chosen unit.
    @param unitName {String} The name of the unit to display in the format
      'app-id/unit-number'.
  */
  _navigateToUnit(unitName) {
    const unitParts = unitName.split('/');
    this.props.changeState({
      gui: {
        inspector: {
          id: unitParts[0],
          unit: unitParts[1],
          activeComponent: 'unit'
        }
      }
    });
  }

  /**
    Navigate to the chosen machine.
    @param machineId {String} The id of the machine to display.
  */
  _navigateToMachine(machineId) {
    this.props.changeState({
      gui: {
{'fraction_non_alphanumeric': 0.12129954841946813, 'fraction_numerical': 0.004264927245358756, 'mean_word_length': 1.8982188295165394, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6884791', 'n_tokens_mistral': 2422, 'n_tokens_neox': 2353, 'n_words': 675}