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

Package search #259

Merged
merged 11 commits into from
Sep 8, 2020
Merged

Package search #259

merged 11 commits into from
Sep 8, 2020

Conversation

giggsey
Copy link
Contributor

@giggsey giggsey commented Sep 6, 2020

Just want a bit of feedback/advice before I continue on this:

  • I'm thinking just an initial basic package name search for the time being, could be expanded to description (and maybe tags?) later
  • Currently, the pagination is done as two different calls to the PackageQuery class - to avoid having to add search functionality for each, could a paginator bundle be used instead? (I come from a Laravel background where it's a core part of the framework)
  • Design wise, I'm thinking that the search bar could be on the right of the title bar, to the left of 'Add package'
    image
  • Side note: could the hard-coded 20 per page be moved to a user setting?

Response::isNotModified() doesn't need to be wrapped in the if statement, as it'll remove the content (even for a StreamedResponse)
* repman-io/master:
  Create CODE_OF_CONDUCT.md (#258)
  Release 0.6.0 (#254)
  Update dependencies (symfony to 5.1.5) (#257)
  Add queue for downloader to limit concurrent requests (#253)
  Add missing config for doctrine migrations 3.0 (#252)
  Update Symfony to 5.1 (#250)
  Set ulimit -n for system user (#251)
  Implement command for clearing old private distributions files (#244)
  Fix Proxy response caching (#247)
Signed-off-by: Joshua Gigg <giggsey@gmail.com>
@akondas
Copy link
Member

akondas commented Sep 7, 2020

Hey @giggsey, looks like a good idea.
When it comes to pagination with filters, I usually do it through an additional object. So you can create something like this:

final class Filter
{
    private int $offset;
    private int $limit;

    public function __construct()
    {
        $this->offset = 0;
        $this->limit = 20;
    }

    public function setOffset(int $offset): self
    {
        $this->offset = $offset;

        return $this;
    }

    public function setLimit(int $limit): self
    {
        $this->limit = $limit;

        return $this;
    }

    public function limit(): int
    {
        return $this->limit;
    }

    public function offset(): int
    {
        return $this->offset;
    }
}

(you can add $query param for serach reason)

And then add it to count and found methods in query:

interface PackageQuery
{
    public function findAll(Filter $filter): array;
    public function count(Filter $filter): int;
}

Side note about UI: here is mine proposition 😉
Screenshot from 2020-09-07 08-53-46

@giggsey
Copy link
Contributor Author

giggsey commented Sep 7, 2020

@akondas Sounds good - I'll continue over the next few days.

@giggsey
Copy link
Contributor Author

giggsey commented Sep 7, 2020

image

@giggsey giggsey marked this pull request as ready for review September 7, 2020 20:09
@giggsey
Copy link
Contributor Author

giggsey commented Sep 7, 2020

@akondas Tests are failing because the test data is inserting NULL name & description. I don't use Postgres, and I'm not sure if there is a trick to include NULLs when the Filter searchTerm is empty.

src/Query/Filter.php Outdated Show resolved Hide resolved
Copy link
Member

@akondas akondas left a comment

Choose a reason for hiding this comment

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

I left some comments, the rest looks fine 👏

@codecov
Copy link

codecov bot commented Sep 8, 2020

Codecov Report

Merging #259 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #259   +/-   ##
=========================================
  Coverage     99.81%   99.82%           
- Complexity     1522     1539   +17     
=========================================
  Files           251      252    +1     
  Lines          4434     4479   +45     
=========================================
+ Hits           4426     4471   +45     
  Misses            8        8           
Impacted Files Coverage Δ Complexity Δ
src/Controller/OrganizationController.php 100.00% <100.00%> (ø) 41.00 <3.00> (+2.00)
src/Query/Filter.php 100.00% <100.00%> (ø) 13.00 <13.00> (?)
src/Query/User/PackageQuery/DbalPackageQuery.php 100.00% <100.00%> (ø) 25.00 <4.00> (+2.00)

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 97de038...43ae73f. Read the comment docs.

src/Query/Filter.php Outdated Show resolved Hide resolved
Copy link
Member

@akondas akondas left a comment

Choose a reason for hiding this comment

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

Nice 👍
Do you want to try to write a functional test for this functionality? (you can check OrganizationControllerTest::testPackages should be very similar, also in test you can use $this->fixtures->syncPackageWithData to populate package with given name)

@giggsey
Copy link
Contributor Author

giggsey commented Sep 8, 2020

Sure, I'll look at adding the tests.

Copy link
Member

@akondas akondas left a comment

Choose a reason for hiding this comment

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

Thanks 🍻 @giggsey, this will also fix error with negative offset 😉

@akondas akondas mentioned this pull request Sep 8, 2020
8 tasks
@akondas akondas merged commit e9e8b28 into repman-io:master Sep 8, 2020
@giggsey
Copy link
Contributor Author

giggsey commented Sep 8, 2020

@akondas There are other places that use pagination, but are still doing it manually. Want me to convert them over to Filter (no need to add search to them)

@akondas
Copy link
Member

akondas commented Sep 8, 2020

Whenever you have the opportunity, I would like to. I'm just wondering if I should make a separate filter then so that this search term is not confusing. In the sense, if a particular query does not implement a search, let it use a filter without that capability.

If so, I would suggest to do a separate filter in the namespace of Package and leave this general filter only with the limit and offset attributes.

Buddy\Repman\Query\Filter
Buddy\Repman\Query\User\PackageQuery\Filter

akondas added a commit that referenced this pull request Sep 9, 2020
* Package List Search

Signed-off-by: Joshua Gigg <giggsey@gmail.com>

* Replace all pagination with Filter classes

Continuation of #259

* Fix code style

* Fix suggestions & PHPStan

* Import Filter as an Alias

Co-authored-by: Arkadiusz Kondas <arkadiusz.kondas@gmail.com>
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