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

Make psychsheets sort by average by default #10368

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ export default function RegistrationList({ competitionInfo }) {
const { sortColumn, sortDirection } = state;
const changeSortColumn = (name) => dispatch({ type: 'CHANGE_SORT', sortColumn: name });

const blindFoldedEvents = ['333mbf', '333bf', '444bf', '555bf'];
Copy link
Member

Choose a reason for hiding this comment

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

You don't need to hardcode this. We have events data available as import { events } from 'lib/wca-data.js.erb' (note you might need to change the relative path to the file)


const [psychSheetEvent, setPsychSheetEvent] = useState();
const [psychSheetSortBy, setPsychSheetSortBy] = useState('single');
const psychSheetSortBy = useMemo(() => (blindFoldedEvents.includes(psychSheetEvent) ? 'single' : 'average'), [psychSheetEvent]);
Copy link
Member

Choose a reason for hiding this comment

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

Using my suggestion from above, you can compute this as events.byId[psychSheetEvent].recommendedFormat().sortBy


const { isLoading: isLoadingPsychSheet, data: psychSheet } = useQuery({
queryKey: [
Expand All @@ -115,7 +117,6 @@ export default function RegistrationList({ competitionInfo }) {

const registrationsWithPsychsheet = useMemo(() => {
if (psychSheet !== undefined) {
setPsychSheetSortBy(psychSheet.sort_by);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this line being deleted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Otherwise, react throws an error that setPsychSheetSortBy is not defined

Copy link
Member

Choose a reason for hiding this comment

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

Ah, because you're changing to a useMemo above. I see. But that means when loading a psych sheet from the backend, you cannot change the sort order anymore. I feel like this will break lots of existing use-cases

(for example, this will break proper sorting on events like 333 which have genuine use-cases of using either single or average for sorting)

return psychSheet.sorted_rankings.map((p) => {
const registrationEntry = registrations.find((r) => p.user_id === r.user_id);
return { ...p, ...registrationEntry };
Expand Down
Loading