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

removed the function for getURLParam and replaced with URLSearchParam method #9768

Merged
merged 1 commit into from Dec 9, 2022

Conversation

Lovelyfin00
Copy link
Contributor

Fixes #9765

Fix Summary

  • Removed the getURLParam function and replaced it with the URLSearchParams method.
  • The function was called in a new variable (currentQuery) line 272, which I removed and replaced with the get method of the URLSearchParams.
  • On running npm run lint line 307 gave me errors which I assume is because of this eslint rule // eslint-disable-next-line func-names
  • Since newQuery local variable in line 270 was used in searchParams.set(), I had to remove it from that line and move it to line 267.

@squash-labs
Copy link

squash-labs bot commented Dec 8, 2022

Manage this branch in Squash

Test this branch here: https://lovelyfin00replace-geturlparam-0c4lw.squash.io

Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

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

Great start on this - thanks for getting a PR up.

The code doesn't look right as is - I have put a few comments.

Reach out on Slack if this doesn't make sense.

Also - when changing code - be sure you validate the behaviour before and after. Maybe add console.log to the search function when working locally to understand what this code is doing and when it's called.

My concern is that this change as is may not work correctly.

return '';
};
const searchParams = new URLSearchParams(window.location.search);
searchParams.set('q', newQuery);
Copy link
Member

Choose a reason for hiding this comment

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

I think there may be some confusion here.

You should probably move the new URL... Thing up to line 270 - inside the function body of search

Also I do not see a need to set the query here at all - that's only needed if you intend to update the URL

@@ -264,12 +264,12 @@ $(() => {

// auto focus on search box
$input.trigger('focus');
const newQuery = $input.val();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this should have moved, pulling this out of the search function will likely break the header search.

This code reads the search field value, which I assume we would only want to do when we call the search function.

@lb- lb- added component:Search status:Needs Work javascript Pull requests that update Javascript code labels Dec 9, 2022
@Lovelyfin00
Copy link
Contributor Author

I've made the changes as requested.
I tested on C:\Users\HP\Desktop\Wagtail New Codebase\wagtail\wagtail\images\templates\wagtailimages\images\index.html

image

Copy link
Member

@lb- lb- left a comment

Choose a reason for hiding this comment

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

Working great! thanks @Lovelyfin00

- Fixes wagtail#9765
- removed the function for getURLParam function and replaced with URLSearchParam method
- already used in many other places in the same file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:Search javascript Pull requests that update Javascript code
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Replace getURLParam with URLSearchParams - JavaScript clean up
2 participants