From a1aa1fadd98ed054341821df153a7ea37851d3ad Mon Sep 17 00:00:00 2001 From: Philipp Veller Date: Thu, 6 Feb 2025 12:29:09 +0100 Subject: [PATCH] a4: update package budgeting: remove old, unused react components --- .../react/budgeting/BudgetingProposalList.jsx | 138 ------------------ meinberlin/react/budgeting/EndSessionLink.jsx | 57 -------- .../__tests__/EndSessionLink.jest.jsx | 43 ------ .../react/budgeting/react_proposals_init.jsx | 2 - package.json | 2 +- requirements/base.txt | 2 +- 6 files changed, 2 insertions(+), 242 deletions(-) delete mode 100644 meinberlin/react/budgeting/BudgetingProposalList.jsx delete mode 100644 meinberlin/react/budgeting/EndSessionLink.jsx delete mode 100644 meinberlin/react/budgeting/__tests__/EndSessionLink.jest.jsx diff --git a/meinberlin/react/budgeting/BudgetingProposalList.jsx b/meinberlin/react/budgeting/BudgetingProposalList.jsx deleted file mode 100644 index fedf3ee8a3..0000000000 --- a/meinberlin/react/budgeting/BudgetingProposalList.jsx +++ /dev/null @@ -1,138 +0,0 @@ -import React, { useEffect, useState, useRef } from 'react' -import django from 'django' -import { useLocation, useSearchParams } from 'react-router' -import { EndSessionLink } from './EndSessionLink' -import { Pagination } from '../contrib/Pagination' -import { Card } from '../contrib/card/Card' -import { CardMeta } from '../contrib/card/CardMeta' -import { CardStatus } from '../contrib/card/CardStatus' -import { CountDown } from '../contrib/CountDown' -import { ControlBar } from '../contrib/ControlBar' - -export const BudgetingProposalList = (props) => { - const [data, setData] = useState([]) - const [meta, setMeta] = useState() - const location = useLocation() - const [queryParams] = useSearchParams() - const getVoteCountText = (votes) => { - const countText = django.ngettext('you have 1 vote left.', 'you have %s votes left.', votes) - return django.interpolate(countText, [votes]) - } - - const translations = { - list: django.gettext('Proposals list'), - noResults: django.gettext('Nothing to show'), - pillList: django.gettext('Proposal tags') - } - - const scrolledRef = useRef(false) - - const fetchProposals = () => { - const url = props.proposals_api_url + location.search - fetch(url) - .then(resp => resp.json()) - .then(json => { - setData(json.results) - setMeta({ - total_count: json.count, - current_page: queryParams.get('page') || 1, - page_count: json.page_count, - is_paginated: json.page_count > 1, - previous: json.previous, - next: json.next, - filters: json.filters, - permissions: json.permissions, - locale: json.locale, - token_info: json.token_info, - page_elided_range: json.page_elided_range - }) - }) - .catch(error => console.log(error)) - } - - const scrollToProposal = () => { - if (location.hash && !scrolledRef.current) { - const id = location.hash.replace('#', '') - const element = document.getElementById(id) - if (element) { - element.scrollIntoView({ behavior: 'smooth' }) - scrolledRef.current = true - } - } - } - - useEffect(fetchProposals, [location.search]) - useEffect(scrollToProposal) - - const renderList = (data) => { - return ( - <> -

{translations.list}

- - {meta?.is_paginated && - } - - ) - } - - return ( - <> - {(meta?.permissions.has_voting_permission_and_valid_token) && -
-
-
- - -
-
-
} - -
-
-
- {Object.keys(data).length > 0 - ? renderList(data) - : translations.noResults} -
-
-
- - ) -} diff --git a/meinberlin/react/budgeting/EndSessionLink.jsx b/meinberlin/react/budgeting/EndSessionLink.jsx deleted file mode 100644 index 9ea6866597..0000000000 --- a/meinberlin/react/budgeting/EndSessionLink.jsx +++ /dev/null @@ -1,57 +0,0 @@ -import React from 'react' -import django from 'django' -import Modal from 'adhocracy4/adhocracy4/static/Modal' -import { useSearchParams } from 'react-router' - -export const EndSessionLink = (props) => { - const translations = { - finished: django.gettext('Are you finished?'), - endSession: django.gettext('End session'), - modalDescription: django.gettext('To save your votes you do not need to do anything else. End the session to enter a new code. If you want to change the votes you have already cast, you can re-enter your code as long as the voting phase is running. '), - modalBodyQuestion: django.gettext('Do you want to end the session?'), - modalCancel: django.gettext('Cancel') - } - const [queryParams, setQueryParams] = useSearchParams() - - const modalPartials = { - title: translations.endSession, - description: translations.modalDescription, - abort: translations.modalCancel - } - - const handleEndSession = () => { - // remove own_votes from url parameters when session is ended - queryParams.delete('own_votes') - setQueryParams(queryParams) - - const endSessionUrl = props.endSessionUrl - fetch(endSessionUrl) - .then(() => window.location.reload(true)) - .catch(error => console.log(error)) - } - - return ( - <> -
- {translations.finished} - -
- - - ) -} diff --git a/meinberlin/react/budgeting/__tests__/EndSessionLink.jest.jsx b/meinberlin/react/budgeting/__tests__/EndSessionLink.jest.jsx deleted file mode 100644 index cb5035f06e..0000000000 --- a/meinberlin/react/budgeting/__tests__/EndSessionLink.jest.jsx +++ /dev/null @@ -1,43 +0,0 @@ -import React from 'react' -import { render, screen, fireEvent, waitFor } from '@testing-library/react' -import { EndSessionLink } from '../EndSessionLink' -import { BrowserRouter } from 'react-router' - -test('End session - check: modal rendered', async () => { - render( - - - - ) - - const modalBtn = screen.getByRole('button', { name: 'End session' }) - const modalRender = screen.queryByRole('dialog') - expect(modalRender).toBeNull() - fireEvent.click(modalBtn) - - await waitFor(() => { - const modalRender = screen.findByRole('dialog', { hidden: false }) - expect(modalRender).toBeTruthy() - }) -}) - -test('End session - check: end session url fetch failed, tests hidden btn click, not in rendered modal', async () => { - // overwrite global.fetch with mock function - global.fetch = jest.fn().mockRejectedValue('testing: expected network error') - - render( - - - - ) - // get second instance of End session btn - const endSessionBtn = screen.getAllByRole('button', { name: 'End session', hidden: true })[1] - fireEvent.click(endSessionBtn) - - expect(global.fetch).toHaveBeenCalledTimes(1) - const noUrl = screen.queryAllByText('mock text') - expect(noUrl).toBeTruthy() - - // reverse overwrite of global.fetch - await global.fetch.mockClear() -}) diff --git a/meinberlin/react/budgeting/react_proposals_init.jsx b/meinberlin/react/budgeting/react_proposals_init.jsx index 61f3bc54cb..6e2d7ee9b8 100644 --- a/meinberlin/react/budgeting/react_proposals_init.jsx +++ b/meinberlin/react/budgeting/react_proposals_init.jsx @@ -2,7 +2,6 @@ import React from 'react' import django from 'django' import { createRoot } from 'react-dom/client' import { widget as ReactWidget } from 'adhocracy4' -// import { BudgetingProposalList } from './BudgetingProposalList.jsx' import { BrowserRouter } from 'react-router' import { FetchItemsProvider } from '../contrib/contexts/FetchItemsProvider' import { ListMapView } from '../contrib/map/ListMapView' @@ -22,7 +21,6 @@ function init () { - {/* */} ) diff --git a/package.json b/package.json index 7e5e1b9aa2..df13833fc3 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@react-leaflet/core": "^2.1.0", "@turf/turf": "^6.5.0", "acorn": "8.14.0", - "adhocracy4": "liqd/adhocracy4#b7508567d7d1ef99313702e3e8e8fef7e696922e", + "adhocracy4": "liqd/adhocracy4#39e188c832746c6ed6dd4aacf3543538f6b580e5", "autoprefixer": "10.4.20", "bootstrap": "5.2.3", "copy-webpack-plugin": "12.0.2", diff --git a/requirements/base.txt b/requirements/base.txt index 5dfa1513d6..b3b02b57f0 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,5 +1,5 @@ # A4 -git+https://github.com/liqd/adhocracy4.git@b7508567d7d1ef99313702e3e8e8fef7e696922e#egg=adhocracy4 +git+https://github.com/liqd/adhocracy4.git@39e188c832746c6ed6dd4aacf3543538f6b580e5#egg=adhocracy4 # Additional requirements beautifulsoup4==4.12.3