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

Migrate Records Page to React #10623

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open

Conversation

FinnIckler
Copy link
Member

@FinnIckler FinnIckler commented Jan 14, 2025

Still need to do some of the other table types, but it's very similar to the rankings page
image

@FinnIckler
Copy link
Member Author

image
Here is the slim Table (events are currently not links because the URL is in the other PR)

@FinnIckler
Copy link
Member Author

image
Separate View

@FinnIckler
Copy link
Member Author

Added mixed history and history
image
image

This means this is now feature complete, but there is definitely possibilities of refactors as there is a lot of code reuse

@FinnIckler
Copy link
Member Author

Did a lot of refactoring to reduce code reuse

app/webpacker/components/Results/Records/index.jsx Outdated Show resolved Hide resolved
Comment on lines +84 to +86
useEffect(() => {
window.history.replaceState(null, '', recordsUrl(event, region, gender, show));
}, [event, region, gender, show]);
Copy link
Contributor

Choose a reason for hiding this comment

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

When I navigate around with browser back/forward, I get crashes.

image

I assume this affects the other migration PRs which handle this the same way.

Copy link
Member Author

Choose a reason for hiding this comment

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

It does not do that for me... window.replaceState should just replace the browser bar and not add an entry to it

Copy link
Member

Choose a reason for hiding this comment

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

Sometimes the hot reloading that we enabled semi-recently (like, a few months ago) creates inconsistent state updates like that. Is the error reproducible for you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I opened a fresh local host tab, navigated to my competitions, navigated to records, clicked back (and got to my competitions), clicked forward, and got the error again.

Copy link
Member Author

Choose a reason for hiding this comment

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

still can't reproduce

app/webpacker/components/Results/Records/index.jsx Outdated Show resolved Hide resolved
import { Table } from 'semantic-ui-react';
import I18n from '../../lib/i18n';

const headerConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly confused why there are 4 configs and 4 header components but 5 'show categories'. Probably mixed-history re-uses either mixed or history, but it's not immediate to trace down.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, history and mixed history have the same headers, just with one more column for events so it has the conditional rendering

Copy link
Member

Choose a reason for hiding this comment

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

Chiming in to note that I'd be happy to see a short comment explaining the Array(4).fill('')s. (Probably one comment to explain all of them is enough)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we instead do a single header cell of width 5 (or 3 when appropriate)? FM results don't look nice:

image

);
}

function TableWrapper({ competitionsById, rows, show }) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like how half of the show-based logic is handled here, and half is handled in the children i.e. in RecordsTable. Handling it all in one spot/level is much nicer. And the higher that level is (and the 'dumber' the children are) the better, generally.

Here, it would be best to either have 5 cases/returns here (1 per show, and if some of those components are very similar then they can just reuse common children), or replace the show prop in RecordsTable with resultsAreGroupedByEventId={show !== 'mixed history'} and other props, so that RecordsTable isn't directly aware of show. The latter looks complicated/messy in this case, so I'd go with the former. (I'd be happy to directly contribute commits to the PR if that would be helpful.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Feel free to commit to it!

Copy link
Contributor

Choose a reason for hiding this comment

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

I raised a PR, since I couldn't figure out how to push directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

took me a while, but merged.
Can you not just do
gh pr checkout 10623
and then push to the PR?

Comment on lines +246 to +264
@record_timestamp = ComputeAuxiliaryData.successful_start_date || Date.current

respond_to do |format|
format.html {}
format.json do
cached_data = Rails.cache.fetch ["records-page-api", *@cache_params, @record_timestamp] do
rows = DbHelper.execute_cached_query(@cache_params, @record_timestamp, @query)
comp_ids = rows.map { |r| r["competitionId"] }.uniq
if @is_slim || @is_separate
rows = compute_slim_or_separate_records(rows)
end
competitions_by_id = Competition.where(id: comp_ids).index_by(&:id).transform_values { |comp| comp.as_json(methods: %w[country], include: [], only: %w[cellName id]) }
{
rows: rows.as_json, competitionsById: competitions_by_id
}
end
render json: cached_data
end
end
Copy link
Member

Choose a reason for hiding this comment

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

This snippet should be merged/extracted to a common function once the Rankings page gets merged.

app/controllers/results_controller.rb Show resolved Hide resolved
app/webpacker/components/Results/Records/RecordsTable.jsx Outdated Show resolved Hide resolved
app/webpacker/components/Results/Records/RecordsTable.jsx Outdated Show resolved Hide resolved
import { Table } from 'semantic-ui-react';
import I18n from '../../lib/i18n';

const headerConfig = {
Copy link
Member

Choose a reason for hiding this comment

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

Chiming in to note that I'd be happy to see a short comment explaining the Array(4).fill('')s. (Probably one comment to explain all of them is enough)

Comment on lines +333 to +347
if (region !== 'world') {
queryParams.append('region', region);
}

if (gender !== 'All') {
queryParams.append('gender', gender);
}

if (eventId){
queryParams.append('event_id', eventId)
}

if (show){
queryParams.append('show', show)
}
Copy link
Member

Choose a reason for hiding this comment

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

See my comment on the Rankings PR about redundant-but-not-redundant parameters ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants