Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon native classes #814

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9a0584b
Refactor lt-scrollable class
Aug 6, 2022
ab3d2d9
Refactor spanned-row class
Aug 6, 2022
73f7af7
Refactor lt-infinity component
Aug 6, 2022
714bad9
Refactor lt-scaffolding-row component
Aug 6, 2022
3e64f02
Refactor lt-column-resizer class
Aug 6, 2022
37c3699
Convert lt-body to angle brackets
Aug 6, 2022
b633757
Clean up some computes column and row classes
Aug 6, 2022
d7d7220
Convert base column and cell components
Aug 6, 2022
8e13c5d
Remove style attribute binding from table-header mixin
Aug 6, 2022
f8c0830
Make lt-foot and lt-head tagless
Aug 6, 2022
7a91442
Convert table-header mixin to component
Aug 6, 2022
83efb51
Convert draggable-column mixin to a component
Aug 6, 2022
cc60b60
Change eslint ember mixin rules from off to warn
Aug 6, 2022
92348aa
Refactor lt-row to native class
Aug 6, 2022
6cd2150
fix(table-header): Add setter for renderInPlace
Aug 6, 2022
1731105
fix(table-header): Add optional chaining to getters
Aug 6, 2022
c71fd4d
refactor(light-table): Remove noop closure actions
Aug 6, 2022
e8b236d
Convert light-table to native class
Aug 6, 2022
e80058c
lt-body: Remove noop closure action
Aug 6, 2022
b9f89a2
Convert lt-body to native class
Aug 6, 2022
0a2f6bc
Clean up template actions
Aug 7, 2022
30c5307
Repace @observes decorator with addObserver/removeObserver
Aug 7, 2022
b9e10b4
Add prefix to table-header methods for clarity
Aug 9, 2022
fa043e6
Remove column drag, drop and resizer noop stubs
Aug 9, 2022
75939cf
Update addon/components/cells/base.js
maxwondercorn Aug 16, 2022
9bcfbc2
Update addon/components/draggable-column.js
maxwondercorn Aug 16, 2022
65d6b1f
Update addon/components/draggable-column.js
maxwondercorn Aug 16, 2022
d3526d3
Update addon/components/draggable-column.js
maxwondercorn Aug 16, 2022
a49d94e
Update addon/components/lt-column-resizer.js
maxwondercorn Aug 16, 2022
8f0b019
Track resizeOnDrag and isResizing
Aug 16, 2022
fa1dbd6
Rremove super on drag functions
Aug 16, 2022
790c137
Add test for column alignment
Aug 17, 2022
fc0ce24
Fixed 'is-sorted' class/Made isSorted a computed property
Aug 17, 2022
f8f2619
Convert remaining function checks to optional chaining
Aug 18, 2022
8efdc50
Clean up naming of optional passed actions
Sep 1, 2022
507d3ed
Add @copmputed's to properties
Sep 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module.exports = {
'ember/no-observers': 'off',
'ember/no-jquery': 'error',
'ember/no-get': 'warn',
'ember/no-mixins': 'off',
'ember/no-new-mixins': 'off',
'ember/no-mixins': 'error',
'ember/no-new-mixins': 'error',
'ember/require-tagless-components': 'off',
},

Expand Down
4 changes: 2 additions & 2 deletions addon/classes/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ export default class Column extends EmberObject.extend({
* @type {String}
* @private
*/
columnId: computed(function () {
get columnId() {
return guidFor(this);
}).readOnly(),
},

/**
* True if `hidden` or `responsiveHidden` is true.
Expand Down
5 changes: 2 additions & 3 deletions addon/classes/Row.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ObjectProxy from '@ember/object/proxy';
import { computed } from '@ember/object';
import { guidFor } from '@ember/object/internals';
import classic from 'ember-classic-decorator';

Expand Down Expand Up @@ -75,7 +74,7 @@ export default class Row extends ObjectProxy.extend({
* @type {String}
* @readOnly
*/
rowId: computed(function () {
get rowId() {
return guidFor(this);
}).readOnly(),
},
}) {}
63 changes: 37 additions & 26 deletions addon/components/cells/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Component from '@ember/component';
import classic from 'ember-classic-decorator';
import {
classNames,
attributeBindings,
classNameBindings,
tagName,
} from '@ember-decorators/component';
import { computed } from '@ember/object';
import { readOnly } from '@ember/object/computed';
import Component from '@ember/component';
import { htmlSafe } from '@ember/template';

