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

Shift key to select rows for annul queue #2812

Merged
merged 5 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions src/components/PaginatedTable/PaginatedTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface PaginatedTableProperties<RawEntryT, GroomedEntryT = RawEntryT> {
onRowClick?: (
row: GroomedEntryT,
ev: React.MouseEvent | React.TouchEvent | React.PointerEvent,
rows: GroomedEntryT[],
) => any;
debug?: boolean;
pageSizeOptions?: Array<number>;
Expand All @@ -63,7 +64,7 @@ interface PaginatedTableProperties<RawEntryT, GroomedEntryT = RawEntryT> {
hidePageControls?: boolean;
/** If provided, the table will listen for this push event and refresh its data accordingly */
uiPushProps?: { event: string; channel: string };
annulQueue?: any[];
highlightedRows?: any[];
}

export interface PaginatedTableRef {
Expand Down Expand Up @@ -355,40 +356,21 @@ function _PaginatedTable<RawEntryT = any, GroomedEntryT = RawEntryT>(
{column_render(column, row)}
</td>
));
if (props.annulQueue) {
if (props.onRowClick) {
return (
<tr
key={row.id}
className={
props.annulQueue.includes(row) ? "queued" : ""
}
onMouseUp={(ev) =>
props.onRowClick && props.onRowClick(row, ev)
}
>
{cols}
</tr>
);
} else {
return <tr key={row.id}>{cols}</tr>;
}
} else {
if (props.onRowClick) {
return (
<tr
key={row.id}
onMouseUp={(ev) =>
props.onRowClick && props.onRowClick(row, ev)
}
>
{cols}
</tr>
);
} else {
return <tr key={row.id}>{cols}</tr>;
}
}
return (
<tr
key={row.id}
className={
props.highlightedRows && props.highlightedRows.includes(row)
? "queued"
: ""
}
onMouseUp={(ev) =>
props.onRowClick && props.onRowClick(row, ev, rows)
}
>
{cols}
</tr>
);
})}
{blank_rows}
</tbody>
Expand Down
22 changes: 20 additions & 2 deletions src/views/User/GameHistoryTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,27 @@ export function GameHistoryTable(props: GameHistoryProps) {
function handleRowClick(
row: GroomedGame,
ev: React.MouseEvent | React.TouchEvent | React.PointerEvent,
rows: GroomedGame[],
) {
if (row.annulled) {
return;
}

if (selectModeActive) {
toggleQueued(row);
if (ev.shiftKey) {
if (annulQueue.at(-1)) {
window.getSelection()?.removeAllRanges();
const indexes = [
rows.findIndex((r) => r.id === annulQueue.at(-1).id),
rows.findIndex((r) => r.id === row.id),
];
const minIndex = Math.min(...indexes);
const maxIndex = Math.max(...indexes);
setAnnulQueue(rows.slice(minIndex, maxIndex + 1).filter((r) => !r.annulled));
}
} else {
toggleQueued(row);
}
} else {
openUrlIfALinkWasNotClicked(ev, row.href);
}
Expand Down Expand Up @@ -336,7 +354,7 @@ export function GameHistoryTable(props: GameHistoryProps) {
groom={game_history_groomer}
pageSizeOptions={[10, 15, 25, 50]}
onRowClick={handleRowClick}
annulQueue={annulQueue}
highlightedRows={annulQueue}
columns={[
{
header: _("User"),
Expand Down
Loading