-
Notifications
You must be signed in to change notification settings - Fork 187
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
FinnIckler
wants to merge
52
commits into
thewca:main
Choose a base branch
from
FinnIckler:react/records
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+779
−136
Open
Changes from 21 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
bb687c0
WIP transform rankings page to records page
FinnIckler a3195c1
port filter changes from other pr
FinnIckler d781932
fix records API
FinnIckler bd3ca24
add more show variables
FinnIckler 7625d3f
fix after merge
FinnIckler 7d12e2e
use init function
FinnIckler 743750d
implement slim table
FinnIckler c4b7cf5
Merge branch 'main' into react/records
FinnIckler e349987
replace fixed with single line
FinnIckler 85db683
separate view
FinnIckler d47e8ba
history view
FinnIckler b3bf9d2
implement mixed History
FinnIckler a577979
id to query to fix duplicates
FinnIckler f98cedc
refator Headers and Rows
FinnIckler ae217b4
create dynamic header
FinnIckler cbd107c
refactor common cells
FinnIckler f7ce2ba
Merge branch 'main' into react/records
FinnIckler 525da5a
remove unneeded props
FinnIckler 7cabe81
add back accidental deletion of <CountryCell country={country} />
FinnIckler 9c9fa3c
review changes
FinnIckler 91848c1
Merge branch 'main' into react/records
FinnIckler a919edc
Create dedicated component per table type
kr-matthews de9b8ae
Fix default 'show' value
kr-matthews 9ad4b6b
Rename TableWrapper -> RecordsTable
kr-matthews 4f1f346
Add key to SlimRecordsTable
kr-matthews bfa5c44
Add key to RankingTypeTable
kr-matthews ab22328
Add key to HistoryRecordsTable
kr-matthews 898b49a
Use filter in table rendering
kr-matthews 50ac182
Create util file
kr-matthews f345a18
Rename components to reflect mult. tables
kr-matthews a55c885
Remove unnecessary key
kr-matthews 230480d
Rename/simplify tables
kr-matthews b39295c
Create and use RecordsTable
kr-matthews 69a8546
Rename to isMixed
kr-matthews ce63f1b
Formatting
kr-matthews dc4fa9c
add empty results fallback
FinnIckler 3cf7223
add more linebreaks
FinnIckler 348f6e6
add getRegionIdWithFallback
FinnIckler 2914644
add empty results fallback
FinnIckler b60f906
add getRegionIdWithFallback
FinnIckler a11bda1
Merge branch 'kr-matthews-react/records' into react/records
FinnIckler 7ae9c73
lint
FinnIckler ad8b79e
Merge branch 'main' into react/records
gregorbg d8b0cc4
Fix import after merging
gregorbg 0e18de3
Combine 'ResultsFilter' after merge
gregorbg 7ebbca1
Styling: Remove line break from 'All' button
gregorbg 9717007
Show filters table while fetching data
gregorbg e326553
Add cubing icon to sub-table headers
gregorbg a51dfca
Use shared cell models
gregorbg 92ae2be
Add cache iso2 backwards compatibility
gregorbg 7470bf8
Make sure the iso2 fallback is only used wheen necessary
gregorbg d32318a
Merge branch 'main' into react/records
gregorbg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,9 @@ | ||
<% provide(:title, t(".title")) %> | ||
|
||
<% record_timestamp = ComputeAuxiliaryData.successful_start_date || Date.current %> | ||
<% @rows = DbHelper.execute_cached_query(@cache_params, record_timestamp, @query) %> | ||
|
||
<div class="container"> | ||
<h1><%= yield(:title) %></h1> | ||
<p><%= t("results.last_updated_html", timestamp: wca_local_time(record_timestamp)) %></p> | ||
<p><%= t("results.last_updated_html", timestamp: wca_local_time(@record_timestamp)) %></p> | ||
<p><i><%= t('results.filters_fixes_underway') %></i></p> | ||
|
||
<div id="results-selector" class="results-select form-inline"> | ||
<%= render 'results_selector', show_records_options: true %> | ||
</div> | ||
|
||
<% cache [*@cache_params, record_timestamp, I18n.locale] do %> | ||
<% | ||
comp_ids = @rows.map { |r| r["competitionId"] }.uniq | ||
unless @is_slim | ||
@competitions_by_id = Hash[Competition.where(id: comp_ids).map { |c| [c.id, c] }] | ||
end | ||
%> | ||
|
||
<div id="search-results" class="results"> | ||
<div id="results-list"> | ||
<% if @is_mixed %> | ||
<% @rows.group_by { |row| row["eventId"] }.each do |event_id, rows| %> | ||
<% event = Event.c_find(event_id) %> | ||
<h2> | ||
<%= link_to rankings_path(event.id, "single"), class: "plain" do %> | ||
<%= cubing_icon event.id %> | ||
<%= event.name %> | ||
<% end %> | ||
</h2> | ||
<%= render 'records_mixed_table', rows: rows %> | ||
<% end %> | ||
<% elsif @is_slim || @is_separate %> | ||
<% slim_rows, single_rows, average_rows = compute_slim_or_separate_records(@rows) %> | ||
<% if @is_slim %> | ||
<%= render 'records_slim_table', rows: slim_rows %> | ||
<% else %> | ||
<h2> <%= t("results.table_elements.type_options.single") %> </h2> | ||
<%= render 'records_separate_table', rows: single_rows, type: "single" %> | ||
|
||
<h2> <%= t("results.table_elements.type_options.average") %> </h2> | ||
<%= render 'records_separate_table', rows: average_rows, type: "average" %> | ||
<% end %> | ||
<% elsif @is_history %> | ||
<% @rows.group_by { |row| row["eventId"] }.each do |event_id, rows| %> | ||
<% event = Event.c_find(event_id) %> | ||
<h2> | ||
<%= link_to rankings_path(event.id, "single"), class: "plain" do %> | ||
<%= cubing_icon event.id %> | ||
<%= event.name %> | ||
<% end %> | ||
</h2> | ||
<%= render 'records_histories_table', rows: rows %> | ||
<% end %> | ||
<% elsif @is_mixed_history %> | ||
<%= render 'records_histories_table', rows: @rows %> | ||
<% end %> | ||
</div> | ||
</div> | ||
<% end %> | ||
<%= react_component("Results/Records") %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Header, Table } from 'semantic-ui-react'; | ||
import _ from 'lodash'; | ||
import { countries, events } from '../../../lib/wca-data.js.erb'; | ||
import { WCA_EVENT_IDS } from '../../wca/EventSelector'; | ||
import { HistoryRow, RecordRow } from '../TableRows'; | ||
import { HistoryHeader, MixedHeader } from '../TableHeaders'; | ||
|
||
export default function RecordsTable({ | ||
rows, competitionsById, show, | ||
}) { | ||
const results = useMemo(() => { | ||
const r = rows.map((result) => { | ||
const competition = competitionsById[result.competitionId]; | ||
const country = countries.real.find((c) => c.id === result.countryId); | ||
|
||
return { | ||
result, | ||
competition, | ||
country, | ||
key: `${result.id}-${show}-${result.type}`, | ||
}; | ||
}); | ||
if (show !== 'mixed history') { | ||
FinnIckler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return _.groupBy(r, 'result.eventId'); | ||
} | ||
return r; | ||
FinnIckler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, [competitionsById, rows, show]); | ||
return ( | ||
FinnIckler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div style={{ overflowX: 'scroll' }}> | ||
{ show !== 'mixed history' ? WCA_EVENT_IDS.map((id) => Object.keys(results).includes(id) | ||
&& <RecordTable record={results[id]} eventId={id} show={show} />) | ||
: <RecordTable record={results} show={show} />} | ||
</div> | ||
); | ||
} | ||
|
||
function RecordTable({ record, eventId, show }) { | ||
return ( | ||
<> | ||
{ show !== 'mixed history' && <Header>{events.byId[eventId].name}</Header>} | ||
<Table basic="very" compact="very" striped unstackable singleLine> | ||
{ show === 'mixed' ? <MixedHeader /> : <HistoryHeader mixed={show === 'mixed history'} /> } | ||
<Table.Body> | ||
{record.map((r) => (show === 'mixed' ? ( | ||
<RecordRow | ||
country={r.country} | ||
key={r.key} | ||
result={r.result} | ||
competition={r.competition} | ||
rank={r.rank} | ||
tiedPrevious={r.tiedPrevious} | ||
/> | ||
) : ( | ||
<HistoryRow | ||
country={r.country} | ||
key={r.key} | ||
result={r.result} | ||
competition={r.competition} | ||
rank={r.rank} | ||
tiedPrevious={r.tiedPrevious} | ||
mixed={show === 'mixed history'} | ||
/> | ||
)))} | ||
</Table.Body> | ||
</Table> | ||
</> | ||
); | ||
} |
35 changes: 35 additions & 0 deletions
35
app/webpacker/components/Results/Records/SeparateRecordsTable.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
import { Header, Table } from 'semantic-ui-react'; | ||
import I18n from '../../../lib/i18n'; | ||
import { SeparateHeader } from '../TableHeaders'; | ||
import { SeparateRecordsRow } from '../TableRows'; | ||
|
||
export default function SeparateRecordsTable({ rows, competitionsById }) { | ||
const [, singleRecords, averageRecords] = rows; | ||
|
||
return ( | ||
<> | ||
<Header>{I18n.t('results.selector_elements.type_selector.single')}</Header> | ||
<RankingTypeTable records={singleRecords} competitionsById={competitionsById} rankingType="single" /> | ||
<Header>{I18n.t('results.selector_elements.type_selector.average')}</Header> | ||
<RankingTypeTable records={averageRecords} competitionsById={competitionsById} rankingType="average" /> | ||
</> | ||
); | ||
} | ||
|
||
function RankingTypeTable({ records, rankingType, competitionsById }) { | ||
return ( | ||
<Table basic="very" compact="very" striped unstackable singleLine> | ||
<SeparateHeader isAverage={rankingType === 'average'} /> | ||
<Table.Body> | ||
{records.map((row) => ( | ||
<SeparateRecordsRow | ||
rankingType={rankingType} | ||
competition={competitionsById[row.competitionId]} | ||
result={row} | ||
/> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
app/webpacker/components/Results/Records/SlimRecordsTable.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import { Table } from 'semantic-ui-react'; | ||
import { SlimHeader } from '../TableHeaders'; | ||
import { SlimRecordsRow } from '../TableRows'; | ||
|
||
export default function SlimRecordsTable({ rows }) { | ||
return ( | ||
<Table basic="very" compact="very" striped unstackable> | ||
<SlimHeader /> | ||
<Table.Body> | ||
{rows.map((row) => <SlimRecordsRow row={row} />)} | ||
</Table.Body> | ||
</Table> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.