Skip to content

Commit

Permalink
feat: infinite tree (#23)
Browse files Browse the repository at this point in the history
* feat: adjustments for restoring column state

* chore: remove comments

* fix: undefined array

* fix: weird bug

* fix: try to debug weird bug

* fix: weird bug debugging

* fix: debug weird ag grid issue

* fix: debug ag grid bug

* fix: debug weird bug

* fix: try to debug weird production only glitch

* fix: suppressDragLeaveHidesColumns adjustment

* fix: try to fix weird order bug

* fix: more adjustments

* feat: add sort feature to columns

* fix: improvements in sort columns feature

* feat: improve restoring scroll position in infinite tables

* feat: performance issues

* feat: add hook useWhyDidYouRender

* feat: improve rerenders

* feat: more adjustmetns

* feat: work in selecting all rows

* feat: changes in selection

* fix: getRows out of sync

* fix: ditch unused hook

* fix: rendering glitch solved

* fix: adjust block sizes for performance

* fix: adjust few things in infinite table

* fix: more tweaks and adjustments in infinite table
  • Loading branch information
mguellsegarra authored Sep 26, 2024
1 parent ac636e9 commit 57c328d
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 296 deletions.
101 changes: 50 additions & 51 deletions src/components/InfiniteTable/HeaderCheckbox.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import React, { memo, useEffect } from "react";
import React, { memo, useEffect, useCallback } from "react";

interface HeaderCheckboxCompProps {
value: boolean | null;
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
}

const HeaderCheckboxComp = memo(
({
value,
onChange,
}: {
value: boolean | null;
onChange: (value: boolean | null) => void;
}) => {
const checkboxRef = React.useRef();
({ value, onChange }: HeaderCheckboxCompProps) => {
const checkboxRef = React.useRef<HTMLInputElement>(null);

useEffect(() => {
const cbRef = checkboxRef.current as any;

if (value === true) {
cbRef.checked = true;
cbRef.indeterminate = false;
} else if (value === false) {
cbRef.checked = false;
cbRef.indeterminate = false;
} else if (value === null) {
cbRef.checked = false;
cbRef.indeterminate = true;
const cbRef = checkboxRef.current;
if (cbRef) {
if (value === true) {
cbRef.checked = true;
cbRef.indeterminate = false;
} else if (value === false) {
cbRef.checked = false;
cbRef.indeterminate = false;
} else if (value === null) {
cbRef.checked = false;
cbRef.indeterminate = true;
}
}
});
}, [value]);

const handleChange = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
onChange(event);
},
[onChange],
);

return (
<input
Expand All @@ -37,9 +44,10 @@ const HeaderCheckboxComp = memo(
onDoubleClick={(e) => {
e.stopPropagation();
}}
ref={checkboxRef as any}
ref={checkboxRef}
type="checkbox"
onChange={onChange as any}
onChange={handleChange}
checked={value === true}
tabIndex={-1}
/>
);
Expand All @@ -48,40 +56,31 @@ const HeaderCheckboxComp = memo(

HeaderCheckboxComp.displayName = "HeaderCheckboxComp";

interface HeaderCheckboxProps {
selectedRowKeysLength: number;
totalRows: number;
onSelectionCheckboxClicked?: (
event: React.ChangeEvent<HTMLInputElement>,
) => void;
}

export const HeaderCheckbox = memo(
({
selectedRowKeysLength,
totalRows,
allRowSelected,
onHeaderCheckboxChange,
allRowSelectedMode,
}: {
selectedRowKeysLength: number;
totalRows: number;
allRowSelected: boolean;
onHeaderCheckboxChange: (value: boolean | null) => void;
allRowSelectedMode: boolean;
}) => {
const noRowsSelected = selectedRowKeysLength === 0;
const someRowsSelected =
selectedRowKeysLength > 0 && totalRows !== selectedRowKeysLength;

let value: boolean | null = false;

if (allRowSelectedMode) {
value = true;
} else if (totalRows === selectedRowKeysLength && totalRows > 0) {
value = true;
} else if (allRowSelected) {
value = true;
} else if (noRowsSelected) {
value = false;
} else if (someRowsSelected) {
value = null;
}
onSelectionCheckboxClicked,
}: HeaderCheckboxProps) => {
const value = React.useMemo(() => {
if (selectedRowKeysLength === 0) return false;
if (selectedRowKeysLength === totalRows && totalRows > 0) return true;
return null;
}, [selectedRowKeysLength, totalRows]);

return (
<HeaderCheckboxComp value={value} onChange={onHeaderCheckboxChange} />
<HeaderCheckboxComp
value={value}
onChange={onSelectionCheckboxClicked!}
/>
);
},
);
Expand Down
Loading

0 comments on commit 57c328d

Please sign in to comment.