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

Show district proposals at community page #2134

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

Senen
Copy link

@Senen Senen commented May 11, 2021

References

This is part of the Ciudades Abiertas project.

Objectives

  1. Add new "District proposals" tab to show district proposals at the community page for proposals with community_hide set to true. The tab title might contain the number of proposals. As example: "District proposals (15)".
  2. Show proposals the same as the proposals index page
  3. Show oldest proposals first
  4. When there are more proposals than the defined per page proposals, show the pagination links. Currently, the per page value is the default, 25.

Visual Changes

Captura de pantalla 2021-05-29 a las 13 10 11

Does this PR need a Backport to CONSUL?

No

Notes

None

@Senen Senen self-assigned this May 11, 2021
@Senen Senen force-pushed the community_proposals branch from 90258eb to 8261b83 Compare May 29, 2021 11:24
@Senen Senen marked this pull request as ready for review May 29, 2021 11:25
@@ -37,11 +43,20 @@ def load_participants
@participants = @community.participants
end

def load_geozone_proposals
geozone = @community.proposal.geozone
@proposals = geozone.proposals.without_comunity.page(params[:proposals_page]).order(:created_at)
Copy link

Choose a reason for hiding this comment

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

Why without_comunity?

Suggested change
@proposals = geozone.proposals.without_comunity.page(params[:proposals_page]).order(:created_at)
@proposals = geozone.proposals.without_comunity.order(:created_at).page(params[:proposals_page])

Although AFAIK it doesn't affect the application, we usually write page after order in order to make the code easier to understand, since it follows the logic behind it: first we order the records, and then we take a certain number of them. We don't take a certain number of records first and then we order them.

<li class="tabs-title">
<%= link_to "#tab-district-proposals" do %>
<h3>
<%= t("community.show.tab.proposals") %>
Copy link

Choose a reason for hiding this comment

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

Would it be possible to make this tab.proposals key and the #tab-district-proposals URL more consistent? I mean, another tab uses tab.participants and #tab-participants; if we followed these conventions, maybe in the future we could refactor the code and remove the duplication.

Of course, now it's a bit difficult because the third "tab" points to #tab-polls but the key is subnav.surveys 😌.

Copy link
Author

Choose a reason for hiding this comment

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

Done!


visit community_path(proposal.community)

expect(page).not_to have_link "District proposals (1)"
Copy link

Choose a reason for hiding this comment

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

Suggested change
expect(page).not_to have_link "District proposals (1)"
expect(page).not_to have_link text: "District proposals"

This way this expectation will fail even if (for whatever reasons) the code has a bug and renders "District proposals ()" for real proposals.

Comment on lines 189 to 191
proposals = create_list(:proposal, Kaminari.config.default_per_page + 1, geozone: geozone)
visit community_path(fake_proposal.community)
click_link "District proposals (26)"
Copy link

Choose a reason for hiding this comment

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

Suggested change
proposals = create_list(:proposal, Kaminari.config.default_per_page + 1, geozone: geozone)
visit community_path(fake_proposal.community)
click_link "District proposals (26)"
allow(Proposal).to receive(:default_per_page).and_return(2)
proposals = create_list(:proposal, 3, geozone: geozone)
visit community_path(fake_proposal.community)
click_link "District proposals (3)"

This way the test is much faster since it creates 3 records instead of 26.

Copy link
Author

Choose a reason for hiding this comment

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

Nice! 👌🏼

@Senen Senen force-pushed the community_proposals branch 2 times, most recently from 70e2107 to 45a5f08 Compare June 1, 2021 08:28
Copy link

@javierm javierm 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 to me 😄.

Senen added 4 commits October 25, 2021 11:39
IMO, it has more sense to call it `community-tabs` than `communities-participants`.
Now we can use the `app/views/custom/proposals/_proposal.html.erb` partial
anywhere. Otherwise, Rails would search for the partial
at the caller parent folder throwing a `Not found template
error`.
The proposal geozone is mandatory when comunity_hide is true.
@Senen Senen force-pushed the community_proposals branch from 45a5f08 to 0f9e409 Compare October 25, 2021 09:43
@Senen
Copy link
Author

Senen commented Oct 25, 2021

I recently updated the code with the latest master branch version to solve conflicts, the latest versión of master branch does not include feature specs anymore, so I deleted them. Here is the previous version where we had feature specs for the new feature.

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.

2 participants