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

Fix dates in competitions admin view #10682

Merged
merged 3 commits into from
Jan 28, 2025
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
2 changes: 1 addition & 1 deletion app/controllers/api/v0/competitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def competition_index
serial_includes = {}

serial_includes["delegates"] = { only: ["id", "name"], methods: [], include: ["avatar"] } if admin_mode
serial_methods |= ["results_submitted_at", "report_posted_at"] if admin_mode
serial_methods |= ["results_submitted_at", "results_posted_at", "report_posted_at", "report_posted_by_user"] if admin_mode

paginate json: competitions,
only: ["id", "name", "start_date", "end_date", "registration_open", "registration_close", "venue"],
Expand Down
4 changes: 4 additions & 0 deletions app/models/competition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,10 @@ def report_posted_at
delegate_report&.posted_at
end

def report_posted_by_user
delegate_report&.posted_by_user_id
end

# This callback updates all tables having the competition id, when the id changes.
# This should be deleted after competition id is made immutable: https://github.com/thewca/worldcubeassociation.org/pull/381
after_save :update_foreign_keys, if: :saved_change_to_id?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
isProbablyOver,
PseudoLinkMarkdown,
reportAdminCellContent,
resultsSubmittedAtAdminCellContent,
startYear,
timeDifferenceAfter,
timeDifferenceBefore,
} from '../../lib/utils/competition-table';
import { countries } from '../../lib/wca-data.js.erb';
Expand Down Expand Up @@ -390,11 +390,7 @@ function AdminCompetitionsTable({
warning={resultsPostedStatus === 'warning'}
error={resultsPostedStatus === 'danger'}
>
{
comp.results_posted_at
? timeDifferenceAfter(comp, comp.results_posted_at)
: (isProbablyOver(comp) && I18n.t('competitions.competition_info.pending'))
}
{resultsSubmittedAtAdminCellContent(comp)}
</Table.Cell>
<Table.Cell collapsing>
<Button
Expand Down
13 changes: 13 additions & 0 deletions app/webpacker/lib/utils/competition-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ export function reportAdminCellContent(comp) {
return null;
}

export function resultsSubmittedAtAdminCellContent(comp) {
if (comp.results_posted_at) {
const date = comp.results_submitted_at ? comp.results_submitted_at : comp.results_posted_at;
return timeDifferenceAfter(comp, date);
}

if (isProbablyOver(comp)) {
return I18n.t('competitions.competition_info.pending');
}

return null;
}

function lookupStatus(numOfDays, statusMap, compareFn, defaultStatus = null) {
if (!Number.isInteger(numOfDays)) {
return defaultStatus;
Expand Down