94 Commits

Author SHA1 Message Date
Wyatt Allen
4f09a3f50c Merge "Restore confirm discard dialog for draft comments" 2017-12-08 20:04:56 +00:00
Kasper Nilsson
7f4e9d1762 Merge "Create a robot-comment-controls plugin endpoint" 2017-12-06 23:34:52 +00:00
Viktar Donich
3a12ebf262 Create a robot-comment-controls plugin endpoint
This is needed to add "Not important" link by a plugin.

Change-Id: Id8ef0a372e7111c12631cf41aafce9ac6a33e7f0
2017-12-06 14:02:52 -08:00
Kasper Nilsson
ed4e5f1f88 Modify resolved checkbox to call save()
Previously, the resolved checkbox called _saveDraft(). Using save()
instead disables the comment while waiting for the save request to
return.

Bug: Issue 7933
Change-Id: I44ce88094b271aa46a726a75aa4eb283b29f1a35
2017-12-06 13:39:52 -08:00
Kasper Nilsson
bc6f579528 Restore confirm discard dialog for draft comments
Draft comments with message text should have a confirm dialog when
discarded to prevent accidental data loss.

This is a regression introduced by I0dae814.

Bug: Issue 7900
Change-Id: Ibd9829ccf36a551445282e5cb0d37c1a6df46ab9
2017-12-05 14:33:13 -08:00
Kasper Nilsson
46a6c8eca2 Allow toggling resolved outside editing state
A recent change modified some comment editing UX. As a consequence, the
save button disabled state was erroneously based entirely on whether or
not the comment message had changed.

With this change:
- Save disabled state on a comment takes into account resolved state
- The resolved checkbox is always visible on an expanded draft comment
- When the resolved checkbox is modified on a non-`editing` draft
  comment, it is saved immediately

Bug: Issue 6023
Change-Id: I40b0b280129e5a76c13e38c97525f91a8e56482d
2017-12-05 13:20:22 -08:00
Becky Siegel
6de1489147 Refactor gr-button styling
A few changes:
- Utilize mixins within gr-button internally, so less styles have to be
  overridden by elements implementing their own button styles.
- All buttons have a hover background color, which is 12% black
  overlayed on top of its current background color.

Bug: Issue 7894
Change-Id: I4f2879aa0232912267bbf1290a1c800d024099a6
2017-12-01 16:15:19 -08:00
Kasper Nilsson
80ca288da5 Delete draft comment when saved with empty text
Recently, the comment editing UX was changed (the discard button was
removed from the editing view). This (obviously) made it impossible to
discard a draft comment whilst editing it.

Editing a comment, clearing the text, and saving now removes the
comment.

Bug: Issue 7832
Change-Id: I0dae814b9ce2e7a5b57530f839c708e59c215341
2017-11-27 16:37:11 -08:00
Kasper Nilsson
d66fb88099 Fix bad vertical align in collapsed comments
Bug: Issue 7762
Change-Id: I3b79b054a99b7ba5caf6b0ec9f48abdf6cdee0b7
2017-11-20 13:54:11 -08:00
Paladox none
1b3ea22cf5 PolyGerrit: Replace content with slot part 2
This change makes the following replacement:

<content select=".header"> replace it with
the slot equivalent.

Change-Id: Icc68576a3b44559775103163febd429194802981
2017-11-15 17:36:37 +00:00
Kasper Nilsson
6a25b28830 Merge "Clean up comment editing UX" 2017-11-09 21:50:01 +00:00
Kasper Nilsson
998e4cf5b7 Clean up comment editing UX
The removal of the 'Discard' button from comments in the editing state
complicated the UX of the 'Cancel' button a bit.

Previously:
- Discard deleted the draft completely.
- Cancel cancelled whatever edits were made, and reverted to the prior
  draft state. Cancel was also hidden on new drafts.

Currently:
- Cancel cancels whatever edits were made, and reverts to whatever edit
  was last stored.