/**
Expand All @@ -13,82 +19,87 @@ import { htmlSafe } from '@ember/template';
* @class Base Cell
*/

export default Component.extend({
tagName: 'td',
classNames: ['lt-cell'],
attributeBindings: ['style'],
classNameBindings: ['align', 'isSorted', 'column.cellClassNames'],

enableScaffolding: false,
@classic
@tagName('td')
@classNames('lt-cell')
@attributeBindings('style')
@classNameBindings('align', 'isSorted', 'column.cellClassNames')
export default class Base extends Component {
enableScaffolding = false;

isSorted: readOnly('column.sorted'),
get isSorted() {
return this.column.isSorted;
}

style: computed('enableScaffolding', 'column.width', function () {
@computed('enableScaffolding', 'column.width')
get style() {
let column = this.column;
let columnWidth = column.get('width');

if (this.enableScaffolding || !column) {
return;
return undefined;
}

// For performance reasons, it's more interesting to bypass cssStyleify
// since it leads to a lot of garbage collections
// when displaying many cells
return columnWidth ? htmlSafe(`width: ${columnWidth};`) : null;
}),
}

align: computed('column.align', function () {
@computed('column.align')
get align() {
return `align-${this.column.align}`;
maxwondercorn marked this conversation as resolved.
Show resolved Hide resolved
}),
}

/**
* @property table
* @type {Table}
*/
table: null,
table = null;

/**
* @property column
* @type {Column}
*/
column: null,
column = null;

/**
* @property row
* @type {Row}
*/
row: null,
row = null;

/**
* @property tableActions
* @type {Object}
*/
tableActions: null,
tableActions = null;

/**
* @property extra
* @type {Object}
*/
extra: null,
extra = null;

/**
* @property rawValue
* @type {Mixed}
*/
rawValue: null,
rawValue = null;

/**
* @property value
* @type {Mixed}
*/
value: computed('column.format', 'rawValue', function () {
let rawValue = this.rawValue;
let format = this.column.format;
@computed('column.format', 'rawValue')
get value() {
const rawValue = this.rawValue;
const format = this.column.format;

if (format && typeof format === 'function') {
return format.call(this, rawValue);
}

return rawValue;
}),
});
}
}
2 changes: 1 addition & 1 deletion addon/components/columns/base.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
@table={{this.table}}
@resizeOnDrag={{this.resizeOnDrag}}
@isResizing={{mut this.isResizing}}
@onColumnResized={{action this.onColumnResized this.column}}
@onColumnResized={{fn this.columnResized this.column}}
maxwondercorn marked this conversation as resolved.
Show resolved Hide resolved
/>
{{/if}}
132 changes: 86 additions & 46 deletions addon/components/columns/base.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import DraggableColumn from '../draggable-column';
import classic from 'ember-classic-decorator';
import {
classNames,
attributeBindings,
classNameBindings,
tagName,
} from '@ember-decorators/component';
import { set } from '@ember/object';
import Component from '@ember/component';
import { computed } from '@ember/object';
import { oneWay, readOnly } from '@ember/object/computed';
import { isEmpty } from '@ember/utils';
import DraggableColumnMixin from 'ember-light-table/mixins/draggable-column';
import cssStyleify from 'ember-light-table/utils/css-styleify';

import { readOnly } from '@ember/object/computed';

/**
* @module Light Table
* @submodule Column Types
Expand All @@ -16,80 +23,108 @@ import cssStyleify from 'ember-light-table/utils/css-styleify';
* @class Base Column
*/

