Skip to content

Commit 0cdcb30

Browse files
committed
Placeholder header checkbox menu
1 parent 18f3686 commit 0cdcb30

File tree

3 files changed

+80
-24
lines changed

3 files changed

+80
-24
lines changed

TODO

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
tables should be aware that rows are players who have pids. add bulk/all/select operations at table-level through ... menu
22
- select/unselect all checkbox in the header
33
- states:
4-
- all checked (not just visible)
5-
- show as checked
6-
- some checked (whether visible or not)
7-
- show as indeterminate https://stackoverflow.com/a/6269487/786644
8-
- not checked
9-
- show as unchecked
4+
- all checked (not just visible) -> checked
5+
- some checked (whether visible or not) -> indeterminate https://stackoverflow.com/a/6269487/786644
6+
- not checked -> unchecked
107
- on click, dropdown letting you check all, visible, or clear https://ux.stackexchange.com/a/102463
8+
- make sure click on cell opens menu
119
- ... -> Bulk select players
1210
- if checkboxes are shown by default, still have this to show the "Bulk" button
1311
- replace the "10 per page" menu with a "Bulk actions" dropdown button
@@ -35,8 +33,6 @@ tables should be aware that rows are players who have pids. add bulk/all/select
3533
- first, make a popup appear when you click the link explaining new UI. set reminder to delete eventually
3634
- add to all pages
3735
- places to use
38-
- compare multiple players
39-
- needs to know pid/playoffs/season for each row, could put in metadata
4036
- could be used for places where we already have check boxes - set showBulkSelectCheckboxes to true even if bulkSelectRows is false
4137
- trading block
4238
- trade
@@ -46,10 +42,13 @@ tables should be aware that rows are players who have pids. add bulk/all/select
4642
- ProtectPlayers
4743
- search for other places with checkboxes
4844
- interaction with hideAllControls?
45+
- for multiple watchlists, maybe have it pop up dialog to let you select, rather than cycling
4946
- test
5047
- bulk actions noop with nothing selected
5148
- with supercols
5249
- with col filters showing
50+
- career totals stats page
51+
- all seasons stats page
5352
- blog
5453
- annoying to flag multiple players. compare players links.
5554
- watch list color

src/ui/components/DataTable/BulkActions.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export const BulkActions = ({
6464
<Dropdown.Toggle
6565
id={`datatable-bulk-actions-${name}`}
6666
size="sm"
67-
title="Bulk actions"
6867
variant={hasSomeSelected ? "primary" : "secondary"}
6968
>
7069
Bulk actions

src/ui/components/DataTable/Header.tsx

+73-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import clsx from "clsx";
2-
import { type SyntheticEvent, type MouseEvent, Fragment } from "react";
2+
import {
3+
type SyntheticEvent,
4+
type MouseEvent,
5+
Fragment,
6+
forwardRef,
7+
useRef,
8+
useLayoutEffect,
9+
} from "react";
310
import type { Col, SortBy, SuperCol } from ".";
411
import { range } from "../../../common/utils";
12+
import { Dropdown } from "react-bootstrap";
513

614
const FilterHeader = ({
715
colOrder,
@@ -157,26 +165,78 @@ export const getSortClassName = (sortBys: SortBy[], i: number) => {
157165
return className;
158166
};
159167

160-
const BulkSelectHeaderCheckbox = ({ checked }: { checked: boolean }) => {
161-
const onChange = () => {
162-
console.log("CHANGE");
163-
};
168+
type CheckboxState = "checked" | "unchecked" | "indeterminate";
169+
170+
// forwardRef needed for react-bootstrap types
171+
const CustomToggle = forwardRef(
172+
(
173+
{
174+
children,
175+
onClick,
176+
}: {
177+
children: CheckboxState;
178+
onClick: (event: MouseEvent) => void;
179+
},
180+
ref,
181+
) => {
182+
const inputRef = useRef<HTMLInputElement>(null);
183+
184+
useLayoutEffect(() => {
185+
if (inputRef.current) {
186+
if (children === "indeterminate") {
187+
inputRef.current.indeterminate = true;
188+
} else if (children === "checked") {
189+
inputRef.current.checked = true;
190+
inputRef.current.indeterminate = false;
191+
} else {
192+
inputRef.current.checked = false;
193+
inputRef.current.indeterminate = false;
194+
}
195+
}
196+
}, [children]);
197+
198+
return (
199+
<input
200+
className="form-check-input"
201+
type="checkbox"
202+
onClick={event => {
203+
event.preventDefault();
204+
onClick(event);
205+
}}
206+
ref={element => {
207+
inputRef.current = element;
208+
209+
if (typeof ref === "function") {
210+
ref(element);
211+
} else if (ref) {
212+
ref.current = element;
213+
}
214+
}}
215+
/>
216+
);
217+
},
218+
);
219+
220+
const BulkSelectHeaderCheckbox = () => {
221+
const state: CheckboxState = "indeterminate";
164222

165223
// Similar to singleCheckbox stuff below
166224
const onClickCell = (event: MouseEvent) => {
167225
if (event.target && (event.target as any).tagName === "TH") {
168-
onChange();
226+
console.log("TODO, SHOULD OPEN MENU");
169227
}
170228
};
171229

172230
return (
173231
<th data-no-row-highlight onClick={onClickCell}>
174-
<input
175-
className="form-check-input"
176-
type="checkbox"
177-
checked={checked}
178-
onChange={onChange}
179-
/>
232+
<Dropdown>
233+
<Dropdown.Toggle as={CustomToggle}>{state}</Dropdown.Toggle>
234+
<Dropdown.Menu>
235+
<Dropdown.Item>Select all</Dropdown.Item>
236+
<Dropdown.Item>Select visible</Dropdown.Item>
237+
<Dropdown.Item>Clear</Dropdown.Item>
238+
</Dropdown.Menu>
239+
</Dropdown>
180240
</th>
181241
);
182242
};
@@ -214,9 +274,7 @@ const Header = ({
214274
/>
215275
) : null}
216276
<tr>
217-
{showBulkSelectCheckboxes ? (
218-
<BulkSelectHeaderCheckbox checked={false} />
219-
) : null}
277+
{showBulkSelectCheckboxes ? <BulkSelectHeaderCheckbox /> : null}
220278
{colOrder.map(({ colIndex }) => {
221279
const {
222280
classNames: colClassNames,

0 commit comments

Comments
 (0)