This behavior is problematic, for a few reasons:
- Due to some vestigial code, the actual value of the comment's message
  (not just the buffer value '_messageText') was updated any time the
  draft comment was edited. This was done to prevent multiple drafts
  from being created on the same thread -- that issue was made obsolete
  by the removal of buttons from individual comments, and their
  consolidation to the thread level.
- If a user cancels a draft, then restarts it (having their text
  repopulated from localstorage), then cancels it again, the draft is
  rendered as a saved draft comment with the localstorage value, despite
  having never been saved at all.

So, with this change:
- Cancel cancels whatever edits were made.
- If a user tries to add a draft in the same place...
  - ...and the draft has been saved on the server, the textarea is
    prepopulated with the value from the comment received from the
    server.
  - ...and the draft has NOT been saved on the server, the textarea is
    rehydrated from localstorage.

This UX makes sense because...
- Case 1 occurs when a user clicks "Edit" on an existing draft comment -
  thus expecting to edit the content shown in the UI.
- Case 2 occurs when a user cancels a draft that they started
  constructing, but did not save -- thus there is no suggestion of any
  prepopulated value by the UI, _and_ the case in which a draft was
  erroneously cancelled during editing can be solved.

Bug: Issue 7709
Change-Id: Iacf9a91fbb0226aba3a518f56edd61f28c15a8ef
2017-11-09 11:38:59 -08:00
Kasper Nilsson
786438b7a6 Re-style comment removal button on diff comments
Some modifications to the styling of paper-button within gr-button
overrode a few deliberate styling decisions made in the delete comment
button (namely, color and padding). This change moves those CSS props
inside a styling mixin so that they are properly applied, and overload
the defaults from inside gr-button.

Change-Id: Ifdfc0a3959f4131e1bb86e8b66d70db2fde79077
2017-11-09 09:18:16 -08:00
Kasper Nilsson
060b612810 Remove hidden attribute from cancel button
The hidden attribute was erroneously left on the cancel button in diff
comments, causing it to not show up by default.

It showed up upon editing an existing draft because the hideOnPublished
CSS overrode the hack for the [hidden] attribute.

In addition, the buggy behavior was actually enforced by a buggy test --
it asserted that the button was not visible, but was labelled as "Cancel
is visible".

Bug: Issue 7664
Change-Id: I9e08c33fc4adf0f1465a52055a3308210625ffde
2017-11-06 17:08:02 -08:00
Wyatt Allen
5eab49acc0 Show comment saving progress indicator inside comments themselves
Bug: Issue 7596
Change-Id: I194bce633c8d746c24f71fc7f4bbdf2b87e5b883
2017-11-03 21:00:56 +00:00
Kasper Nilsson
9725fac3b7 Hide "Discard" button while editing comment
Bug: Issue 7491
Change-Id: I3514fd3f2ba63f138cd6eb52d32034d1ec8e47b0
2017-11-01 12:15:19 -07:00
Wyatt Allen
d563a713d6 Only erase unsaved drafts after save request succeeds
Unsaved diff drafts are kept in localstorage so they are not lost if
they do not get saved (for example, if the browser crashes). However,
this stored copy of the comment is cleared when the save request is
started, not after it succeeds. As such, if the save request fails (for
example, if the user credentials are invalid), the comment can be truly
lost.

With this change, the localstorage copy is only cleared after save
success. If the request fails, it allows the error message to appear
rather than showing a misleading "All comments saved" toast.

Bug: issue 7289
Change-Id: Id5c8144ecccec50de35f83af616b4e4915b62b5c
2017-10-27 12:56:04 -07:00
Wyatt Allen
fb3733ccb9 Prevent save while disabled
The [Save] button cannot be clicked when the comment is disabled (via
`pointer-events: disabled;` in the CSS), and clicking the [Save] button
results in setting disabled to true. However, it is possible to click
save again before the style is applied. It's also possible to trigger
the button using a non-pointer-event (such as a key). With this change,
an extra check is added to the [Save] button's click handler to prevent
clicks when the component is disabled.

