|
| 1 | +import Component from '@glimmer/component'; |
| 2 | +import { tracked } from '@glimmer/tracking'; |
| 3 | +import { action, computed } from '@ember/object'; |
| 4 | +import { isArray } from '@ember/array'; |
| 5 | + |
| 6 | +export default class TableCellPodContentActionsComponent extends Component { |
| 7 | + constructor(owner, { column, row }) { |
| 8 | + super(...arguments); |
| 9 | + if (isArray(column.actions)) { |
| 10 | + this.actions = column.actions; |
| 11 | + } |
| 12 | + |
| 13 | + if (typeof column.actions === 'function') { |
| 14 | + this.actions = column.actions(row); |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | + @tracked actions = []; |
| 19 | + @tracked defaultButtonText = 'Actions'; |
| 20 | + |
| 21 | + @computed('args.column.ddButtonText', 'defaultButtonText') get buttonText() { |
| 22 | + const { ddButtonText } = this.args.column; |
| 23 | + |
| 24 | + if (ddButtonText === undefined) { |
| 25 | + return this.defaultButtonText; |
| 26 | + } |
| 27 | + |
| 28 | + if (ddButtonText === false) { |
| 29 | + return null; |
| 30 | + } |
| 31 | + |
| 32 | + return ddButtonText; |
| 33 | + } |
| 34 | + |
| 35 | + @action setupComponent(dropdownWrapperNode) { |
| 36 | + const tableCellNode = this.getOwnerTableCell(dropdownWrapperNode); |
| 37 | + tableCellNode.style.overflow = 'visible'; |
| 38 | + } |
| 39 | + |
| 40 | + @action getOwnerTableCell(dropdownWrapperNode) { |
| 41 | + while (dropdownWrapperNode) { |
| 42 | + dropdownWrapperNode = dropdownWrapperNode.parentNode; |
| 43 | + |
| 44 | + if (dropdownWrapperNode.tagName.toLowerCase() === 'td') { |
| 45 | + return dropdownWrapperNode; |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + return undefined; |
| 50 | + } |
| 51 | + |
| 52 | + @action onDropdownItemClick(columnAction, row, dd) { |
| 53 | + if (typeof dd?.actions?.close === 'function') { |
| 54 | + dd.actions.close(); |
| 55 | + } |
| 56 | + |
| 57 | + if (typeof columnAction?.fn === 'function') { |
| 58 | + columnAction.fn(row); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + @action calculatePosition(trigger) { |
| 63 | + let { width } = trigger.getBoundingClientRect(); |
| 64 | + |
| 65 | + let style = { |
| 66 | + marginTop: '0px', |
| 67 | + right: width + 3, |
| 68 | + top: 0, |
| 69 | + }; |
| 70 | + |
| 71 | + return { style }; |
| 72 | + } |
| 73 | +} |
0 commit comments