Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use standard approach of displaying filters for list tables #5174

Merged
merged 19 commits into from
Aug 3, 2022

Conversation

merkushin
Copy link
Member

@merkushin merkushin commented May 24, 2022

In this PR I'm trying to display filters as it is done for Posts. It helps to avoid issues with positioning of elements. However, I found we have some special cases (the standard approach is to hide filters on mobile, but we have some required filters that we have to display always).

Known Issues

  • I noticed that filters started adding unnecessary params like _wpnonce and _wp_http_referer to the query. These params we add to the form, the same on the Posts page. But when I submit filters for Posts it doesn't add mentioned params to the query. Can't find how it is filtered there. Any ideas? 🙏

Changes proposed in this Pull Request

  • Enclose the table, search box and filters into single form.

Testing instructions

  • Try to open Reports, Grading, Students pages.
  • Compare them to trunk. There might be changes, but they should be "positive" (i.e. it should look like in Pages now instead of "custom" positioning).
  • Check them with mobile dimensions.

Screenshot / Video

After
CleanShot 2022-05-29 at 17 11 32@2x
CleanShot 2022-05-29 at 17 11 51@2x
CleanShot 2022-05-24 at 10 52 01@2x
CleanShot 2022-05-24 at 10 52 19@2x
CleanShot 2022-05-24 at 10 52 47@2x
CleanShot 2022-05-24 at 10 53 02@2x
CleanShot 2022-05-29 at 17 29 55@2x

Before
CleanShot 2022-05-24 at 10 56 34@2x
CleanShot 2022-05-24 at 10 56 48@2x
CleanShot 2022-05-24 at 10 57 11@2x
CleanShot 2022-05-24 at 10 57 26@2x
CleanShot 2022-05-24 at 10 57 52@2x
CleanShot 2022-05-24 at 10 58 08@2x

@merkushin merkushin added this to the 4.4.3 milestone May 24, 2022
@merkushin merkushin requested a review from a team May 24, 2022 08:04
@merkushin merkushin self-assigned this May 24, 2022
@m1r0
Copy link
Member

m1r0 commented May 25, 2022

Looks pretty good so far! One thing that I think could be improved a bit is the grading filters. Maybe remove the space between the inputs and have a filter button that is disabled by default and enabled once a lesson is selected?

@merkushin merkushin marked this pull request as ready for review May 29, 2022 14:37
@dadish dadish modified the milestones: 4.4.3, 4.4.4 May 31, 2022
@alexsanford alexsanford modified the milestones: 4.5.1, 4.5.2 Jun 20, 2022
Copy link
Member

@m1r0 m1r0 left a comment

Choose a reason for hiding this comment

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

Hey Dmitry, thanks for improving this part! 🙏

I have a few comments (mostly visual), so here it goes:


I noticed that filters started adding unnecessary params like _wpnonce and _wp_http_referer to the query. These params we add to the form, the same on the Posts page. But when I submit filters for Posts it doesn't add mentioned params to the query. Can't find how it is filtered there. Any ideas?

WP core is removing the parameters and making a redirect, but I'm not entirely sure why, to be honest. 🙂 Maybe it's a security issue? How hard would it be to do the same?


On mobile (chrome), the search input is missaligned.

image
image


The height of the select (select2) inputs is different than the button. I think it was like this before, but could it be easily fixed at least for the filters?

image


On mobile, the Grading filter inputs/button look small compared to the other inputs/buttons. The "Reset filter" button also has too much white space at the end.

Grading filters:
image

Other filters:
image


On mobile, the course filter on Reports -> Lessons is a bit off compared to the filter button.

image


If you feel some of the mentions are not related to the current PR, I'm OK with opening separate issues for them. 👍

Comment on lines 413 to 422
foreach ( $this->query_args as $name => $value ) {
if ( 'filter_by_course_id' === $name || 'filter_type' === $name ) {
continue;
}
$this->courses_select( $courses, $selected_course, 'courses-select-filter', 'filter_by_course_id', __( 'Filter By Course', 'sensei-lms' ) );
?>
<button type="submit" id="filt" class="button action"><?php echo esc_html__( 'Filter', 'sensei-lms' ); ?></button>
</div>
</form>
echo '<input type="hidden" name="' . esc_attr( $name ) . '" value="' . esc_attr( $value ) . '">';
}
Copy link
Member

@m1r0 m1r0 Jul 12, 2022

Choose a reason for hiding this comment

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

Hm, this causes input duplication now that we have one form.

image

I've also noticed the same issue on the other screens.

image

I don't think it's causing issues, so I'm also ok with leaving it as-is for now.