Bug: Issue 6972
Change-Id: I16117af31c5e7b5d7d49a025eebb690d8802b64b
2017-10-24 16:34:10 -07:00
Wyatt Allen
489e2680a7 Show confirmation dialog before destructively discarding draft comments
The discard confirm dialog is added alongside the delete confirm dialog
and the dialog opening/closing code is refactored to work on either. The
confirm discard dialog only appears if the draft message is savable.

Feature: Issue 6984
Change-Id: I6d88a8734fa7736f685796790e02437b10c81f00
2017-10-19 13:11:54 -07:00
Becky Siegel
7eb2707811 Update order of buttons in gr-diff-comment
Because the order of buttons switched on most modals (cancel on left,
save on right) this updates the button order in gr-diff-comment for
consistency. Discard is moved to the left of 'save' and 'edit'.'

Change-Id: Ifa08976b77d99bb32fb1d6388f38843ad9e065fa
2017-10-16 09:43:23 -07:00
Becky Siegel
d1f95e97ae Update a few gr-button styles
- Diff preferences
  - Use link button, align right
- diff comment
  - use link button, modify colors

Change-Id: Ibdd232b1f30d2d0d3e36ce708afbd35470f6da44
2017-10-12 00:52:20 +00:00
Kasper Nilsson
aafba229bb Make comment removal element less obtrusive
This change moves the admin-only commment up above the comment next to
the date and styles it more subtly, saving vertical space.

Bug: Issue 7274
Change-Id: Id3095a5439e33055eec3191f6e31d17bb8640615
2017-09-23 00:48:28 +00:00
Kasper Nilsson
15cdbd4bd1 Invert comment action alignments
It makes the most sense (at least for left-to-right language speaking
locales) to have the most final and most destructive UI elements read
last, as interacting with those is the most permanent, and requires the
full context of the information in the element.

In diff comments, actions like 'Save' and 'Discard' (which affect the
entire comment) were on the left, whereas toggling the resolved state
was on the right. This change flips these alignments.

Bug: Issue 5924
Change-Id: Id00e19d662a983fad071df0fb866052b2001beb4
2017-09-22 13:39:47 -07:00
Wyatt Allen
494e7d42b7 Show toast messages for storing diff comment drafts
With this change, toast messages show when diff comments are being saved
and notify when saving is complete, even when the diff view is no-longer
loaded. This signal is intended to encourage users to write diff
comments and feel free to navigate away to view other parts of a change.

With this change, new toast messages are able to replace existing toast
messages.

Feature: Issue 6970
Change-Id: I5973673d85c73b14794cb5e5b21327dd0c27ec1d
2017-09-17 15:53:32 -07:00
Becky Siegel
1a09820022 Update bold fonts to Roboto Medium
Bold fonts were inconsistent across platforms and new design specs use
Roboto Medium instead, so switching all currently bold fonts to use
that.

Change-Id: Ibfc5ffc3fc33517acb85acc0194215b4d7864cae
2017-09-08 16:06:35 -07:00
Becky Siegel
8d92d53db5 Annotation updates
Change-Id: I146f76b9dcc1a92e18acec01481ad280fb431868
2017-08-12 11:49:52 -07:00
Becky Siegel
03690330ff Do not show overflow-y in gr-editable-content
Because of the way iron-autogrow-textarea works, There will never be
a need to have a vertical scroll bar, as the text area expands
accordingly.

In cases where a horizontal scrollbar appeared (due to long lines of
text), the height of the textarea shrank just enough for a vertical
scrollbar to be added as well. There also appeared to be some browser
quirks in which the scroll bars jumped around when they shouldn't.
In order to prevent this from happening, hide overflow-y.

Additionally, add box-sizing: border-box to all iron-autogrow-textarea
instances, so that scrollbars appear correctly in shadow dom.

Bug: Issue 6500
Change-Id: I28f3b47d656a246decd693f637040748ec4fd3a0
2017-07-24 18:13:13 +00:00
Becky Siegel
59f2b4ce83 Show helper text only when hovering over draft icon, not text
Previously, when you clicked 'reply' on a comment, the cursor would
automatically be hovering the 'DRAFT' text. This change makes it so
that only the ⓘ  is hoverable, but not the text itself.

Bug: Issue 5810
Change-Id: I0be8d1e777bcfe68fd4b192290c711fcb1430c3a
2017-07-06 21:12:08 +00:00
Kasper Nilsson
076adcd4f8 Fix errors introduced by eslint^4.0.0
The release of eslint 4 introduced some breaking changes -- a full
upgrade guide can be found here [1].

In this change, the "no-useless-escape" and "indent" rules are disabled,
"indent" being replaced with "indent-legacy" to minimize breaks due to
lint. Also, extra spaces before comments and other assorted new lint
issues are corrected.

The long-term plan is to move away from the deprecated "indent-legacy"
rule and also reenable the "no-useless-escape" rule, but for now we
want to minimize breakages and not affect PG developer velocity.

[1] http://eslint.org/docs/user-guide/migrating-to-4.0.0

Change-Id: I8044256c95e3fe3f94fa9acc7922600908f8a0f4
2017-07-05 19:34:14 +00:00
Kasper Nilsson
9fee82ef7d Migrate gr-diff-comment to iron-a11y-keys
Bug: Issue 4198
Change-Id: I68ca64a9b0ef5cc9e83f19521529971d260fda55
2017-06-22 10:32:05 -07:00
Wyatt Allen
27a7a367b1 Merge "Add polygerrit-ui/app/test/common-test-setup.html" 2017-06-06 00:40:15 +00:00
Becky Siegel
a4fc6de235 Fix various selectors for shadow dom
https://www.polymer-project.org/2.0/docs/devguide/style-shadow-dom

Bug: Issue 6372
Change-Id: I1918e86b31d4fa02b67d1b0e5ef9ae8f48877257
2017-06-05 22:42:22 +00:00
Mike Samuel
e07c4b2ea1 Add polygerrit-ui/app/test/common-test-setup.html
This is a partial roll-forward of c/106190

This replaces all loads of iron-test-helpers with a load of a file
that wraps it, and adds that file to test files that do not currently
load iron-test-helpers.

A future CL will also install polymer-resin via common-test-helpers.html.

I tested by running

$ WCT_ARGS="-l chrome" ./polygerrit-ui/app/run_test.sh

Change-Id: Ifb3cd2c8db13d724f57e56e7e78045470d103a43
2017-06-05 22:10:12 +00:00
Becky Siegel
b159a7f5cc Update styles for shadow dom
- Create a shared style module that is included in every custom element
- Add the shared style module to each existing element

Change-Id: I1ee382955afe4ff630548a6640e7c4d03688849d
2017-06-02 14:54:03 -07:00
Wyatt Allen
c601abccc3 Revert "Polygerrit now loads polymer-resin"
This reverts commit 0895052c01ac5ac657a9763d2ad9967d9ae55c18.

Reason for revert: issue 6387

Change-Id: I14e00addeab53606952aa3ea2d45a74eac7a9d8a
2017-06-02 09:37:37 -07:00
Wyatt Allen
2f0df3d255 Merge "Polygerrit now loads polymer-resin" 2017-06-01 18:36:38 +00:00
Wyatt Allen
3312df1741 Use monospaced font when composing diff comment
Bug: Issue 6349
Change-Id: Iaacd1472d1718e7e67e5b57f5eda05eed9bac78b
2017-05-31 11:46:10 -07:00
Mike Samuel
0895052c01 Polygerrit now loads polymer-resin
polymer-resin intercepts polymer property assignments
before they reach XSS-vulnerable sinks like `href="..."`
and text nodes in `<script>` elements.

This follows the instructions in WORKSPACE for adding a new bower
dependency with kaspern's tweak to use the dependency in a rule so
that it's found.  //lib/js/bower_components.bzl has already been
rolled-back per those instructions.

The license is the polymer license as can be seen at
https://github.com/Polymer/polymer-resin/blob/master/LICENSE though
I'm not sure that //tools/js/bower2bazel.py recognizes it as such.

Docs for the added component are available at
https://github.com/Polymer/polymer-resin/blob/master/README.md
https://github.com/Polymer/polymer-resin/blob/master/getting-started.md

