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

Add Helpers for TextFilters #1812

Merged

Conversation

lrljoe
Copy link
Collaborator

@lrljoe lrljoe commented Aug 3, 2024

There is some clean-up of tests and test-processes.

The main feature of this PR however is: adds Extra Helpers for TextFilter types, to simplify every-day use cases

Extra Helpers

There are a number of helpers to simplify your code, should you not wish to rewrite the filter function repeatedly for a Text Filter. You can use one of the below methods per-filter.

Contains

This executes the filter and returns results where the field contains the filter value

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->contains('users.name'),
    ];
}

notContains

This executes the filter and returns results where the field does not contain filter value

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->notContains('users.name'),
    ];
}

startsWith

This executes the filter and returns results where the field starts with the filter value

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->startsWith('users.name'),
    ];
}

notStartsWith

This executes the filter and returns results where the field does not start with the filter value

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->notStartsWith('users.name'),
    ];
}

endsWith

This executes the filter and returns results where the field ends with the filter value

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->endsWith('users.name'),
    ];
}

notEndsWith

This executes the filter and returns results where the field does not end with the filter value

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->notEndsWith('users.name'),
    ];
}

setField

An optional method for setting the field to use when filtering, if used, you may omit the field from the above methods, for example:

public function filters(): array
{
    return [
        TextFilter::make('Name')
            ->config([
                'placeholder' => 'Search Name',
                'maxlength' => '25',
            ])
            ->setField('users.name')
            ->contains(),
    ];
}

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests and did you add any new tests needed for your feature?
  2. Did you update all templates (if applicable)?
  3. Did you add the relevant documentation (if applicable)?
  4. Did you test locally to make sure your feature works as intended?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link

codecov bot commented Aug 3, 2024

Codecov Report

Attention: Patch coverage is 91.80328% with 5 lines in your changes missing coverage. Please review.

Project coverage is 88.27%. Comparing base (40485a0) to head (6bff360).
Report is 18 commits behind head on development.

Files Patch % Lines
...rc/Views/Traits/Filters/HandlesWildcardStrings.php 90.74% 5 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                @@
##             development    #1812      +/-   ##
=================================================
+ Coverage          87.14%   88.27%   +1.12%     
- Complexity          1495     1562      +67     
=================================================
  Files                139      143       +4     
  Lines               3484     3649     +165     
=================================================
+ Hits                3036     3221     +185     
+ Misses               448      428      -20     

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

@lrljoe lrljoe merged commit f715bfe into rappasoft:development Aug 3, 2024
lrljoe added a commit that referenced this pull request Aug 4, 2024
## [v3.4.0] - 2024-08-04
### New Features
- Add Helpers for TextFilters by @lrljoe in #1812
- Change method names for TextFilters handler by @lrljoe in #1814
- Capability to set Reorder Column TH Attributes by @lrljoe in #1811
- Bulk Actions - Customise Select All Behaviours by @lrljoe in #1810

### Bug Fixes
- Fix loading spinner for dark tailwind theme by @lrljoe in #1809

### Tweaks
- Blade Minimisation & ColumnSelect Cleanup by @lrljoe in #1806
- Adjust DateColumn with Missing Tests and Coping with DateTime Casts by @lrljoe in #1813

### Docs
- Add reference to Bulk Actions TH styling in main styling by @lrljoe in #1808
- Update docs for setPillsLocale by @lrljoe in #1800
- Add note on label method for setAdditionalSelects by @lrljoe in #1816
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.

1 participant