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

Pills fallback value #538

Merged
merged 6 commits into from
Nov 21, 2021
Merged

Pills fallback value #538

merged 6 commits into from
Nov 21, 2021

Conversation

fabio-ivona
Copy link
Contributor

@fabio-ivona fabio-ivona commented Nov 2, 2021

Hi @rappasoft

this PR will add a new way to generate filter pills fallback value:

at this time a filter pill label is computed as follow, using the first non-empty value:

  1. Use the label set up in $filterNames property
  2. Search for a Column with the same column value as the filter key and uses its Text
  3. Manually computes the pill label from the filter key ucwords(strtr($key, ['_' => ' ', '-' => ' ']))

with this implementation a new step is inserted between 2 and 3:

  1. Use the label set up in $filterNames property
  2. Search for a Column with the same column value as the filter key and uses its Text
  3. Uses the filter name property
  4. Manually computes the pill label from the filter key ucwords(strtr($key, ['_' => ' ', '-' => ' ']))

This way, if a filter is defined using a key that doesn't match a column name, the filter label is used for its pill value

eg. a filter is defined like this one:

'breed_id'     => Filter::make('Filter Breed')->select([
      '' => 'All',
      1  => 'American Shorthair',
      2  => 'Maine Coon',
      3  => 'Persian',
      4  => 'Norwegian Forest',
  ]),

there is not a matching column, the pill will be rendered as Filter Breed instead of Breed Id (that is meaningless for the end user)

Implementation

  • I updated the three filter-pills.blade.php templates in order to use the filter name before falling back to its key
  • I added tests in order to check that the pills are rendered with the right label

IMPORTANT

As in filter tests now the actual Livewire render method is called, in tests workflows with prefer-stable options some issues come up because lowest versions of Laravel don't support ->has() and ->class() methods in ComponentAttributeBag.

This could cause errors on projects that use older versions of Laravel. I fixed this by replacing these calls with the old methods. Let me know what do you think about it.

notes

  • this implementation is backward compatible, when views are published they will keep using the old fallback method instead of the filter label

  • I added tests for filters, which I've seen are missing:

image

@rappasoft rappasoft added the Awaiting Next Release Currently merged into development awaiting a release to master label Nov 21, 2021
@rappasoft rappasoft mentioned this pull request Nov 21, 2021
@rappasoft rappasoft merged commit 52feab7 into rappasoft:master Nov 21, 2021
@fabio-ivona fabio-ivona deleted the pills-fallback-value branch November 21, 2021 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Next Release Currently merged into development awaiting a release to master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants