Merge changes I47bf9593,Id38b7edd

* changes:
  Supply commit message editor with a storage key
  Upgrade gr-editable-content with alert
This commit is contained in:
Kasper Nilsson 2018-01-04 00:06:48 +00:00 committed by Gerrit Code Review
commit 325bad9dbb
4 changed files with 27 additions and 4 deletions

View File

@ -391,6 +391,7 @@ limitations under the License.
<gr-editable-content id="commitMessageEditor"
editing="[[_editingCommitMessage]]"
content="{{_latestCommitMessage}}"
storage-key="[[_computeCommitMessageKey(_change._number, _change.current_revision)]]"
remove-zero-width-space>
<gr-linked-text pre
content="[[_latestCommitMessage]]"

View File

@ -1348,5 +1348,9 @@
break;
}
},
_computeCommitMessageKey(number, revision) {
return `c${number}_rev${revision}`;
},
});
})();

View File

@ -14,6 +14,7 @@
(function() {
'use strict';
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
Polymer({
@ -31,6 +32,12 @@
* @event editable-content-cancel
*/
/**
* Fired when content is restored from storage.
*
* @event show-alert
*/
properties: {
content: {
notify: true,
@ -81,10 +88,16 @@
let content;
if (this.storageKey) {
content = this.$.storage.getEditableContentItem(this.storageKey);
const storedContent =
this.$.storage.getEditableContentItem(this.storageKey);
if (storedContent && storedContent.message) {
content = storedContent.message;
this.dispatchEvent(new CustomEvent('show-alert',
{detail: {message: RESTORED_MESSAGE}, bubbles: true}));
}
}
if (!content) {
content = this.content;
content = this.content || '';
}
// TODO(wyatta) switch linkify sequence, see issue 5526.

View File

@ -100,25 +100,30 @@ limitations under the License.
});
suite('storageKey and related behavior', () => {
let dispatchSpy;
setup(() => {
element.content = 'current content';
element.storageKey = 'test';
dispatchSpy = sandbox.spy(element, 'dispatchEvent');
});
test('editing toggled to true, has stored data', () => {
sandbox.stub(element.$.storage, 'getEditableContentItem')
.returns('stored content');
.returns({message: 'stored content'});
element.editing = true;
assert.equal(element._newContent, 'stored content');
assert.isTrue(dispatchSpy.called);
assert.equal(dispatchSpy.lastCall.args[0].type, 'show-alert');
});
test('editing toggled to true, has no stored data', () => {
sandbox.stub(element.$.storage, 'getEditableContentItem')
.returns('');
.returns({});
element.editing = true;
assert.equal(element._newContent, 'current content');
assert.isFalse(dispatchSpy.called);
});
test('edits are cached', () => {