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

Kt 2021 proposalitem features conditions #3984

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions meinberlin/apps/budgeting/assets/BudgetingProposalList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ export const BudgetingProposalList = (props) => {
useEffect(fetchProposals, [])

return (
<div className="l-wrapper">
<div className="l-center-8">
<ul className="u-list-reset">
{data.map((proposal, idx) =>
<BudgetingProposalListItem
key={`budgeting-proposal-${idx}`}
proposal={proposal}
/>)}
</ul>
{meta?.is_paginated &&
<Pagination
currPageIndex={meta.current_page}
pageCount={meta.page_count}
onPaginate={newUrl => onPaginate(newUrl)}
/>}
<div className="module-content--light">
<div className="l-wrapper">
<div className="l-center-8">
<ul className="u-list-reset">
{data.map((proposal, idx) =>
<BudgetingProposalListItem
key={`budgeting-proposal-${idx}`}
proposal={proposal}
isVotingPhase={props.is_voting_phase}
/>)}
</ul>
{meta?.is_paginated &&
<Pagination
currPageIndex={meta.current_page}
pageCount={meta.page_count}
onPaginate={newUrl => onPaginate(newUrl)}
/>}
</div>
</div>
</div>
)
Expand Down
28 changes: 15 additions & 13 deletions meinberlin/apps/budgeting/assets/BudgetingProposalListItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { ListItemBadges } from './ListItemBadges'
import { ListItemStats } from './ListItemStats'

export const BudgetingProposalListItem = (props) => {
const { proposal } = props
const { proposal, isVotingPhase } = props
return (
<li className="list-item no-hover">
<ListItemStats
positiveCount={proposal.positive_rating_count}
negativeCount={proposal.negative_rating_count}
commentCount={proposal.comment_count}
/>
{!isVotingPhase &&
<ListItemStats
positiveCount={proposal.positive_rating_count}
negativeCount={proposal.negative_rating_count}
commentCount={proposal.comment_count}
/>}
<h3 className="list-item__title">
<a href={proposal.url}>
{proposal.name}
Expand All @@ -33,13 +34,14 @@ export const BudgetingProposalListItem = (props) => {
</span>
{toDate(proposal.created)}
</div>
<CheckboxButton
onText={django.gettext('Voted')}
offText={django.gettext('Give my vote')}
onClass="btn"
offClass="btn btn--light"
uniqueID={proposal.pk}
/>
{isVotingPhase &&
<CheckboxButton
onText={django.gettext('Voted')}
offText={django.gettext('Give my vote')}
onClass="btn"
offClass="btn btn--light"
uniqueID={proposal.pk}
/>}
</div>
</li>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { BudgetingProposalListItem } from '../BudgetingProposalListItem'

test('render list item with vote button', () => {
const proposal = {
name: 'myProposal',
url: 'www',
creator: 'creator',
created: '2021-11-11T15:37:19.490201+01:00'
}
render(<BudgetingProposalListItem proposal={proposal} isVotingPhase />)
expect(screen.getByText('myProposal')).toBeTruthy()
expect(screen.getByText('creator')).toBeTruthy()
expect(screen.getByText('11. mock text 2021')).toBeTruthy()
})

test('render list item with stats', () => {
const proposal = {
name: 'myProposal',
url: 'www',
creator: 'creator',
created: '2021-11-11T15:37:19.490201+01:00'
}
render(<BudgetingProposalListItem proposal={proposal} isVotingPhase={false} />)
expect(screen.getByText('myProposal')).toBeTruthy()
expect(screen.getByText('creator')).toBeTruthy()
expect(screen.getByText('11. mock text 2021')).toBeTruthy()
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { ListItemBadges } from './ListItemBadges'
import { ListItemBadges } from '../ListItemBadges'

test('displaying category badge', () => {
render(<ListItemBadges category={{ name: 'Renovation' }} />)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { render, screen } from '@testing-library/react'
import { ListItemStats } from './ListItemStats'
import { ListItemStats } from '../ListItemStats'

test('displaying all 3 stats', () => {
render(
Expand Down
10 changes: 10 additions & 0 deletions meinberlin/apps/budgeting/assets/__tests__/SpacedSpan.jest.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import { render } from '@testing-library/react'
import { SpacedSpan } from '../SpacedSpan'

test('displaying spaced span', () => {
const tree = render(<SpacedSpan>word</SpacedSpan>)
// screen.debug()
const firstSpaceSpan = tree.container.querySelector('span')
expect(firstSpaceSpan.innerHTML).toBe(' ')
})
2 changes: 1 addition & 1 deletion meinberlin/apps/budgeting/assets/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const months = [

// toDate returns a formatted date string
// input: 2021-11-11T15:37:19.490201+01:00
// output: 15. November 2021
// output: 11. November 2021
export const toDate = (isodate) => {
const d = new Date(isodate)
return `${d.getDate()}. ${months[d.getMonth()]} ${d.getFullYear()}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@
{% map_display_points object_list module.settings_instance.polygon %}
</div>
{% else %}
<div class="module-content--light">
{% react_proposals view.module %}
<div class="l-wrapper">
<div class="l-center-8">
{% if object_list.count > 0 %}
<ul class="u-list-reset">
{% for object in object_list %}
{% include "meinberlin_contrib/includes/proposal_list_item.html" with object=object %}
{% endfor %}
</ul>
{% else %}
{% trans "Nothing to show" %}
{% endif %}

{% include "meinberlin_contrib/includes/pagination.html" %}
</div>
</div>
</div>
{% react_proposals view.module %}
{% endif %}
{% endblock %}
7 changes: 2 additions & 5 deletions meinberlin/apps/budgeting/templatetags/react_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
from django.urls import reverse
from django.utils.html import format_html

# from django.urls import reverse
# from django.utils.translation import gettext_lazy as _
# from adhocracy4.rules.discovery import NormalUser

register = template.Library()


@register.simple_tag(takes_context=True)
def react_proposals(context, obj):
proposals_api_url = reverse('proposals-list', kwargs={'module_pk': obj.pk})
attributes = {'proposals_api_url': proposals_api_url}
attributes = {'proposals_api_url': proposals_api_url,
'is_voting_phase': 'voting' in obj.active_phase.type}

return format_html(
'<div data-mb-widget="proposals" '
Expand Down