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

Add show_reg_status to URL params in competitions overview #10728

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ export function CompDisplayCheckboxes({
shouldIncludeCancelled,
dispatchFilter,
shouldShowRegStatus,
setShouldShowRegStatus,
shouldShowAdminDetails,
canViewAdminDetails,
displayMode,
Expand Down Expand Up @@ -376,7 +375,9 @@ export function CompDisplayCheckboxes({
name="show_registration_status"
id="show_registration_status"
checked={shouldShowRegStatus}
onChange={() => setShouldShowRegStatus(!shouldShowRegStatus)}
onChange={() => dispatchFilter(
{ shouldShowRegStatus: !shouldShowRegStatus },
)}
/>
</div>
{canViewAdminDetails && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ function CompetitionsView({ canViewAdminDetails = false }) {
);
const debouncedFilterState = useDebounce(filterState, DEBOUNCE_MS);
const [displayMode, setDisplayMode] = useState(() => getDisplayMode(searchParams));
const [shouldShowRegStatus, setShouldShowRegStatus] = useState(false);
const competitionQueryKey = useMemo(
() => calculateQueryKey(debouncedFilterState, canViewAdminDetails),
[debouncedFilterState, canViewAdminDetails],
Expand Down Expand Up @@ -99,20 +98,20 @@ function CompetitionsView({ canViewAdminDetails = false }) {
body: JSON.stringify({ ids: compIds }),
}),
queryKey: ['registration-info', ...compIds],
enabled: shouldShowRegStatus && compIds.length > 0,
enabled: filterState.shouldShowRegStatus && compIds.length > 0,
// This is where the magic happens: Using `keepPreviousData` makes it so that
// all previously loaded indicators are held in-cache while the fetcher for the next
// batch is running in the background. (Adding comment here because it's not in the docs)
placeholderData: keepPreviousData,
select: (data) => data.data,
});

const competitions = useMemo(() => (shouldShowRegStatus ? (
const competitions = useMemo(() => (filterState.shouldShowRegStatus ? (
baseCompetitions?.map((comp) => {
const regData = compRegistrationData?.find((reg) => reg.id === comp.id);
return regData ? { ...comp, ...regData } : comp;
})
) : baseCompetitions), [baseCompetitions, compRegistrationData, shouldShowRegStatus]);
) : baseCompetitions), [baseCompetitions, compRegistrationData, filterState.shouldShowRegStatus]);

const [showFilters, setShowFilters] = useState(true);

Expand Down Expand Up @@ -162,8 +161,7 @@ function CompetitionsView({ canViewAdminDetails = false }) {
<CompDisplayCheckboxes
shouldIncludeCancelled={filterState.shouldIncludeCancelled}
dispatchFilter={dispatchFilter}
shouldShowRegStatus={shouldShowRegStatus}
setShouldShowRegStatus={setShouldShowRegStatus}
shouldShowRegStatus={filterState.shouldShowRegStatus}
shouldShowAdminDetails={shouldShowAdminDetails}
canViewAdminDetails={canViewAdminDetails}
displayMode={displayMode}
Expand All @@ -184,7 +182,7 @@ function CompetitionsView({ canViewAdminDetails = false }) {
<ListView
competitions={competitions}
filterState={debouncedFilterState}
shouldShowRegStatus={shouldShowRegStatus}
shouldShowRegStatus={filterState.shouldShowRegStatus}
shouldShowAdminDetails={shouldShowAdminDetails}
isLoading={competitionsIsFetching}
regStatusLoading={regDataIsPending}
Expand Down
10 changes: 10 additions & 0 deletions app/webpacker/components/CompetitionsOverview/filterUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DELEGATE = 'delegate';
const SEARCH = 'search';
const SELECTED_EVENTS = 'event_ids[]';
const INCLUDE_CANCELLED = 'show_cancelled';
const SHOW_REGISTRATION_STATUS = 'show_reg_status';
const SHOW_ADMIN_DETAILS = 'show_admin_details';
const ADMIN_STATUS = 'admin_status';
const LEGACY_ADMIN_STATUS = 'status';
Expand All @@ -36,6 +37,7 @@ const DEFAULT_DELEGATE = '';
const DEFAULT_SEARCH = '';
const DEFAULT_ADMIN_STATUS = 'all';
const INCLUDE_CANCELLED_TRUE = 'on';
const SHOW_REGISTRATION_STATUS_TRUE = 'on';
const SHOW_ADMIN_DETAILS_TRUE = 'yes';
const LEGACY_DISPLAY_MODE_ADMIN = 'admin';

Expand Down Expand Up @@ -111,6 +113,7 @@ export const createFilterState = (searchParams) => ({
selectedEvents:
sanitizeEvents(searchParams.getAll(SELECTED_EVENTS)),
shouldIncludeCancelled: searchParams.get(INCLUDE_CANCELLED) === INCLUDE_CANCELLED_TRUE,
shouldShowRegStatus: searchParams.get(SHOW_REGISTRATION_STATUS) === SHOW_REGISTRATION_STATUS_TRUE,
shouldShowAdminDetails: searchParams.get(SHOW_ADMIN_DETAILS) === SHOW_ADMIN_DETAILS_TRUE
|| searchParams.get(DISPLAY_MODE) === LEGACY_DISPLAY_MODE_ADMIN,
adminStatus: sanitizeAdminStatus(
Expand All @@ -130,6 +133,7 @@ export const updateSearchParams = (searchParams, filterState, displayMode) => {
search,
selectedEvents,
shouldIncludeCancelled,
shouldShowRegStatus,
shouldShowAdminDetails,
adminStatus,
} = filterState;
Expand Down Expand Up @@ -185,6 +189,12 @@ export const updateSearchParams = (searchParams, filterState, displayMode) => {
searchParams.delete(INCLUDE_CANCELLED);
}

if (shouldShowRegStatus) {
searchParams.set(SHOW_REGISTRATION_STATUS, SHOW_REGISTRATION_STATUS_TRUE);
} else {
searchParams.delete(SHOW_REGISTRATION_STATUS);
}

if (shouldShowAdminDetails) {
searchParams.set(SHOW_ADMIN_DETAILS, SHOW_ADMIN_DETAILS_TRUE);
} else {
Expand Down
3 changes: 3 additions & 0 deletions app/webpacker/components/CompetitionsOverview/queryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function calculateQueryKey(filterState, canViewAdminDetails = false) {
search: filterState?.search,
time: timeKey,
shouldIncludeCancelled: filterState?.shouldIncludeCancelled,
shouldShowRegStatus: filterState?.shouldShowRegStatus,
adminStatus,
};
}
Expand All @@ -38,6 +39,7 @@ export function createSearchParams(filterState, pageParam, canViewAdminDetails =
customEndDate,
adminStatus,
shouldIncludeCancelled,
shouldShowRegStatus,
} = filterState;

const dateNow = DateTime.now();
Expand All @@ -60,6 +62,7 @@ export function createSearchParams(filterState, pageParam, canViewAdminDetails =
searchParams.append('admin_status', adminStatus);
}
searchParams.append('include_cancelled', shouldIncludeCancelled);
searchParams.append('include_registration_status', shouldShowRegStatus);

if (timeOrder === 'present') {
searchParams.append('sort', 'start_date,end_date,name');
Expand Down
Loading