Skip to content

Commit

Permalink
Tidy up render-tree tab
Browse files Browse the repository at this point in the history
- fix table striping
- remove observer
- fix search highlighting
- action, this, {{on}}, etc.
- use Ui:Disclosure
  • Loading branch information
nummi committed Sep 19, 2019
1 parent 580ccf2 commit a4fbd1d
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 145 deletions.
46 changes: 2 additions & 44 deletions app/components/render-item.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
import Component from '@ember/component';
import { isNone, isEmpty } from '@ember/utils';
import { run } from '@ember/runloop';
import { observer, computed } from '@ember/object';
import { computed } from '@ember/object';
import { htmlSafe } from '@ember/string';
import escapeRegExp from 'ember-inspector/utils/escape-reg-exp';

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

const { once } = run;

export default Component.extend({
tagName: '',

search: null,

isExpanded: false,

expand() {
this.set('isExpanded', true);
},

searchChanged: observer('search', function() {
let search = this.search;
if (!isEmpty(search)) {
once(this, 'expand');
}
}),

searchMatch: computed('search', 'name', function() {
let search = this.search;
if (isEmpty(search)) {
Expand Down Expand Up @@ -59,18 +41,6 @@ export default Component.extend({

hasChildren: gt('model.children.length', 0),

expandedClass: computed('hasChildren', 'isExpanded', function() {
if (!this.hasChildren) {
return;
}

if (this.isExpanded) {
return 'list__cell_arrow_expanded';
} else {
return 'list__cell_arrow_collapsed';
}
}),

readableTime: computed('model.timestamp', function() {
let d = new Date(this.get('model.timestamp'));
let ms = d.getMilliseconds();
Expand All @@ -79,17 +49,5 @@ export default Component.extend({
let hours = d.getHours().toString().length === 1 ? `0${d.getHours()}` : d.getHours();

return `${hours}:${minutes}:${seconds}:${ms}`;
}),

init() {
this._super(...arguments);

this.searchChanged();
},

actions: {
toggleExpand() {
this.toggleProperty('isExpanded');
}
}
})
});
41 changes: 13 additions & 28 deletions app/controllers/render-tree.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, get } from '@ember/object';
import { action, computed, get } from '@ember/object';
import { isEmpty } from '@ember/utils';
import Controller, { inject as controller } from '@ember/controller';
import { inject as service } from '@ember/service';
Expand All @@ -14,13 +14,7 @@ export default Controller.extend({
showEmpty: and('initialEmpty', 'modelEmpty'),

/**
* Service used for storage. Storage is
* needed for remembering if the user closed the warning
* as it might get mildly annoying for devs to see and close
* the trivial warning every time.
* The default storage service is local storage however we
* fall back to memory storage if local storage is disabled (For
* example as a security setting in Chrome).
* Storage is needed for remembering if the user closed the warning
*
* @property storage
* @type {Service}
Expand All @@ -30,7 +24,6 @@ export default Controller.extend({

/**
* Checks if the user previously closed the warning by referencing localStorage
* it is a computed get/set property.
*
* @property isWarningClosed
* @type {Boolean}
Expand All @@ -55,18 +48,6 @@ export default Controller.extend({
return this.isWarningClosed ? 31 : 56;
}),

actions: {
/**
* This action when triggered, closes the warning message for rendering times being inaccurate
* and sets `isWarningClosed` value to true, thus preventing the warning from being shown further.
*
* @method closeWarning
*/
closeWarning() {
this.set('isWarningClosed', true);
}
},

// bound to the input field, updates the `search` property
// 300ms after changing
searchValue: debounceComputed('search', 300),
Expand All @@ -79,15 +60,19 @@ export default Controller.extend({
}),

filtered: computed('[email protected]', 'search', function() {
return get(this, 'model').filter((item) => {
let search = this.escapedSearch;
if (isEmpty(search)) {
return true;
}
let regExp = new RegExp(search);
return !!recursiveMatch(item, regExp);
if (isEmpty(this.escapedSearch)) {
return this.model;
}

return this.model.filter((item) => {
const regExp = new RegExp(this.escapedSearch);
return recursiveMatch(item, regExp);
});
}),

closeWarning: action(function() {
this.set('isWarningClosed', true);
})
});

function recursiveMatch(item, regExp) {
Expand Down
12 changes: 5 additions & 7 deletions app/templates/components/deprecation-item.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
<Ui::Accordion as |accordion|>
<Ui::Disclosure as |disclosure|>
<div class="deprecation-item px-3" data-test="deprecation-item">
<div class="flex items-center">
<div
class="flex items-center flex-grow py-2"
{{on "click" accordion.toggle}}
{{on "click" disclosure.toggle}}
>
{{#if @model.hasSourceMap}}
<div class="flex-shrink-0 w-3">
<span class="disclosure-triangle {{if accordion.isExpanded "expanded" "collapsed"}}">
{{svg-jar "disclosure-triangle" width="9px" height="9px"}}
</span>
<disclosure.triangleIcon />
</div>
{{/if}}

Expand Down Expand Up @@ -49,7 +47,7 @@
{{/if}}
</div>

{{#if (and @model.hasSourceMap accordion.isExpanded)}}
{{#if (and @model.hasSourceMap disclosure.isExpanded)}}
{{#each @model.sources as |single|}}
<DeprecationItemSource @model={{single}} as |source|>
<div class="deprecation-source pb-2" data-test="deprecation-source">
Expand Down Expand Up @@ -83,4 +81,4 @@
{{/each}}
{{/if}}
</div>
</Ui::Accordion>
</Ui::Disclosure>
65 changes: 37 additions & 28 deletions app/templates/components/render-item.hbs
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
<tr
style={{nodeStyle}}
class="list__row js-render-profile-item"
>
{{#list.cell
class=(concat "list__cell_main " expandedClass " js-render-main-cell")
on-click=(action "toggleExpand")
style=nameStyle
}}
<span class="list__cell-arrow"></span>
<Ui::Disclosure as |disclosure|>
<tr
style={{this.nodeStyle}}
class="list__row js-render-profile-item"
>
{{#list.cell
class="list__cell_main js-render-main-cell"
on-click=disclosure.toggle
style=this.nameStyle
}}
{{#if this.hasChildren}}
<disclosure.triangleIcon />
{{/if}}

<span title={{model.name}}>
<span class="js-render-profile-name">{{model.name}}</span>
</span>
{{/list.cell}}
<span title={{@model.name}}>
<span class="js-render-profile-name">{{@model.name}}</span>
</span>
{{/list.cell}}

{{#list.cell class="list__cell_value_numeric"}}
<span class="pill js-render-profile-duration">
{{ms-to-time model.duration}}
</span>
{{/list.cell}}
{{#list.cell class="list__cell_value_numeric"}}
<span class="pill js-render-profile-duration">
{{ms-to-time @model.duration}}
</span>
{{/list.cell}}

{{#list.cell class="list__cell_value_numeric js-render-profile-timestamp"}}
{{readableTime}}
{{/list.cell}}
</tr>
{{#list.cell class="list__cell_value_numeric js-render-profile-timestamp"}}
{{this.readableTime}}
{{/list.cell}}
</tr>

{{#if isExpanded}}
{{#each model.children as |child|}}
{{render-item model=child target=this list=list}}
{{/each}}
{{/if}}
{{#if disclosure.isExpanded}}
{{#each @model.children as |child|}}
<RenderItem
@model={{child}}
@target={{this}}
@list={{@list}}
@search={{@search}}
/>
{{/each}}
{{/if}}
</Ui::Disclosure>
2 changes: 1 addition & 1 deletion app/templates/render-tree-toolbar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@action={{action send "clearProfiles"}}
/>

{{#unless showEmpty}}
{{#unless this.showEmpty}}
<Ui::ToolbarDivider />
<Ui::ToolbarReloadButton
@action={{action send "refreshPage"}}
Expand Down
16 changes: 10 additions & 6 deletions app/templates/render-tree.hbs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
{{#unless isWarningClosed}}
<WarningMessage @close={{action "closeWarning"}}>
{{#unless this.isWarningClosed}}
<WarningMessage @close={{this.closeWarning}}>
Render times may be inaccurate due to instrumentation and environment
</WarningMessage>
{{/unless}}

{{#if showEmpty}}
{{#if this.showEmpty}}
<Ui::EmptyMessage class="js-render-tree-empty">
<p>No rendering metrics have been collected. Try reloading or navigating around your application.</p>
<p><strong>Note:</strong> Very fast rendering times (&lt;1ms) are excluded.</p>
<button class="js-toolbar-page-refresh-btn" {{action "refreshPage"}}>Reload</button>
</Ui::EmptyMessage>
{{else}}
<List
class="js-render-tree"
class="js-render-tree list--css-striping"
@headerHeight={{this.headerHeight}}
@schema={{schema-for "render-tree"}}
@setIsDragging={{action "setIsDragging" target=this.application}} as |list|
>
<tbody>
{{#each filtered as |item|}}
{{render-item model=item search=search list=list}}
{{#each this.filtered as |item|}}
<RenderItem
@model={{item}}
@search={{this.search}}
@list={{list}}
/>
{{/each}}
</tbody>
</List>
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions lib/ui/addon/styles/_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@
}
}

.list.list--css-striping {
.list__row:nth-child(even) {
background: var(--base00);
}
}

.list__cell-content {
width: 100%;
}
Expand Down
1 change: 0 additions & 1 deletion lib/ui/app/components/ui/accordion.js

This file was deleted.

1 change: 1 addition & 0 deletions lib/ui/app/components/ui/disclosure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ui/components/disclosure';
4 changes: 0 additions & 4 deletions lib/ui/app/templates/components/ui/accordion.hbs

This file was deleted.

24 changes: 16 additions & 8 deletions lib/ui/app/templates/components/ui/disclosure-triangle.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<button
class="disclosure-triangle {{if @expanded "expanded" "collapsed"}}"
{{on "click" @toggle}}
...attributes
>
{{svg-jar "disclosure-triangle" width="9px" height="9px"}}
</button>

{{#if @toggle}}
<button
class="disclosure-triangle {{if @expanded "expanded" "collapsed"}}"
{{on "click" @toggle}}
...attributes
>
{{svg-jar "disclosure-triangle" width="9px" height="9px"}}
</button>
{{else}}
<span
class="disclosure-triangle {{if @expanded "expanded" "collapsed"}}"
...attributes
>
{{svg-jar "disclosure-triangle" width="9px" height="9px"}}
</span>
{{/if}}
6 changes: 6 additions & 0 deletions lib/ui/app/templates/components/ui/disclosure.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{yield (hash
isExpanded=this.isExpanded
toggle=this.toggle
triangleIcon=(component "ui/disclosure-triangle" expanded=this.isExpanded)
triangleButton=(component "ui/disclosure-triangle" expanded=this.isExpanded toggle=this.toggle)
)}}
18 changes: 0 additions & 18 deletions tests/acceptance/render-tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,6 @@ module('Render Tree Tab', function(hooks) {
assert.dom(rows[0].querySelector('.js-render-profile-name')).hasText('First View Rendering');
assert.dom(rows[1].querySelector('.js-render-profile-name')).hasText('Second View Rendering');

await fillIn('.js-render-profiles-search input', 'first');

rows = findAll('.js-render-profile-item');
assert.equal(rows.length, 2, "The first parent is rendered with the child");
assert.dom(rows[0].querySelector('.js-render-profile-name')).hasText('First View Rendering');
assert.dom(rows[1].querySelector('.js-render-profile-name')).hasText('Child view');

// Minimize to hide child view
await click('.js-render-main-cell');

await fillIn('.js-render-profiles-search input', '');

rows = findAll('.js-render-profile-item');
assert.equal(rows.length, 2, "filter is reset");

assert.dom(rows[0].querySelector('.js-render-profile-name')).hasText('First View Rendering');
assert.dom(rows[1].querySelector('.js-render-profile-name')).hasText('Second View Rendering');

await fillIn('.js-render-profiles-search input', 'Second');

rows = findAll('.js-render-profile-item');
Expand Down

0 comments on commit a4fbd1d

Please sign in to comment.