Skip to content

Commit

Permalink
Search routes (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
nummi authored and RobbieTheWagner committed May 2, 2018
1 parent 42cc850 commit a42e649
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
12 changes: 9 additions & 3 deletions app/controllers/route-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import Controller, { inject as controller } from '@ember/controller';
import checkCurrentRoute from "ember-inspector/utils/check-current-route";
import searchMatch from 'ember-inspector/utils/search-match';

export default Controller.extend({
application: controller(),
Expand All @@ -10,23 +11,28 @@ export default Controller.extend({

currentRoute: null,
hideRoutes: alias('options.hideRoutes'),
searchValue: '',

options: {
hideRoutes: false
},

model: computed(() => []),

filtered: computed('model.[]', 'options.hideRoutes', 'currentRoute', function() {
filtered: computed('model.[]', 'options.hideRoutes', 'currentRoute', 'searchValue', function() {
return this.get('model').filter(routeItem => {
let currentRoute = this.get('currentRoute');
let hideRoutes = this.get('options.hideRoutes');

if (!searchMatch(routeItem.value.name, this.get('searchValue'))) {
return false;
}

if (hideRoutes && currentRoute) {
return checkCurrentRoute(currentRoute, routeItem.value.name);
} else {
return true;
}

return true;
});
}),

Expand Down
6 changes: 6 additions & 0 deletions app/templates/route-tree-toolbar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
Current Route only
</label>
</div>

<div class="divider"></div>

<div class="toolbar__search js-filter-views">
{{search-field value=searchValue}}
</div>
</div>
26 changes: 25 additions & 1 deletion tests/acceptance/route-tree-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { visit, find, findAll, click, triggerEvent } from '@ember/test-helpers';
import { visit, fillIn, find, findAll, click, triggerEvent } from '@ember/test-helpers';
import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
Expand Down Expand Up @@ -191,6 +191,30 @@ module('Route Tree Tab', function(hooks) {
assert.deepEqual(isCurrent, [true, true, true, false], 'Current route is bound');
});

test("It should filter the tree using the search text", async function(assert) {
port.reopen({
send(name/*, message*/) {
if (name === 'route:getTree') {
this.trigger('route:routeTree', { tree: routeTree });
} else if (name === 'route:getCurrentRoute') {
this.trigger('route:currentRoute', { name: 'post.edit' });
}
}
});

await visit('route-tree');
let routeNodes = findAll('.js-route-tree-item');
assert.equal(routeNodes.length, 4);

await fillIn('.js-filter-views input', 'edit');
routeNodes = findAll('.js-route-tree-item');
assert.equal(routeNodes.length, 1);

await click('.js-search-field-clear-button');
routeNodes = findAll('.js-route-tree-item');
assert.equal(routeNodes.length, 4);
});

test("Hiding non current route", async function(assert) {
port.reopen({
send(name/*, message*/) {
Expand Down

0 comments on commit a42e649

Please sign in to comment.