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

Trim Package Name of unwanted information #220

Merged

Conversation

RhysLees
Copy link
Contributor

This PR filters unwanted information out of the package name.

Resolves #212

@marcusmoore marcusmoore self-requested a review May 25, 2022 15:50
@marcusmoore marcusmoore self-assigned this May 25, 2022
Copy link
Contributor

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

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

Thanks for your quick PR (and all of the PRs you have been submitting lately!).

I think we can simplify this PR by moving the logic to a new accessor on the Package model (something like getDisplayNameAttribute) and potentially using Laravel's string helpers to remove the unwanted strings.

This isn't tested but something like

$toRemove = [
  'nova 4',
  'nova4',
  '(nova 4)',
  'v4',
  'for nova',
  'for v4',
  "()",
  'laravel nova',
];

Str::of($name)->remove($toRemove, false)->trim();

It would be good to have tests around this as well. I'm thinking of a test in Tests\Unit\PackageTest that uses a data provider to test for the following (plus any others you can think of):

Package Name Is Converted To
CKEditor4 CKEditor4
R64 Fields R64 Fields
Nova ABC ABC
Nova 4 ABC ABC
Nova4 ABC ABC
ABC for Nova v4 ABC
ABC nova v4 ABC
ABC for v4 ABC
ABC (Nova 4) ABC
ABC v4 ABC

What do you think?

@RhysLees
Copy link
Contributor Author

Thanks for your quick PR (and all of the PRs you have been submitting lately!).

I think we can simplify this PR by moving the logic to a new accessor on the Package model (something like getDisplayNameAttribute) and potentially using Laravel's string helpers to remove the unwanted strings.

This isn't tested but something like

$toRemove = [
  'nova 4',
  'nova4',
  '(nova 4)',
  'v4',
  'for nova',
  'for v4',
  "()",
  'laravel nova',
];

Str::of($name)->remove($toRemove, false)->trim();

It would be good to have tests around this as well. I'm thinking of a test in Tests\Unit\PackageTest that uses a data provider to test for the following (plus any others you can think of):

Package Name Is Converted To
CKEditor4 CKEditor4
R64 Fields R64 Fields
Nova ABC ABC
Nova 4 ABC ABC
Nova4 ABC ABC
ABC for Nova v4 ABC
ABC nova v4 ABC
ABC for v4 ABC
ABC (Nova 4) ABC
ABC v4 ABC
What do you think?

Yeah, ill give a test with this approach using Str helper but i still think we should probably use the section where it iterates through the version numbers from 1 to latest major so it will auto-extend the list when a new major version comes out. this will future and past proof the implementation.

@marcusmoore
Copy link
Contributor

That is a good point 👍🏾

@RhysLees
Copy link
Contributor Author

That is a good point 👍🏾

Just pushed some updates, I noticed an issue caused by the order of the filter list where filters for newer versions were filtering text but not version numbers which caused failures so i swapped the loop around which fixed the issue:
Old Generation

'For Laravel Nova 4',
'For Nova 4',
'N4',
'(4)', // Place at bottom
'For Laravel Nova 3',
'For Nova 3',
'N3',
'(3)', // Place at bottom

New Generation:

'For Laravel Nova 4',
'For Laravel Nova 3',
'For Nova 4',
'For Nova 3',
'N4',
'N3',
'(4)', // Place at bottom
'(3)', // Place at bottom

The only thing I can see being an annoyance is the order of the filter list in config being important for example putting ! at the top would mean Nova ! would never be filtered leaving Nova but i suppose that is what the test is for

Copy link
Contributor

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

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

Thanks! One more request to add a few more test cases.

Let me know if you want me to take over at any point as well 😄

app/Http/Resources/Package.php Outdated Show resolved Hide resolved
app/Http/Resources/PackageResource.php Outdated Show resolved Hide resolved
tests/Unit/PackageTest.php Outdated Show resolved Hide resolved
tests/Unit/PackageTest.php Show resolved Hide resolved
@RhysLees
Copy link
Contributor Author

RhysLees commented Jun 8, 2022

@marcusmoore I made them changes as requested btw.

@marcusmoore
Copy link
Contributor

Thanks @RhysLees. I haven't had a chance to check this out yet but plan on getting back to it later this week.

Copy link
Contributor

@marcusmoore marcusmoore left a comment

Choose a reason for hiding this comment

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

Thanks @RhysLees 😄

@marcusmoore marcusmoore merged commit 1fc3d5e into tighten:main Jul 5, 2022
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.

Remove "N4", "v4", "Nova 4", "4", "(4)" From name
2 participants