Problem/Motivation

Steps to reproduce:

  1. Login as admin
  2. Edit a view using the table style, that has sortable columns. For example, the "People" view at /admin/structure/views/view/user_admin_people
  3. Scroll down to the Preview section of the page
  4. Click a column header to try to sort by that column
  5. Expected behavior: The preview reloads, but sorted according to the column you chose. This was the behavior in D7, and in D8 before commit 20f1c993b6d76be0203138f2091952bc90a4bd61 .

    Observed behavior: You are sent to a page containing an AJAX response:
  6. Proposed resolution

    ???

    Remaining tasks

    Contributor tasks needed
    Task Novice task? Contributor instructions Complete?
    Create a patch Instructions
    Update the issue summary noting if allowed during the beta Instructions

    User interface changes

    ???

    API changes

    None.

    Data model changes

    None.

Comments

vasi created an issue. See original summary.

toniteof’s picture

Assigned: Unassigned » toniteof

I am working on it.

toniteof’s picture

Status: Active » Needs review
StatusFileSize
new748 bytes

URL path was changed.

Status: Needs review » Needs work

The last submitted patch, 3: 2575245-3.patch, failed testing.

toniteof’s picture

Status: Needs work » Needs review
StatusFileSize
new1.25 KB
new530 bytes

Updated FieldWebTest

dawehner’s picture

+++ b/core/modules/views/views.theme.inc
@@ -438,9 +438,7 @@ function template_preprocess_views_view_table(&$variables) {
         $link_options = array(
           'query' => $query,
         );
-        // It is ok to specify no URL path here as we will always reload the
-        // current page.
-        $url = new Url('<none>', [], $link_options);
+        $url = new Url('<current>', [], $link_options);

This would break cacheablity of pagers inside views blocks. I'd suggest to maybe check for the views preview instead?

toniteof’s picture

StatusFileSize
new966 bytes
new1.36 KB

If I understood correctly

dawehner’s picture

Status: Needs review » Needs work

IMHO you should use $view->live_preview

toniteof’s picture

thx for help

$route_name = !empty($view->live_preview) ? '<current>' : '<none>';
...
$url = new Url($route_name, [], $link_options);

Something like this?

dawehner’s picture

+1 and maybe even better put a quick line of documentation there, why we are doing that.

toniteof’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB
new1.3 KB
dawehner’s picture

Status: Needs review » Needs work
Issue tags: -Regression
+++ b/core/modules/views/views.theme.inc
@@ -397,6 +397,9 @@ function template_preprocess_views_view_table(&$variables) {
+  // If it is views live preview, route name must be specify as current.
+  $route_name = !empty($view->live_preview) ? '<current>' : '<none>';

Sorry, but this is not WHY, this line of documentation explains what the next line of code is doing.

Removing the regression tag because its pointless. A bug is a bug and stays a bug. All bugs are regressions relative to the expected behaviour. Almost

toniteof’s picture

So as for the why

  // In order not to break cacheability of pagers inside views block we check
  // if we are doing a live preview.
dawehner’s picture

I would go with the following which explains both:
// For the actual site we want to not render full URLs, because this would make pagers cacheable per URL, which is problematic in blocks, for example. For the actual live preview though the javascript relies on properly working URLs.

toniteof’s picture

Status: Needs work » Needs review
StatusFileSize
new1.36 KB
new833 bytes

-

thenchev’s picture

Thanks @toniteof
Tested it, works great for me.

@dawehner
Do you have anything to add or can we RTBC?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Not not really ...
I'll set this to RTBC because this part of the preview can just be tested properly with some JS, I believe.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Can we at least test the URLs in the output?

dawehner’s picture

Status: Needs review » Needs work

MH, I guess we can. We don't even necessarily need to fake up the ajax request.

toniteof’s picture

Status: Needs work » Needs review
StatusFileSize
new3.24 KB
new1.88 KB

Add tests.

dawehner’s picture

The test looks great in general.

  1. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -271,6 +271,32 @@ public function testPreviewError() {
    +  function testPreviewSortLink() {
    

    Let's add public there.

  2. +++ b/core/modules/views_ui/src/Tests/PreviewTest.php
    @@ -271,6 +271,32 @@ public function testPreviewError() {
    +    ¶
    ...
    +    ¶
    ...
    +    ¶
    ...
    +    ¶
    ...
    +    ¶
    ...
    +    ¶
    

    Let's remove the whitespace.

toniteof’s picture

StatusFileSize
new3.22 KB
new1.44 KB

Thanks @dawehner.

thenchev’s picture

Status: Needs review » Reviewed & tested by the community

I have nothing to add. Great job. I guess we can put it back to RTBC.

  • catch committed 64ad408 on
    Issue #2575245 by toniteof: Click-sorting broken in previews
    

  • catch committed 0e2097d on
    Issue #2575245 by toniteof: Click-sorting broken in previews
    
    (cherry...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.