With this change, when I introduce an XSS vulnerability as below,
polymer-resin intercepts and stops it.

Patch that introduces a strawman vulnerability.

--- a/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js
+++ b/polygerrit-ui/app/elements/core/gr-main-header/gr-main-header.js
@@ -55,6 +55,10 @@
         url: '/q/status:abandoned',
         name: 'Abandoned',
       },
+      {
+        url: location.hash.replace(/^#/, '') || 'http://example.com/#fragment_echoed_here',
+        name: 'XSS Me',
+      },
     ],
   }];

---

Address kaspern's and paladox's comments.

---

Undo version bumps for bower dependencies.

---

Change Soy index template to parallel app/index.html.

---

update polymer-resin to version 1.1.1-beta

----

Load polymer-resin into polygerrit-ui/**/*_test.html

After this, I ran the tests with
  -l chrome
  -l firefox

I ran a handful of tests with -p and observed that the
console shows "initResin" is called before test cases start
executing.

These changes were done programmaticly by running the script below
(approximately) thus:
```
gerrit/ $ cd polygerrit-ui/app
app/ $ find . -name \*test.html | xargs perl hack-tests.pl
```

```
use strict;

sub removeResin($) {
  my $s = $_[0];
  $s =~ s@<link rel="import" href="[^"]*/polymer-resin/[^"]*"[^>]*>\n?@@;
  $s =~ s@<script src="[^"]*/polymer-resin/[^"]*"></script>\n?@@;
  $s =~ s@<script>\s*security\.polymer_resin.*?</script>\n?@@s;
  return $s;
}

for my $f (@ARGV) {
  next if $f =~ m@/bower_components/|/node_modules/@;

  system('git', 'checkout', $f);
  print "$f\n";

  my @lines = ();
  open(IN, "<$f") or die "$f: $!";
  my $maxLineOfMatch = 0;
  while (<IN>) {
    push(@lines, $_);
    # Put a marker after core loading directives.
    $maxLineOfMatch = scalar(@lines)
      if m@/webcomponentsjs/|/polymer[.]html\b|/browser[.]js@;
  }
  close(IN) or die "$f: $!";

  die "$f missing loading directives" unless $maxLineOfMatch;

  # Given ./a/b/c/my_test.html, $pathToRoot is "../../.."
  # assuming no non-leading . or .. components in the path from find.
  my $pathToRoot = $f;
  $pathToRoot =~ s@^\.\/@@;
  $pathToRoot =~ s@^(.*?/)?app/@@;
  $pathToRoot =~ s@\/[^\/]*$@@;
  $pathToRoot =~ s@[^/]+@..@g;

  my $nLines = scalar(@lines);
  open(OUT, ">$f") or die "$f: $!";

  # Output the lines up to the last polymer-resin dependency
  # loaded explicitly by this test.
  my $before = join '', @lines[0..($maxLineOfMatch - 1)];
  $before = removeResin($before);
  print OUT "$before";

  # Dump out the lines that load polymer-resin and configure it for
  # polygerrit.
  if (1) {
      print OUT qq'<link rel="import" href="$pathToRoot/bower_components/polymer-resin/standalone/polymer-resin-debug.html"/>
<script>
security.polymer_resin.install({allowedIdentifierPrefixes: [\'\']});
</script>
    ';
  }

  # Emit any remaining lines.
  my $after = join '', @lines[$maxLineOfMatch..$#lines];
  $after = removeResin($after);
  $after =~ s/^\n*//;
  print OUT "$after";

  close(OUT) or die "$f: $!";
}
```

---

update polymer-resin to version 1.2.1-beta

---

update Soy index template to new style polymer-resin initialization

----

fix lint warnings

----

Load test/common-test-setup.html into *_test.html

Instead of inserting instructions to load and initialize polymer-resin into
every test file, add a common-test-setup.html that does that and also fold
iron-test-helpers loading into it.

----

imported files do not need to load webcomponentsjs

