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 support for parameters as Array #39

Merged
merged 3 commits into from Apr 18, 2024

Conversation

sousousore1
Copy link
Contributor

https://edgeguides.rubyonrails.org/action_controller_overview.html#hash-and-array-parameters

This pull request introduces an enhancement to the js_rails_routes library by adding support for array parameters in URLs, aligning with the Ruby on Rails guideline for handling hash and array parameters.

Copy link
Member

@ohakutsu ohakutsu left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!
I have reviewed it!

@@ -11,7 +11,13 @@ class JavaScript < Base
var query = [];
for (var param in params) if (Object.prototype.hasOwnProperty.call(params, param)) {
if (keys.indexOf(param) === -1) {
query.push(param + "=" + encodeURIComponent(params[param]));
if (Array.isArray(params[param])) {
for (var value of params[param] as Value[]) {
Copy link
Member

Choose a reason for hiding this comment

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

Please remove type assertion, since it's JavaScript. 🙏

Suggested change
for (var value of params[param] as Value[]) {
for (var value of params[param]) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback. I have made the suggested changes.

@@ -7,14 +7,20 @@ module JSRailsRoutes
module Language
class TypeScript < JavaScript
PROCESS_FUNC = <<~TYPESCRIPT
type Value = string | number
type Value = string | number | Value[]
Copy link
Member

Choose a reason for hiding this comment

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

How about this instead, since we don't expect array of array?

Suggested change
type Value = string | number | Value[]
type Value = string | number | (string | number)[]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback. I have made the suggested changes.

Copy link
Member

@ohakutsu ohakutsu left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you!

@ohakutsu ohakutsu merged commit 04d233f into increments:master Apr 18, 2024
0 of 13 checks passed
@ohakutsu ohakutsu mentioned this pull request Apr 18, 2024
@sousousore1 sousousore1 deleted the support-array-parameters branch April 19, 2024 01:19
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.

None yet

2 participants