Skip to content

Commit

Permalink
Edit Person Requests page in WRT panel (#10451)
Browse files Browse the repository at this point in the history
* Edit Person Requests page in WRT panel

* Review changes

---------

Co-authored-by: Daniel M James <[email protected]>
  • Loading branch information
danieljames-dj and Daniel M James authored Jan 9, 2025
1 parent a7354e8 commit eb7f694
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 1 deletion.
41 changes: 41 additions & 0 deletions app/controllers/tickets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@
# frozen_string_literal: true

class TicketsController < ApplicationController
include Rails::Pagination

SORT_WEIGHT_LAMBDAS = {
createdAt:
lambda { |ticket| ticket.created_at },
}.freeze

def index
tickets = Ticket

# Filter based on params
type = params[:type]
if type
tickets = tickets.where(metadata_type: type)
end

status = params[:status]
tickets = tickets.select do |ticket|
if status
ticket.metadata&.status == status
else
true
end
end

# Filter based on current_user's permission
tickets = tickets.select do |ticket|
ticket.can_user_access?(current_user)
end

# Sort
sort_param = params[:sort] || ''
tickets = sort(tickets, sort_param, SORT_WEIGHT_LAMBDAS)

# paginate won't help in improving efficiency here because we are fetching all the tickets
# and then filtering and sorting them. We can't use the database to do this because the
# filtering and sorting is based on the metadata of the ticket.
# TODO: Check the feasibility of using the database to filter and sort the tickets.
paginate json: tickets
end

def show
respond_to do |format|
format.html do
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ def self.panel_pages
:downloadVoters,
:generateDbToken,
:approveAvatars,
:editPersonRequests,
].index_with { |panel_page| panel_page.to_s.underscore.dasherize }
end

Expand Down Expand Up @@ -682,6 +683,7 @@ def self.panel_list
name: 'WRT panel',
pages: [
panel_pages[:postingDashboard],
panel_pages[:editPersonRequests],
panel_pages[:editPerson],
panel_pages[:approveAvatars],
],
Expand Down
5 changes: 5 additions & 0 deletions app/webpacker/components/Panel/PanelPages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import RegionsAdmin from './pages/RegionsAdmin';
import RegionManager from './pages/RegionManager';
import DownloadVoters from './pages/DownloadVoters';
import ApprovePictures from './pages/ApprovePictures';
import EditPersonRequestsPage from './pages/EditPersonRequestsPage';

const DELEGATE_HANDBOOK_LINK = 'https://documents.worldcubeassociation.org/edudoc/delegate-handbook/delegate-handbook.pdf';

Expand Down Expand Up @@ -139,4 +140,8 @@ export default {
name: 'Approve Avatars',
component: ApprovePictures,
},
[PANEL_PAGES.editPersonRequests]: {
name: 'Edit Person Requests',
component: EditPersonRequestsPage,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Header } from 'semantic-ui-react';
import _ from 'lodash';
import TicketsList from '../../../TicketsList';
import { ticketTypes, ticketStatuses } from '../../../../lib/wca-data.js.erb';

export default function EditPersonRequestsPage() {
return (
<>
{[ticketStatuses.edit_person.open, ticketStatuses.edit_person.closed].map((status) => (
<>
<Header>{`${_.upperFirst(status)} Tickets`}</Header>
<TicketsList
type={ticketTypes.edit_person}
status={status}
sort="createdAt:desc"
/>
</>
))}
</>
);
}
29 changes: 29 additions & 0 deletions app/webpacker/components/TicketsList/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { List } from 'semantic-ui-react';
import useLoadedData from '../../lib/hooks/useLoadedData';
import { viewUrls } from '../../lib/requests/routes.js.erb';
import Loading from '../Requests/Loading';
import Errored from '../Requests/Errored';

export default function TicketsList({ type, status, sort }) {
const { data: tickets, loading, error } = useLoadedData(
viewUrls.tickets.list(type, status, sort),
);

if (loading) return <Loading />;
if (error) return <Errored />;

return (
<List divided relaxed>
{tickets.map((ticket) => (
<List.Item>
<List.Content>
<List.Header as="a" href={viewUrls.tickets.show(ticket.id)}>
{`Ticket #${ticket.id}`}
</List.Header>
</List.Content>
</List.Item>
))}
</List>
);
}
7 changes: 7 additions & 0 deletions app/webpacker/lib/requests/routes.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ export const panelUrls = {

export const panelRedirectUrl = (panelPage) => `<%= CGI.unescape(Rails.application.routes.url_helpers.panel_redirect_path(panel_page: "${panelPage}")) %>`;

export const viewUrls = {
tickets: {
list: (type, status, sort) => `<%= CGI.unescape(Rails.application.routes.url_helpers.tickets_path) %>?${jsonToQueryString({ type, status, sort })}`,
show: (ticketId) => `<%= CGI.unescape(Rails.application.routes.url_helpers.ticket_path("${ticketId}")) %>`,
}
}

export const actionUrls = {
tickets: {
show: (ticketId) => `<%= CGI.unescape(Rails.application.routes.url_helpers.ticket_path("${ticketId}", format: "json")) %>`,
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
end
get 'panel/:panel_id' => 'panel#index', as: :panel_index
get 'panel/redirect/:panel_page' => 'panel#redirect', as: :panel_redirect
resources :tickets, only: [:show] do
resources :tickets, only: [:index, :show] do
post 'update_status' => 'tickets#update_status', as: :update_status
get 'edit_person_validators' => 'tickets#edit_person_validators', as: :edit_person_validators
end
Expand Down

0 comments on commit eb7f694

Please sign in to comment.