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

Simplify the code rendering the map #5108

Merged
merged 18 commits into from
May 5, 2023
Merged

Simplify the code rendering the map #5108

merged 18 commits into from
May 5, 2023

Conversation

javierm
Copy link
Member

@javierm javierm commented Apr 26, 2023

References

Objectives

  • Make it easier to add new features involving maps

@javierm javierm self-assigned this Apr 26, 2023
@javierm javierm added this to Doing in Consul Democracy Apr 26, 2023
});
},
getPopupContent: function(data) {
return "<a href='/budgets/" + data.budget_id + "/investments/" + data.investment_id + "'>" + data.investment_title + "</a>";

Choose a reason for hiding this comment

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

Line 213 exceeds the maximum line length of 110.

@javierm javierm force-pushed the map_refactoring branch 3 times, most recently from 2089f8f to 7118e4e Compare April 28, 2023 14:15
@javierm javierm marked this pull request as ready for review April 28, 2023 14:15
@javierm javierm moved this from Doing to Reviewing in Consul Democracy Apr 28, 2023
@javierm javierm moved this from Reviewing to Doing in Consul Democracy Apr 28, 2023
@javierm javierm moved this from Doing to Reviewing in Consul Democracy Apr 28, 2023
@javierm javierm force-pushed the map_refactoring branch 3 times, most recently from 1907495 to 1c94694 Compare May 2, 2023 13:45
@taitus taitus self-assigned this May 3, 2023
javierm added 11 commits May 4, 2023 15:27
The only view that linked to this action was never used and so it was
deleted in commit 0bacd5b.

Since now the proposals controller is the only one place rendering the
`shared/map` partial, we're moving it to the proposals views.
We're calling this method after setting the map location with
`map_location = MapLocation.new if map_location.nil?`, so the condition
`map_location.present?` is always going to be true.
This way it'll be easier to refactor it.
Since we aren't using helpers anymore, we don't need the `map_location`
prefix.
The calls to `render_map` are confusing since there are so many
parameters. We can assume that the map is editable if we pass the remove
marker label.
We were passing `nil` in some calls, which was confusing.

Since now we've got two optional parameters, we're using named
parameters.
We were probably setting them separately to avoid having blank data
attributes in the HTML. However, when a data attribute is `nil`, Rails
doesn't write it in the HTML in the first place.
We were manually generating the IDs in order to pass them as data
attributes in the HTML in a component where we don't have access to the
form which has the inputs.

However, these data attributes only make sense when there's a form
present, so we can pass the form as a parameter and use it to get the
IDs.

We can now define a map as editable when there's an associated form,
which makes sense IMHO.
Rails forms automatically take the value from the object related to the
form.
We had two different keys with the same text and were passing it as a
parameter. Since the text is the same in any case, we don't need a
parameter for it.

Note we are using the `proposals` i18n key instead of creating a new one
in a `shared` namespace one because creating a new key would mean that
we'd lose the already existing translations in Crowdin.
We had 130 lines long function, and we're trying to reduce its size so
it's easier to follow the code.
The `marker` variable is like a global variable inside the
`initializeMap` function, so assigning it inside the `createMarker`
function was changing its value in other places.

So we're using different variable names like `newMarker` in order to
make the code easier to follow. Now we "only" change the `marker`
variable in functions that modify the marker.
Consul Democracy automation moved this from Reviewing to Testing May 5, 2023
@javierm javierm merged commit 0ef1882 into master May 5, 2023
Consul Democracy automation moved this from Testing to Release 2.0.0 May 5, 2023
@javierm javierm deleted the map_refactoring branch May 5, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants