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

Remove mapBy and filterBy #2600

Merged
merged 2 commits into from
Oct 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion app/components/object-inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class ObjectInspector extends Component {
if (nested.length === 0) {
return '';
}
return `.${nested.mapBy('property').join('.')}`;
return `.${nested.map((item) => item.property).join('.')}`;
}

get isNested() {
Expand Down
4 changes: 2 additions & 2 deletions app/libs/resizable-columns.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default class {
let saved = this.storage.getItem(this.getStorageKey());
if (saved && saved.columnVisibility) {
let savedIds = keys(saved.columnVisibility).sort();
let schemaIds = this.columnSchema.mapBy('id').sort();
let schemaIds = this.columnSchema.map((col) => col.id).sort();
if (!compareArrays(savedIds, schemaIds)) {
// Clear saved items
this.storage.removeItem(this.getStorageKey());
Expand Down Expand Up @@ -221,7 +221,7 @@ export default class {
let diff = this.tableWidth - totalWidth;
while (diff > 0) {
columns
.filterBy('visible')
.filter((col) => col.visible)
.sortBy('width')
.forEach((column) => {
if (diff > 0) {
Expand Down
52 changes: 28 additions & 24 deletions tests/unit/resizable-columns-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,53 +188,57 @@ module('Unit | Lib | ResizableColumns', function (hooks) {
resizableColumns.build();

assert.deepEqual(
resizableColumns.columns.filterBy('visible').mapBy('id'),
resizableColumns.columns
.filter((col) => col.visible)
.map((col) => col.id),
['1', '2'],
'shows/hides according to schema',
);
assert.deepEqual(resizableColumns.getColumnVisibility().mapBy('visible'), [
true,
true,
false,
]);
assert.deepEqual(
resizableColumns.getColumnVisibility().map((col) => col.visible),
[true, true, false],
);

resizableColumns.toggleVisibility('3');
assert.deepEqual(
resizableColumns.columns.filterBy('visible').mapBy('id'),
resizableColumns.columns
.filter((col) => col.visible)
.map((col) => col.id),
['1', '2', '3'],
'toggles the third column correctly',
);
assert.deepEqual(resizableColumns.getColumnVisibility().mapBy('visible'), [
true,
true,
true,
]);
assert.deepEqual(
resizableColumns.getColumnVisibility().map((col) => col.visible),
[true, true, true],
);

resizableColumns.toggleVisibility('1');
assert.deepEqual(
resizableColumns.columns.filterBy('visible').mapBy('id'),
resizableColumns.columns
.filter((col) => col.visible)
.map((col) => col.id),
['2', '3'],
'toggles the first column correctly',
);
assert.deepEqual(resizableColumns.getColumnVisibility().mapBy('visible'), [
false,
true,
true,
]);
assert.deepEqual(
resizableColumns.getColumnVisibility().map((col) => col.visible),
[false, true, true],
);

// Confirm correct caching
resizableColumns = new ResizableColumns(this.options);
resizableColumns.build();
assert.deepEqual(
resizableColumns.columns.filterBy('visible').mapBy('id'),
resizableColumns.columns
.filter((col) => col.visible)
.map((col) => col.id),
['2', '3'],
'caching overrides schema visibility settings',
);
assert.deepEqual(resizableColumns.getColumnVisibility().mapBy('visible'), [
false,
true,
true,
]);
assert.deepEqual(
resizableColumns.getColumnVisibility().map((col) => col.visible),
[false, true, true],
);
});

test("resets cache correctly if schema doesn't match cache", function (assert) {
Expand Down
Loading