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

Accept an array as valuePath #458

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion addon/classes/Column.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,15 @@ export default class Column extends EmberObject.extend({
cellComponent: null,

/**
* The path to the `value` for this column and row. Light Table will basically
* call `Ember.get(row, valuePath)` and pass that as `rawValue` to the cell.
* The cell then formats `rawValue` and makes it available as `value`.
*
* If you pass an array, the cell will also receive an array of values as
* `rawValue` (and `value`).
*
* @property valuePath
* @type {String}
* @type {String|String[]}
*/
valuePath: null,

Expand Down
2 changes: 1 addition & 1 deletion addon/templates/components/lt-row.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{#each columns as |column|}}
{{component (concat 'light-table/cells/' column.cellType) column row
table=table
rawValue=(get row column.valuePath)
rawValue=(collect row column.valuePath)
tableActions=tableActions}}
{{/each}}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"ember-cli-uglify": "^1.2.0",
"ember-cli-yuidoc": "0.8.8",
"ember-code-snippet": "^1.9.0",
"ember-collect-helper": "^0.1.2",
"ember-concurrency": "^0.8.6",
"ember-data": "^2.10.0",
"ember-disable-prototype-extensions": "^1.1.0",
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/components/lt-row-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { find } from 'ember-native-dom-helpers';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Table from 'ember-light-table';

moduleForComponent('lt-row', 'Integration | Component | lt row', {
integration: true
Expand All @@ -14,3 +15,35 @@ test('it renders', function(assert) {

assert.equal(find('*').textContent.trim(), '');
});

test('it accepts a string as `valuePath`', function(assert) {
this.set('columns', Table.createColumns([
{
valuePath: 'foo',
format(value) {
return `${typeof value} "${value}"`;
}
}
]));
this.set('row', { foo: 'hello' });

this.render(hbs`{{lt-row row columns}}`);

assert.equal(find('*').textContent.trim(), 'string "hello"');
});

test('it accepts an array as `valuePath`', function(assert) {
this.set('columns', Table.createColumns([
{
valuePath: ['foo', 'bar'],
format(values) {
return values.join(' ');
}
}
]));
this.set('row', { foo: 'hello', bar: 'world' });

this.render(hbs`{{lt-row row columns}}`);

assert.equal(find('*').textContent.trim(), 'hello world');
});
53 changes: 53 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,18 @@ babel-plugin-debug-macros@^0.1.1, babel-plugin-debug-macros@^0.1.10, babel-plugi
dependencies:
semver "^5.3.0"

babel-plugin-debug-macros@^0.1.11:
version "0.1.11"
resolved "https://registry.yarnpkg.com/babel-plugin-debug-macros/-/babel-plugin-debug-macros-0.1.11.tgz#6c562bf561fccd406ce14ab04f42c218cf956605"
dependencies:
semver "^5.3.0"

babel-plugin-ember-modules-api-polyfill@^1.4.1:
version "1.4.2"
resolved "https://registry.yarnpkg.com/babel-plugin-ember-modules-api-polyfill/-/babel-plugin-ember-modules-api-polyfill-1.4.2.tgz#e254f8ed0ba7cf32ea6a71c4770b3568a8577402"
dependencies:
ember-rfc176-data "^0.2.0"

babel-plugin-eval@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-eval/-/babel-plugin-eval-1.0.1.tgz#a2faed25ce6be69ade4bfec263f70169195950da"
Expand Down Expand Up @@ -720,6 +732,10 @@ babel-plugin-syntax-async-functions@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95"

babel-plugin-syntax-class-properties@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-class-properties/-/babel-plugin-syntax-class-properties-6.13.0.tgz#d7eb23b79a317f8543962c505b827c7d6cac27de"

babel-plugin-syntax-exponentiation-operator@^6.8.0:
version "6.13.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de"
Expand All @@ -736,6 +752,15 @@ babel-plugin-transform-async-to-generator@^6.22.0:
babel-plugin-syntax-async-functions "^6.8.0"
babel-runtime "^6.22.0"

babel-plugin-transform-class-properties@^6.24.1:
version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-class-properties/-/babel-plugin-transform-class-properties-6.24.1.tgz#6a79763ea61d33d36f37b611aa9def81a81b46ac"
dependencies:
babel-helper-function-name "^6.24.1"
babel-plugin-syntax-class-properties "^6.8.0"
babel-runtime "^6.22.0"
babel-template "^6.24.1"

babel-plugin-transform-es2015-arrow-functions@^6.22.0:
version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221"
Expand Down Expand Up @@ -2520,6 +2545,23 @@ ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.4, ember-cli-babel@^6.0.0-be
clone "^2.0.0"
ember-cli-version-checker "^2.0.0"

ember-cli-babel@^6.3.0:
version "6.6.0"
resolved "https://registry.yarnpkg.com/ember-cli-babel/-/ember-cli-babel-6.6.0.tgz#a8362bc44841bfdf89b389f3197f104d7ba526da"
dependencies:
amd-name-resolver "0.0.6"
babel-plugin-debug-macros "^0.1.11"
babel-plugin-ember-modules-api-polyfill "^1.4.1"
babel-plugin-transform-es2015-modules-amd "^6.24.0"
babel-polyfill "^6.16.0"
babel-preset-env "^1.5.1"
broccoli-babel-transpiler "^6.0.0"
broccoli-debug "^0.6.2"
broccoli-funnel "^1.0.0"
broccoli-source "^1.1.0"
clone "^2.0.0"
ember-cli-version-checker "^2.0.0"

ember-cli-broccoli-sane-watcher@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/ember-cli-broccoli-sane-watcher/-/ember-cli-broccoli-sane-watcher-2.0.4.tgz#f43f42f75b7509c212fb926cd9aea86ae19264c6"
Expand Down Expand Up @@ -2928,6 +2970,13 @@ ember-code-snippet@^1.9.0:
glob "^4.0.4"
highlight.js "^9.5.0"

ember-collect-helper@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/ember-collect-helper/-/ember-collect-helper-0.1.2.tgz#cc02411d89a1f7ccd1eaa4d7924c2a0ef72affb8"
dependencies:
babel-plugin-transform-class-properties "^6.24.1"
ember-cli-babel "^6.3.0"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ember-component-inbound-actions/-/ember-component-inbound-actions-1.0.1.tgz#9b354803c2d729f2d072999cc89ded69762e1dad"
Expand Down Expand Up @@ -3149,6 +3198,10 @@ ember-responsive@^2.0.4:
ember-cli-babel "^6.4.1"
ember-getowner-polyfill "^1.1.1"

ember-rfc176-data@^0.2.0:
version "0.2.5"
resolved "https://registry.yarnpkg.com/ember-rfc176-data/-/ember-rfc176-data-0.2.5.tgz#b26f62d9c03d3b02485153cf31137e089299839a"

ember-router-generator@^1.0.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/ember-router-generator/-/ember-router-generator-1.2.3.tgz#8ed2ca86ff323363120fc14278191e9e8f1315ee"
Expand Down