Skip to content

Commit d4efb2c

Browse files
maxidragongregorbg
andauthored
Fix dates in competitions admin view (#10682)
* Fix dates in competitions admin view * Slim down report serialization to base model --------- Co-authored-by: Gregor Billing <[email protected]>
1 parent 4d8b5f6 commit d4efb2c

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

app/controllers/api/v0/competitions_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def competition_index
2929
serial_includes = {}
3030

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

3434
paginate json: competitions,
3535
only: ["id", "name", "start_date", "end_date", "registration_open", "registration_close", "venue"],

app/models/competition.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,10 @@ def report_posted_at
838838
delegate_report&.posted_at
839839
end
840840

841+
def report_posted_by_user
842+
delegate_report&.posted_by_user_id
843+
end
844+
841845
# This callback updates all tables having the competition id, when the id changes.
842846
# This should be deleted after competition id is made immutable: https://github.com/thewca/worldcubeassociation.org/pull/381
843847
after_save :update_foreign_keys, if: :saved_change_to_id?

app/webpacker/components/CompetitionsOverview/ListViewSection.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import {
1616
isProbablyOver,
1717
PseudoLinkMarkdown,
1818
reportAdminCellContent,
19+
resultsSubmittedAtAdminCellContent,
1920
startYear,
20-
timeDifferenceAfter,
2121
timeDifferenceBefore,
2222
} from '../../lib/utils/competition-table';
2323
import { countries } from '../../lib/wca-data.js.erb';
@@ -390,11 +390,7 @@ function AdminCompetitionsTable({
390390
warning={resultsPostedStatus === 'warning'}
391391
error={resultsPostedStatus === 'danger'}
392392
>
393-
{
394-
comp.results_posted_at
395-
? timeDifferenceAfter(comp, comp.results_posted_at)
396-
: (isProbablyOver(comp) && I18n.t('competitions.competition_info.pending'))
397-
}
393+
{resultsSubmittedAtAdminCellContent(comp)}
398394
</Table.Cell>
399395
<Table.Cell collapsing>
400396
<Button

app/webpacker/lib/utils/competition-table.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ export function reportAdminCellContent(comp) {
118118
return null;
119119
}
120120

121+
export function resultsSubmittedAtAdminCellContent(comp) {
122+
if (comp.results_posted_at) {
123+
const date = comp.results_submitted_at ? comp.results_submitted_at : comp.results_posted_at;
124+
return timeDifferenceAfter(comp, date);
125+
}
126+
127+
if (isProbablyOver(comp)) {
128+
return I18n.t('competitions.competition_info.pending');
129+
}
130+
131+
return null;
132+
}
133+
121134
function lookupStatus(numOfDays, statusMap, compareFn, defaultStatus = null) {
122135
if (!Number.isInteger(numOfDays)) {
123136
return defaultStatus;

0 commit comments

Comments
 (0)