Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,33 @@ namespace tf_paginated_view {
expect(_getPageCount()).to.equal(5);
});

it('sets all items to active=true when opened is true', () => {
expect(getItem('id0').hasAttribute('active')).to.be.true;
expect(getItem('id1').hasAttribute('active')).to.be.true;
});

it('sets all items to active=false when opened is false', async () => {
querySelector('button').click();
await flushAllP();

expect(getItem('id0').hasAttribute('active')).to.be.false;
expect(getItem('id1').hasAttribute('active')).to.be.false;
});

it('sets item to inactive when it is out of view', async () => {
// The DOM will be removed from document but it will be updated. Hold
// references to them here.
const item0 = getItem('id0');
const item1 = getItem('id1');

await goNext();

expect(item0.hasAttribute('active')).to.be.false;
expect(item1.hasAttribute('active')).to.be.false;
expect(getItem('id2').hasAttribute('active')).to.be.true;
expect(getItem('id3').hasAttribute('active')).to.be.true;
});

function _getPageCount(): number {
return view.$.view._pageCount;
}
Expand Down
6 changes: 5 additions & 1 deletion tensorboard/components/tf_paginated_view/test/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
category="[[category]]"
>
<template>
<span id$="[[item.id]]" number$="[[randomNumber]]">
<span
id$="[[item.id]]"
number$="[[randomNumber]]"
active$="[[active]]"
>
[[item.content]]
</span>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@
readOnly: true,
},

_contentActive: {
type: Boolean,
computed: '_computeContentActive(opened)',
},

disablePagination: {
type: Boolean,
value: false,
Expand Down Expand Up @@ -393,6 +398,10 @@
this._setOpened(!this.opened);
},

_computeContentActive() {
return this.opened;
},

_onPaneRenderedChanged(newRendered, oldRendered) {
if (newRendered && newRendered !== oldRendered) {
// Force dom-if render without waiting for one rAF.
Expand Down
31 changes: 27 additions & 4 deletions tensorboard/components/tf_paginated_view/tf-dom-repeat.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@
value: 'item',
},

/**
* Whether all stamped items are active or not.
* @protected
*/
_contentActive: {
type: Boolean,
value: true,
},

_domBootstrapped: {
type: Boolean,
value: false,
Expand Down Expand Up @@ -97,6 +106,7 @@
observers: [
'_bootstrapDom(_itemsRendered, isAttached)',
'_updateDom(_renderedItems.*, _domBootstrapped)',
'_updateActive(_contentActive)',
'_trimCache(_cacheSize)',
],

Expand Down Expand Up @@ -135,7 +145,7 @@
parentModel: true,
instanceProps: {
[this.as]: true,
active: true,
active: this._contentActive,
},
forwardHostProp: function(prop, value) {
this._renderedTemplateInst.forEach((inst) => {
Expand Down Expand Up @@ -166,6 +176,14 @@
this._domBootstrapped = true;
},

_updateActive() {
if (!this._domBootstrapped) return;

Array.from(this._renderedTemplateInst.values()).forEach((inst) => {
inst.notifyPath('active', this._contentActive);
});
},

_updateDom(event) {
if (!this._domBootstrapped) return;
// These are uninteresting.
Expand Down Expand Up @@ -193,7 +211,7 @@
if (this._renderedTemplateInst.has(key)) {
this._renderedTemplateInst
.get(key)
.notifyPath(this.as, event.value, true /* fromAbove */);
.notifyPath(this.as, event.value);
} else {
console.warn(
`Expected '${key}' to exist in the DOM but ` +
Expand All @@ -213,8 +231,11 @@
if (this._lruCachedItems.has(key)) {
fragOrEl = this._lruCachedItems.get(key);
this._lruCachedItems.delete(key);
this._renderedTemplateInst
.get(key)
.notifyPath('active', this._contentActive);
} else {
const prop = {[this.as]: item, active: true};
const prop = {[this.as]: item, active: this._contentActive};
const inst = new this._ctor(prop);
fragOrEl = inst.root;
this._renderedTemplateInst.set(key, inst);
Expand All @@ -234,7 +255,9 @@

_removeItem(item, node) {
Polymer.dom(node.parentNode).removeChild(node);
this._lruCachedItems.set(this._getItemKey(item), node);
const key = this._getItemKey(item);
this._lruCachedItems.set(key, node);
this._renderedTemplateInst.get(key).notifyPath('active', false);
},

_trimCache() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ <h3>No scalar data was found.</h3>
>
<template>
<tf-scalar-card
active="[[active]"
active="[[active]]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…was this just like active="true" always?

data-to-load="[[item.series]]"
ignore-y-outliers="[[_ignoreYOutliers]]"
multi-experiments="[[_getMultiExperiments(dataSelection)]]"
Expand Down