Skip to content

Commit 58e2216

Browse files
committed
Shuffle column def code around
1 parent 5372707 commit 58e2216

File tree

5 files changed

+219
-223
lines changed

5 files changed

+219
-223
lines changed

app/webpacker/components/Results/Rankings/RankingsTable.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
regionColumn,
1414
representingColumn,
1515
resultsFiveWideColumn,
16-
} from '../TableRows';
16+
} from '../TableColumns';
1717

1818
function getCountryOrContinent(result, firstContinentIndex, firstCountryIndex, index) {
1919
if (index < firstContinentIndex) {

app/webpacker/components/Results/Records/RecordsTable.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { Segment } from 'semantic-ui-react';
33
import React from 'react';
44
import { getRecords } from '../api/records';
55
import Loading from '../../Requests/Loading';
6-
import { augmentApiResults } from './utils';
76
import GroupedEventsTable from './GroupedEventsTable';
87
import GroupedRankingTypesTable from './GroupedRankingTypesTable';
98
import {
9+
augmentApiResults,
1010
historyConfig,
1111
mixedRecordsConfig,
1212
separateRecordsConfig,
1313
slimConfig,
14-
} from '../TableRows';
14+
} from './utils';
1515
import DataTable from '../DataTable';
1616

1717
function SlimRecordsTable({ results }) {

app/webpacker/components/Results/Records/utils.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1+
import { DateTime } from 'luxon';
2+
import React from 'react';
13
import { countries } from '../../../lib/wca-data.js.erb';
4+
import I18n from '../../../lib/i18n';
5+
import {
6+
EventCell,
7+
PersonCell,
8+
} from '../TableCells';
9+
import { formatAttemptResult } from '../../../lib/wca-live/attempts';
10+
import {
11+
attemptResultColumn,
12+
competitionColumn,
13+
personColumn,
14+
regionColumn,
15+
resultsFiveWideColumn,
16+
eventColumn,
17+
} from '../TableColumns';
218

319
export function augmentResults(results, competitionsById) {
420
return results.map((result) => {
@@ -34,3 +50,100 @@ export function augmentApiResults(data, show) {
3450

3551
return augmentResults(rows, competitionsById);
3652
}
53+
54+
export const slimConfig = [
55+
{
56+
accessorKey: 'single.personName',
57+
header: I18n.t('results.table_elements.name'),
58+
cell: ({ row, getValue }) => (
59+
<PersonCell
60+
personId={row.original.single.personId}
61+
personName={getValue()}
62+
/>
63+
),
64+
},
65+
{
66+
accessorKey: 'single.value',
67+
header: I18n.t('common.single'),
68+
cell: ({ row, getValue }) => formatAttemptResult(getValue(), row.original.single.eventId),
69+
},
70+
{
71+
accessorKey: 'single.eventId',
72+
header: I18n.t('results.table_elements.event'),
73+
cell: ({ getValue }) => <EventCell eventId={getValue()} />,
74+
},
75+
{
76+
accessorKey: 'average.value',
77+
header: I18n.t('common.average'),
78+
cell: ({ row, getValue }) => (
79+
getValue() && formatAttemptResult(getValue(), row.original.average?.eventId)
80+
),
81+
},
82+
{
83+
accessorKey: 'average.personName',
84+
header: I18n.t('results.table_elements.name'),
85+
cell: ({ row, getValue }) => getValue && (
86+
<PersonCell
87+
personId={row.original.average?.personId}
88+
personName={getValue()}
89+
/>
90+
),
91+
},
92+
{
93+
...resultsFiveWideColumn,
94+
accessorKey: 'average',
95+
},
96+
];
97+
98+
export const separateRecordsConfig = (rankingType) => [
99+
eventColumn,
100+
attemptResultColumn,
101+
personColumn,
102+
regionColumn,
103+
competitionColumn,
104+
rankingType === 'average' && resultsFiveWideColumn,
105+
].filter(Boolean);
106+
107+
export const historyConfig = (isMixed) => [
108+
{
109+
accessorKey: 'result.start_date',
110+
header: I18n.t('results.table_elements.date_circa'),
111+
cell: ({ getValue }) => DateTime.fromISO(getValue()).toFormat('MMM dd, yyyy'),
112+
},
113+
isMixed && eventColumn,
114+
personColumn,
115+
{
116+
id: 'single',
117+
accessorKey: 'result.value',
118+
header: I18n.t('common.single'),
119+
cell: ({ row, getValue }) => (
120+
row.original.result.type === 'single'
121+
&& formatAttemptResult(getValue(), row.original.result.eventId)
122+
),
123+
},
124+
{
125+
id: 'average',
126+
accessorKey: 'result.value',
127+
header: I18n.t('common.average'),
128+
cell: ({ row, getValue }) => (
129+
row.original.result.type === 'average'
130+
&& formatAttemptResult(getValue(), row.original.result.eventId)
131+
),
132+
},
133+
regionColumn,
134+
competitionColumn,
135+
resultsFiveWideColumn,
136+
].filter(Boolean);
137+
138+
export const mixedRecordsConfig = [
139+
{
140+
accessorKey: 'result.type',
141+
header: I18n.t('results.selector_elements.type_selector.type'),
142+
cell: ({ getValue }) => I18n.t(`results.selector_elements.type_selector.${getValue()}`),
143+
},
144+
personColumn,
145+
attemptResultColumn,
146+
regionColumn,
147+
competitionColumn,
148+
resultsFiveWideColumn,
149+
];
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React from 'react';
2+
import _ from 'lodash';
3+
import { formatAttemptResult } from '../../lib/wca-live/attempts';
4+
import I18n from '../../lib/i18n';
5+
import { countries } from '../../lib/wca-data.js.erb';
6+
import {
7+
AttemptsCells,
8+
CompetitionCell,
9+
CountryCell,
10+
EventCell,
11+
PersonCell,
12+
} from './TableCells';
13+
14+
function resultAttempts(result) {
15+
const attempts = [result?.value1, result?.value2, result?.value3, result?.value4, result?.value5]
16+
.filter(Boolean);
17+
18+
const bestResult = _.max(attempts);
19+
const worstResult = _.min(attempts);
20+
21+
const bestResultIndex = attempts.indexOf(bestResult);
22+
const worstResultIndex = attempts.indexOf(worstResult);
23+
24+
return [attempts, bestResultIndex, worstResultIndex];
25+
}
26+
27+
export const resultsFiveWideColumn = {
28+
accessorKey: 'result',
29+
header: I18n.t('results.table_elements.solves'),
30+
colSpan: 5,
31+
isMultiAttemptsHack: true,
32+
cell: ({ getValue }) => {
33+
const result = getValue();
34+
35+
const [attempts, bestResultIndex, worstResultIndex] = resultAttempts(result);
36+
37+
return (
38+
<AttemptsCells
39+
attempts={attempts}
40+
bestResultIndex={bestResultIndex}
41+
worstResultIndex={worstResultIndex}
42+
eventId={result.eventId}
43+
/>
44+
);
45+
},
46+
};
47+
48+
export const competitionColumn = {
49+
accessorKey: 'competition',
50+
header: I18n.t('results.table_elements.competition'),
51+
cell: ({ getValue }) => (
52+
<CompetitionCell
53+
competition={getValue()}
54+
compatIso2={countries.byId[getValue().countryId]?.iso2}
55+
/>
56+
),
57+
};
58+
59+
export const regionColumn = {
60+
accessorKey: 'country',
61+
header: I18n.t('results.table_elements.region'),
62+
cell: ({ getValue }) => (
63+
<CountryCell country={getValue()} />
64+
),
65+
};
66+
67+
export const representingColumn = {
68+
accessorKey: 'country',
69+
header: I18n.t('results.table_elements.region'),
70+
cell: ({ getValue }) => (
71+
<CountryCell country={getValue()} />
72+
),
73+
};
74+
75+
export const attemptResultColumn = {
76+
accessorKey: 'result.value',
77+
header: I18n.t('results.table_elements.result'),
78+
cell: ({ row, getValue }) => formatAttemptResult(getValue(), row.original.result.eventId),
79+
};
80+
81+
export const personColumn = {
82+
accessorKey: 'result.personName',
83+
header: I18n.t('results.table_elements.name'),
84+
cell: ({ row, getValue }) => (
85+
<PersonCell
86+
personId={row.original.result.personId}
87+
personName={getValue()}
88+
/>
89+
),
90+
};
91+
92+
export const eventColumn = {
93+
accessorKey: 'result.eventId',
94+
header: I18n.t('results.table_elements.event'),
95+
cell: ({ getValue }) => <EventCell eventId={getValue()} />,
96+
};
97+
98+
export const rankColumn = {
99+
accessorKey: 'rank',
100+
header: '#',
101+
textAlign: 'center',
102+
cell: ({ getValue }) => getValue(),
103+
};

0 commit comments

Comments
 (0)