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

Custom tables 2 #406

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export { default as gameAttributeHasHistory } from "./gameAttributeHasHistory";
export { default as gameAttributesArrayToObject } from "./gameAttributesArrayToObject";
export { default as getAdjustedTicketPrice } from "./getAdjustedTicketPrice";
export { default as getDraftLotteryProbs } from "./getDraftLotteryProbs";
export { default as getCols } from "./getCols";
export { default as getCols } from "../ui/util/columns/getCols";
export { default as getPeriodName } from "./getPeriodName";
export { default as helpers } from "./helpers";
export { default as isSport } from "./isSport";
Expand Down
1 change: 1 addition & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,7 @@ export type UpdateEvents = (
| "account"
| "allStarDunk"
| "allStarThree"
| "customizeTable"
| "firstRun"
| "g.goatFormula"
| "gameAttributes"
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/BoxScore.basketball.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const StatsTable = ({
}) => {
const [sortBys, setSortBys] = useState<SortBy[]>([]);

const onClick = (event: MouseEvent, i: number) => {
const onClick = (event: MouseEvent, colKey: string) => {
setSortBys(prevSortBys => {
const newSortBys =
updateSortBys({
cols,
event,
i,
colKey,
prevSortBys,
}) ?? [];

Expand Down
21 changes: 11 additions & 10 deletions src/ui/components/BoxScore.football.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const StatsHeader = ({
sortable,
}: {
cols: Col[];
onClick: (b: MouseEvent, a: number) => void;
onClick: (b: MouseEvent, a: string) => void;
sortBys: SortBy[];
sortable: boolean;
}) => {
Expand All @@ -59,7 +59,7 @@ export const StatsHeader = ({
className={className}
key={i}
onClick={event => {
onClick(event, i);
onClick(event, col.key);
}}
title={desc}
>
Expand All @@ -78,7 +78,7 @@ export const sortByStats = (
) => {
return (a: any, b: any) => {
for (const [index, order] of sortBys) {
const stat = stats[index];
const stat = index.includes(":") ? index.split(":")[1] : index;

const aValue = getValue?.(a, stat) ?? a.processed[stat];
const bValue = getValue?.(b, stat) ?? b.processed[stat];
Expand Down Expand Up @@ -109,20 +109,21 @@ const StatsTableIndividual = ({

const [sortBys, setSortBys] = useState(() => {
return PLAYER_GAME_STATS[type].sortBy.map(
stat => [stats.indexOf(stat), "desc"] as SortBy,
stat => [`stat:${stat}`, "desc"] as SortBy,
);
});

const onClick = (event: MouseEvent, i: number) => {
setSortBys(
prevSortBys =>
const onClick = (event: MouseEvent, colKey: string) => {
setSortBys(prevSortBys => {
return (
updateSortBys({
cols,
event,
i,
colKey,
prevSortBys,
}) ?? [],
);
}) ?? []
);
});
};

const players = t.players
Expand Down
15 changes: 8 additions & 7 deletions src/ui/components/BoxScore.hockey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,21 @@ const StatsTable = ({

const [sortBys, setSortBys] = useState(() => {
return PLAYER_GAME_STATS[type].sortBy.map(
stat => [stats.indexOf(stat), "desc"] as SortBy,
stat => [`stat:${stat}`, "desc"] as SortBy,
);
});

const onClick = (event: MouseEvent, i: number) => {
setSortBys(
prevSortBys =>
const onClick = (event: MouseEvent, colKey: string) => {
setSortBys(prevSortBys => {
return (
updateSortBys({
cols,
event,
i,
colKey,
prevSortBys,
}) ?? [],
);
}) ?? []
);
});
};

const players = t.players
Expand Down
10 changes: 7 additions & 3 deletions src/ui/components/DataTable/Controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const style = {

const Controls = ({
enableFilters,
enableCustomizeColumns,
hideAllControls,
name,
onExportCSV,
Expand All @@ -25,6 +26,7 @@ const Controls = ({
searchText,
}: {
enableFilters: boolean;
enableCustomizeColumns: boolean;
hideAllControls?: boolean;
name: string;
onExportCSV: () => void;
Expand Down Expand Up @@ -130,9 +132,11 @@ const Controls = ({
<span className="glyphicon glyphicon-option-vertical text-muted" />
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item onClick={onSelectColumns}>
Customize Columns
</Dropdown.Item>
{enableCustomizeColumns ? (
<Dropdown.Item onClick={onSelectColumns}>
Customize Columns
</Dropdown.Item>
) : null}
<Dropdown.Item onClick={onExportCSV}>
Download Spreadsheet
</Dropdown.Item>
Expand Down
Loading