@gabrielcaires gabrielcaires modified the milestones: 4.5.2, 5.0.0 Jul 14, 2022
@m1r0 m1r0 modified the milestones: 5.0.0, 4.5.3 Jul 18, 2022
@codecov
Copy link

codecov bot commented Jul 28, 2022

Codecov Report

Merging #5174 (65c173f) into trunk (d4a9a1e) will increase coverage by 1.69%.
The diff coverage is 1.60%.

Impacted file tree graph

@@             Coverage Diff              @@
##              trunk    #5174      +/-   ##
============================================
+ Coverage     42.86%   44.56%   +1.69%     
- Complexity     8687     8728      +41     
============================================
  Files           412      412              
  Lines         31053    31115      +62     
  Branches        234      234              
============================================
+ Hits          13311    13865     +554     
+ Misses        17569    17077     -492     
  Partials        173      173              
Impacted Files Coverage Δ
includes/admin/class-sensei-learners-main.php 4.96% <0.00%> (-0.09%) ⬇️
...cludes/class-sensei-analysis-lesson-list-table.php 0.00% <0.00%> (ø)
.../class-sensei-analysis-user-profile-list-table.php 0.00% <0.00%> (ø)
includes/class-sensei-analysis.php 8.90% <0.00%> (+0.24%) ⬆️
includes/class-sensei-course-structure.php 91.19% <ø> (ø)
includes/class-sensei-frontend.php 15.53% <0.00%> (+1.09%) ⬆️
includes/class-sensei-grading-main.php 0.00% <0.00%> (ø)
includes/class-sensei-grading.php 11.72% <0.00%> (-0.10%) ⬇️
includes/class-sensei-list-table.php 9.09% <0.00%> (-0.59%) ⬇️
includes/class-sensei-modules.php 34.18% <ø> (ø)
... and 27 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 132dda1...65c173f. Read the comment docs.

@merkushin
Copy link
Member Author

@m1r0

WP core is removing the parameters and making a redirect, but I'm not entirely sure why, to be honest. 🙂 Maybe it's a security issue? How hard would it be to do the same?

Haha, eventually, I know the answer. Yep, I think the main issue with these parameters is security. I suppose it is not safe to share your link with them, for example. I'm going to add the same redirect on our pages.

@dadish dadish modified the milestones: 4.6.0, 4.6.1 Aug 1, 2022
# Conflicts:
#	includes/reports/overview/list-table/class-sensei-reports-overview-list-table-abstract.php
We can't redirect from these pages as output has already started. At the same time, we don't have POST forms and we can omit those fields.
@merkushin
Copy link
Member Author

@m1r0 Could you take a look again?
I didn't fix styles for a filter from this screenshot. It is completely custom, I think it would be better to work on it in a separate task.
I think I didn't remove all duplications of hidden fields, but, as you noticed, it doesn't break anything.
The problem with nonce and referrer fields I solved by not displaying them :) We don't have POST forms on these pages, so I consider it safe. Unfortunately, we can't redirect on these pages, because output had already started by that time.

@Imran92 Feel free to join if you have some time :)

@m1r0
Copy link
Member

m1r0 commented Aug 1, 2022

The changes look good! Just one more thing I've noticed is the search on the reports working funky. Maybe it's related to the inputs?

Xu6i0h.mp4

@merkushin
Copy link
Member Author

Thanks @m1r0!
Fixed the issue here: 65c173f

For some reason, I started "filtering" a field instead of s (for search).
So it appeared with the previous value later on the page and caused that effect.

Copy link
Member

@m1r0 m1r0 left a comment

Choose a reason for hiding this comment

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

Looks good and works well. Thank you!

@merkushin merkushin merged commit 3bd0d78 into trunk Aug 3, 2022
@merkushin merkushin deleted the update/usage-of-list-table branch August 3, 2022 15:54
@fjorgemota
Copy link
Member

fjorgemota commented Sep 5, 2022

Just reporting out to keep note: I found that this PR caused the issue on #5504, which, curiously, only happens when there are no items on the list page (in this case, for the students page).

I'm still investigating the optimal way to fix this, but apparently, the root cause is that this PR opens a big <form> container (which has method="GET") on the table, as per 1cf3d7b, and this causes an issue because <form> tags can't be nested, so technically each time we open a <form> tag inside that tag, the opening that is ignored, but the end tag isn't (well, kinda like that), so that causes some annoying HTML validation errors (according to Firefox source code view), which then causes the error...

Just sharing because it might be another thing to consider when doing those sorts of refactorings, especially when considering HTML forms. :)

UPDATE: I sent PR #5583 to fix the new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants