import Ember from 'ember';

const {
  Component,
  computed,
  $
} = Ember;

export default Component.extend({
  tagName: 'tr',
  classNames: ['upf-datatable__row'],
  classNameBindings: [
    'isHeaderRow:upf-datatable__row--header',
    'isSelected:upf-datatable__row--selected',
    'isHovering:upf-datatable__row--polymorphic'
  ],

  isSelected: computed.bool('ref.selected'),

  mouseEnter() {
    if (this.get('hasPolymorphicColumns')) {
      this.set('isHovering', true);
    }
  },

  mouseLeave() {
    if (this.get('hasPolymorphicColumns')) {
      this.set('isHovering', false);
    }
  },

  click: function(e) {
    let clickedColumnIsUneditable = $(e.target).parents(
      'td.upf-datatable__column.upf-datatable__column--uneditable'
    ).length !== 0;
    if (this.get('onRowClickCallback') && !clickedColumnIsUneditable) {
      this.send('handleRowClickCallback');
    }
  },

  actions: {
    handleRowClickCallback() {
      this.sendAction(
        'action',
        this.get('onRowClickCallback'),
        this.get('ref')
      );
    }
  }
});

import Ember from 'ember';

const {
  Component,
  computed,
  $
} = Ember;

export default Component.extend({
  tagName: 'tr',
  classNames: ['upf-datatable__row'],
  classNameBindings: [
    'isHeaderRow:upf-datatable__row--header',
    'isSelected:upf-datatable__row--selected',
    'isHovering:upf-datatable__row--polymorphic'
  ],

  isSelected: computed.bool('ref.selected'),

  mouseEnter() {
    this.$().parentsUntil('.upf-datatable').find(
      '.upf-datatable__row--polymorphic'
    ).removeClass('upf-datatable__row--polymorphic');

    if (this.get('hasPolymorphicColumns')) {
      this.set('isHovering', true);
    }
  },

  mouseLeave() {
    if (this.get('hasPolymorphicColumns')) {
      this.set('isHovering', false);
    }
  },

  click: function(e) {
    let clickedColumnIsUneditable = $(e.target).parents(
      'td.upf-datatable__column.upf-datatable__column--uneditable'
    ).length !== 0;
    if (this.get('onRowClickCallback') && !clickedColumnIsUneditable) {
      this.send('handleRowClickCallback');
    }
  },

  actions: {
    handleRowClickCallback() {
      this.sendAction(
        'action',
        this.get('onRowClickCallback'),
        this.get('ref')
      );
    }
  }
});

fix polymorphic columns not disappearing after hover on tooltip