export default Component.extend(DraggableColumnMixin, {
tagName: 'th',
classNames: ['lt-column'],
attributeBindings: ['style', 'colspan', 'rowspan'],
classNameBindings: [
'align',
'isGroupColumn:lt-group-column',
'isHideable',
'isSortable',
'isSorted',
'isResizable',
'isResizing',
'isDraggable',
'column.classNames',
],

isGroupColumn: readOnly('column.isGroupColumn'),
isSortable: readOnly('column.sortable'),
isSorted: readOnly('column.sorted'),
isHideable: readOnly('column.hideable'),
isResizable: readOnly('column.resizable'),
isDraggable: readOnly('column.draggable'),
isResizing: false,

style: computed('column.width', function () {
@classic
@tagName('th')
@classNames('lt-column')
@attributeBindings('style', 'colspan', 'rowspan')
@classNameBindings(
'align',
'isGroupColumn:lt-group-column',
'isHideable',
'isSortable',
'isSorted',
'isResizable',
'isResizing',
'isDraggable',
'column.classNames'
)
export default class Base extends DraggableColumn {
@computed('column.isGroupColumn')
get isGroupColumn() {
return this.column.isGroupColumn;
}

@readOnly('column.sortable')
get isSortable() {
return this.column.sortable;
}

@computed('column.sorted')
get isSorted() {
return this.column.sorted;
}

@computed('column.hideable')
get isHideable() {
return this.column.hideable;
maxwondercorn marked this conversation as resolved.
Show resolved Hide resolved
}

@computed('column.resizable')
get isResizable() {
return this.column.resizable;
}

@computed('column.draggable')
get isDraggable() {
return this.column.draggable;
}

isResizing = false;

get style() {
return cssStyleify(this.column.getProperties(['width']));
}),
}

align: computed('column.align', function () {
@computed('column.align')
get align() {
return `align-${this.column.align}`;
}),
}

/**
* @property label
* @type {String}
*/
label: oneWay('column.label'),
@computed('column.label')
get label() {
return this.column.label;
}

/**
* @property table
* @type {Table}
*/
table: null,
table = null;

/**
* @property column
* @type {Column}
*/
column: null,
column = null;

/**
* @property tableActions
* @type {Object}
*/
tableActions: null,
tableActions = null;

/**
* @property extra
* @type {Object}
*/
extra: null,
extra = null;

/**
* @property sortIcons
* @type {Object}
*/
sortIcons: null,
sortIcons = null;

/**
* @property sortIconProperty
* @type {String|null}
* @private
*/
sortIconProperty: computed('column.{sortable,sorted,ascending}', function () {
@computed('column.{sortable,sorted,ascending}', function () {
let sorted = this.column.sorted;

if (sorted) {
Expand All @@ -99,22 +134,26 @@ export default Component.extend(DraggableColumnMixin, {

let sortable = this.column.sortable;
return sortable ? 'iconSortable' : null;
}),
})
sortIconProperty;

/**
* @property colspan
* @type {Number}
*/
colspan: computed('column', 'column.visibleSubColumns.[]', function () {
let subColumns = this.column.visibleSubColumns;
return !isEmpty(subColumns) ? subColumns.length : 1;
}),
@computed('column', 'column.visibleSubColumns.[]', {
get() {
let subColumns = this.column.visibleSubColumns;
return !isEmpty(subColumns) ? subColumns.length : 1;
},
})
colspan;

/**
* @property rowspan
* @type {Number}
*/
rowspan: computed('_rowspan', 'column.visibleSubColumns.[]', {
@computed('_rowspan', 'column.visibleSubColumns.[]', {
get() {
if (this._rowspan) {
return this._rowspan;
Expand All @@ -127,5 +166,6 @@ export default Component.extend(DraggableColumnMixin, {
set(key, value) {
return set(this, '_rowspan', value);
},
}),
});
})
rowspan;
}
Loading