Change-Id: I71221c36ed8a0fe7f8720c1064a2fcc9555bb8df
2017-05-30 23:16:09 -04:00
Becky Siegel
99625b5a6c Add gr-autogrow-textarea to gr-diff-comment
This replaces iron-autogrow-textarea so that the diff comments can have
emoji support.

Change-Id: I8bfa31b789604f28aca0ff28dc5c0836afdb6005
2017-05-25 10:08:33 -07:00
Viktar Donich
e16c279304 Fix gr-diff-comment_test in Firefox, Safari
Change-Id: I0d11ffa48c254622cbc86ec7c0ce265f24212859
2017-05-23 21:05:33 +00:00
Becky Siegel
64cede2a14 Fix delete button again
In the previous fix, the function was not called and since it was
the function that set the class to 'hidden' it did not hide.

Change-Id: Ic8f908802cb515086860f20e2c82d0ddd06c0278
2017-05-19 23:08:16 +00:00
Becky Siegel
94cf669dc0 Do not show delete button for admins when comment is a draft
There was a formatting issue caused by delete buttons in a draft change.
It really does not make sense for the button to be there for drafts
anyway. This change hides the delete button for admins on draft changes.

Bug: Issue 6257
Change-Id: I236eff9db1f0ca76ed658f3048132c9c675ee407
2017-05-18 13:15:09 -07:00
Kasper Nilsson
fbad19e18e Catch-all fix for merged linter errors
Bug: Issue 6179
Change-Id: I436b6dbd88e83b4d901d5446a0c7900678be157d
2017-05-17 17:17:25 -07:00
Kasper Nilsson
a4c24de33c ES6ify /gr-diff-comment/*
Bug: Issue 6179
Change-Id: Id103711e6a7ca24785a301dbb8341bb0c8f63617
2017-05-17 19:29:04 +00:00
Viktar Donich
9f047389f4 UI for comments deletion by admins
This change depends on API implemented in Change 105052.

Feature: Issue 4644
Change-Id: I91137aaa69eef419e08c8a568cef9350d8a1448b
2017-05-17 10:29:08 -07:00
Becky Siegel
10a7126d9b Fix draft storage issue
Previously, there was a race condition in which erasing a draft comment
could occur prior to the updated version of the comment getting saved.
When this happened, if the user replied to the same thread, their old
draft would be pre-populated in the new reply.

This change cancels the 'store' debouncer when erasing a draft comment,
to avoid this race condition.

Bug: Issue 6141
Change-Id: I11a646acf01b1ac986c587e1e8fdb4fd7efc25b7
2017-05-16 15:13:52 -07:00
Viktar Donich
29e1ce5e84 Collection of prospective test flake fixes
Potentially related:
https://github.com/Polymer/web-component-tester/issues/505

Bug: Issue 5792
Change-Id: I9ab6e8e40d9811dd52906335426764c052907609
2017-03-30 13:46:58 -07:00
Becky Siegel
0727efa3d1 Implement isOnParent as functions rather than an attribute on comments
Previously, the rest api interface set '__isOnParent' for comments.
When comments were added, the property from the comment thread
'isOnParent' was passed as a property. When the draft was saved, it was
expecting '__isOnParent' rather than 'isOnParent' and this caused
comments to show up on the wrong side after saved/refreshed, because
'__isOnParent' was undefined.

Instead of changing to either '__isOnParent' which would be strange to
pass as an attribute or 'isOnParent' which would look like it came from
the api directly, this change introduces isOnParent functions so that
translation doesn't need to be done with the API.

Bug: Issue 5831
Change-Id: I3b849ba5878275cda0a39638626a12bd51341a29
2017-03-21 14:57:58 -07:00
Wyatt Allen
81ef082667 Merge "Reduce confusion between side and commentSide" 2017-03-16 00:17:47 +00:00
Becky Siegel
cd2d4232f1 Reduce confusion between side and commentSide
Use '__isOnParent' as a boolean in place if 'side' ('PARENT vs
'REVISION').  In doing so, it's necessary to convert to/from 'side'
whenever interacting with the REST API.

Change-Id: Ic023c9be1969597e4b9c73a51cfed9f5eb9bc23e
2017-03-15 13:50:21 -07:00