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

Browser/Plugin improvements: counting nodes, ordering and Nodes section at top/bottom #1575

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rNoz
Copy link

@rNoz rNoz commented Nov 30, 2024

What am I doing?

Providing some tweaks to Sabre\DAV\Browser\Plugin.php:

  • showing the number of nodes
  • ordering by last modified datetime and then by displayPath.
  • Nodes section is displayed at the bottom if the number of nodes are greater than 20 (considering UX).

Example with this PR:

  1. When accessing a collection with more than 20 nodes (e.g., calendar)

image

  1. When traversing collections with <=20 nodes, so it is comfortable and quick to jump from collections as it is the most used action in these types of resources.

image

  1. When there are no nodes, there is no "Nodes (0)" section generated. Zoomed out:

image

  1. When accessing a collection with more than 20 nodes (e.g., addressbook). Zoomed out:

image

Why?

More context: issue

I have added a test to evaluate the new compareNodes protected function, as I didn't see a way to easily replace lastmodified values for a set of files and just parsing the table rows of the response body. So I am using reflection to verify all the possibilities when comparing.

Originally, I had another function (see below) to evaluate specifically the counting of nodes, but I think it will be fine just using what is provided by the parent::setUp() + setUp (3 nodes).

public function testCollectionNodes()
{
    $dir = $this->server->tree->getNodeForPath('dir2');
    $dir->createDirectory('subdir2');
    $dir->createDirectory('subdir1');
    $dir->createFile('file2');
    $dir->createFile('file1');

    $request = new HTTP\Request('GET', '/dir2');
    $this->server->httpRequest = ($request);
    $this->server->exec();

    $body = $this->response->getBodyAsString();
    self::assertTrue(false !== strpos($body, 'Nodes (4)'), $body);
    self::assertTrue(false !== strpos($body, '<a href="/dir2/subdir1/">'));
}

All passing:

> phpunit --configuration tests/phpunit.xml tests
PHPUnit 9.6.21 by Sebastian Bergmann and contributors.

....SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS   61 / 1646 (  3%)
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS............  122 / 1646 (  7%)
.............................................................  183 / 1646 ( 11%)
.............................................................  244 / 1646 ( 14%)
.............................................................  305 / 1646 ( 18%)
.............................................................  366 / 1646 ( 22%)
.............................................................  427 / 1646 ( 25%)
.............................................................  488 / 1646 ( 29%)
.............................................................  549 / 1646 ( 33%)
.............................................................  610 / 1646 ( 37%)
.............................................................  671 / 1646 ( 40%)
.........SSSSSSSSSSSSSSSSSSSSSSSSSSSS........................  732 / 1646 ( 44%)
.............................................................  793 / 1646 ( 48%)
.................................................SSSS........  854 / 1646 ( 51%)
.............................................................  915 / 1646 ( 55%)
.............................................................  976 / 1646 ( 59%)
........................................SSSSSSSSSSSSSSSS..... 1037 / 1646 ( 63%)
............................................................. 1098 / 1646 ( 66%)
..........................................SSSSSSSSSSSSSSSSSS. 1159 / 1646 ( 70%)
............................................................. 1220 / 1646 ( 74%)
............................................................. 1281 / 1646 ( 77%)
............................................................. 1342 / 1646 ( 81%)
............................................................. 1403 / 1646 ( 85%)
............................................................. 1464 / 1646 ( 88%)
............................................................. 1525 / 1646 ( 92%)
......SSSSSSSSSSSSSSSSSSSSSSSSSS............................. 1586 / 1646 ( 96%)
............................................................  1646 / 1646 (100%)

Time: 00:06.069, Memory: 48.00 MB

OK, but incomplete, skipped, or risky tests!
Tests: 1646, Assertions: 2915, Skipped: 198.

Let me know if something else is necessary ;)

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 96.36364% with 2 lines in your changes missing coverage. Please review.

Project coverage is 97.22%. Comparing base (ed901a9) to head (f2d6f75).
Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
lib/DAV/Browser/Plugin.php 96.36% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1575      +/-   ##
============================================
- Coverage     97.23%   97.22%   -0.01%     
- Complexity     2836     2843       +7     
============================================
  Files           175      175              
  Lines          9028     9043      +15     
============================================
+ Hits           8778     8792      +14     
- Misses          250      251       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phil-davis
Copy link
Contributor

@rNoz php-cs-fixer has some minor formatting required.

https://github.com/sabre-io/dav/actions/runs/12096265416/job/34109861744?pr=1575

You can run it locally composer cs-fixer to see what it does, then commit the changes and push.

Comment on lines +316 to +318
// If there are nodes and they are more than the max number to show at the top of the page
if ($numSubNodes) {
$html .= $this->generateNodesSection($subNodes, $numSubNodes);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test case for when there are more than 20 nodes?
That will exercise this code, and the test can check that the Nodes section comes down the bottom of the HTML.

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.

2 participants