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

[core] Drop useGridContainerProps #3007

Merged
merged 97 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 87 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
a6f0876
[core] Drop useGridContainerProps
flaviendelangle Oct 27, 2021
42a69a6
Fix
flaviendelangle Oct 27, 2021
3389f12
Fix
flaviendelangle Oct 27, 2021
10293d3
Fix
flaviendelangle Oct 27, 2021
6eba4b4
Fix
flaviendelangle Oct 27, 2021
b221921
Work
flaviendelangle Oct 28, 2021
124ffbf
Fix
flaviendelangle Oct 28, 2021
4e1b0d0
Fix
flaviendelangle Oct 28, 2021
e88e40c
Fix
flaviendelangle Oct 28, 2021
f42c3a8
Fix
flaviendelangle Oct 28, 2021
3b2c3bb
Test
flaviendelangle Oct 28, 2021
a13a4c9
Test
flaviendelangle Oct 28, 2021
42afd88
Test
flaviendelangle Oct 28, 2021
9b8a01c
Test
flaviendelangle Oct 28, 2021
19490da
Test
flaviendelangle Oct 28, 2021
9371bb7
Test
flaviendelangle Oct 28, 2021
9166da9
Fix
flaviendelangle Oct 28, 2021
f486d8a
Fix
flaviendelangle Oct 28, 2021
a9a9e85
Fix
flaviendelangle Oct 28, 2021
fe18140
Fix
flaviendelangle Oct 28, 2021
facc7c5
Fix
flaviendelangle Oct 28, 2021
0b17d27
Fix
flaviendelangle Oct 28, 2021
37c0e71
Fix
flaviendelangle Oct 28, 2021
500901d
Fix
flaviendelangle Oct 28, 2021
c715ffc
Fix
flaviendelangle Oct 28, 2021
4b0b1a0
Fix
flaviendelangle Oct 28, 2021
e4567e3
Fix
flaviendelangle Oct 28, 2021
2c52522
Fix
flaviendelangle Oct 28, 2021
d792c87
Clean
flaviendelangle Oct 28, 2021
fb05a97
Fix
flaviendelangle Oct 28, 2021
ed92f6b
Test
flaviendelangle Oct 29, 2021
a002a60
Test
flaviendelangle Oct 29, 2021
5b47ae1
Fix
flaviendelangle Oct 29, 2021
f0fe6bd
Merge branch 'next' into drop-useGridContainerProps
flaviendelangle Nov 1, 2021
7ce4824
Fix api
flaviendelangle Nov 1, 2021
2cd454a
Fix
flaviendelangle Nov 1, 2021
96ebdc5
Fix
flaviendelangle Nov 2, 2021
75c6c7a
Fix
flaviendelangle Nov 2, 2021
7c64b7a
Fix
flaviendelangle Nov 2, 2021
8038ad4
Merge branch 'next' into drop-useGridContainerProps
flaviendelangle Nov 2, 2021
623a6a9
Fix
flaviendelangle Nov 2, 2021
263563a
[DataGrid] Keyboard navigation broken on page > 0
flaviendelangle Nov 2, 2021
5b28789
Add test
flaviendelangle Nov 2, 2021
0cf8e56
Fix
flaviendelangle Nov 2, 2021
e72bdad
Fix
flaviendelangle Nov 2, 2021
da3d747
Fix
flaviendelangle Nov 2, 2021
4777e2b
Fix
flaviendelangle Nov 2, 2021
3758b2c
Fix
flaviendelangle Nov 2, 2021
ed10545
Fix
flaviendelangle Nov 2, 2021
86d2e8d
Fix
flaviendelangle Nov 2, 2021
f3c3405
Merge
flaviendelangle Nov 2, 2021
6439022
Improve
flaviendelangle Nov 2, 2021
2da04df
Fix
flaviendelangle Nov 2, 2021
df7af47
Fix
flaviendelangle Nov 2, 2021
3ba706b
Fix
flaviendelangle Nov 2, 2021
03234df
Code review
flaviendelangle Nov 2, 2021
88da6be
Fix
flaviendelangle Nov 3, 2021
7445fe7
Work
flaviendelangle Nov 3, 2021
f487960
Fix
flaviendelangle Nov 3, 2021
e44c88e
Fix
flaviendelangle Nov 3, 2021
dcbad7e
Fix
flaviendelangle Nov 3, 2021
1420fdc
Fix
flaviendelangle Nov 3, 2021
4b44d5e
Test
flaviendelangle Nov 3, 2021
e02ca01
Test
flaviendelangle Nov 3, 2021
78cec2a
Test
flaviendelangle Nov 3, 2021
a475a7e
Test
flaviendelangle Nov 3, 2021
6a5c1f4
Test
flaviendelangle Nov 3, 2021
af18d83
Merge
flaviendelangle Nov 5, 2021
524764d
Merge
flaviendelangle Nov 8, 2021
c161cc1
Fix
flaviendelangle Nov 8, 2021
ae451ce
Fix
flaviendelangle Nov 8, 2021
17c877d
Fix
flaviendelangle Nov 8, 2021
c781712
Merge branch 'next' into drop-useGridContainerProps
flaviendelangle Nov 8, 2021
0f46ae3
Merge branch 'next' into drop-useGridContainerProps
flaviendelangle Nov 8, 2021
db51360
Fix
flaviendelangle Nov 9, 2021
6d661e2
Work
flaviendelangle Nov 10, 2021
72ec2aa
Work
flaviendelangle Nov 10, 2021
0f72a3d
Merge branch 'next' into drop-useGridContainerProps
flaviendelangle Nov 10, 2021
958abe1
Fix
flaviendelangle Nov 10, 2021
495a585
Code review
flaviendelangle Nov 10, 2021
dbcfc73
Fix
flaviendelangle Nov 10, 2021
6cde81d
Fix
flaviendelangle Nov 10, 2021
a8320d4
Work
flaviendelangle Nov 10, 2021
d5dc0be
New method
flaviendelangle Nov 10, 2021
9f44ccf
Docs
flaviendelangle Nov 10, 2021
1f61628
Fix lint
flaviendelangle Nov 12, 2021
0c7987a
Merge branch 'next' into drop-useGridContainerProps
flaviendelangle Nov 12, 2021
8e0993e
Update packages/grid/_modules_/grid/hooks/features/dimensions/gridDim…
flaviendelangle Nov 15, 2021
94e3d10
Code review
flaviendelangle Nov 15, 2021
84f840b
Fix overlay
flaviendelangle Nov 15, 2021
89a14a3
Work
flaviendelangle Nov 15, 2021
a1887c7
Fix
flaviendelangle Nov 15, 2021
3a0d279
Work
flaviendelangle Nov 16, 2021
bf5b035
Work
flaviendelangle Nov 16, 2021
a45bfcb
Work
flaviendelangle Nov 16, 2021
798f698
Fix
flaviendelangle Nov 16, 2021
d08dd91
Work
flaviendelangle Nov 16, 2021
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
164 changes: 83 additions & 81 deletions docs/pages/api-docs/data-grid/grid-api.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion docs/src/pages/components/data-grid/events/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,9 @@
"name": "stateChange",
"description": "Fired when the state of the grid is updated. Called with a GridState object."
},
{ "name": "unmount", "description": "Fired when the grid is unmounted." }
{ "name": "unmount", "description": "Fired when the grid is unmounted." },
{
"name": "viewportInnerSizeChange",
"description": "Fired when the inner size of the viewport changes. Called with an ElementSize object."
}
]
11 changes: 5 additions & 6 deletions packages/grid/_modules_/grid/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
import { GridComponentProps } from '../GridComponentProps';
import { GridStateColDef } from '../models/colDef/gridColDef';
import { GridCellIdentifier } from '../hooks/features/focus/gridFocusState';
import { GridScrollBarState } from '../models/gridContainerProps';
import { gridColumnsMetaSelector } from '../hooks/features/columns/gridColumnsSelector';
import { useGridSelector } from '../hooks/utils/useGridSelector';

Expand All @@ -31,7 +30,6 @@ export interface GridRowProps {
cellFocus: GridCellIdentifier | null;
cellTabIndex: GridCellIdentifier | null;
editRowsState: GridEditRowsModel;
scrollBarState: GridScrollBarState;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onDoubleClick?: React.MouseEventHandler<HTMLDivElement>;
}
Expand Down Expand Up @@ -79,7 +77,6 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {
cellFocus,
cellTabIndex,
editRowsState,
scrollBarState, // to be removed
onClick,
onDoubleClick,
...other
Expand All @@ -88,6 +85,10 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const columnsMeta = useGridSelector(apiRef, gridColumnsMetaSelector);
const { hasScrollX, hasScrollY } = apiRef.current.getRootDimensions() ?? {
hasScrollX: false,
hasScrollY: false,
};

const ownerState = {
selected,
Expand Down Expand Up @@ -141,8 +142,7 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {
const indexRelativeToAllColumns = firstColumnToRender + i;

const isLastColumn = indexRelativeToAllColumns === visibleColumns.length - 1;
const removeLastBorderRight =
isLastColumn && scrollBarState.hasScrollX && !scrollBarState.hasScrollY;
const removeLastBorderRight = isLastColumn && hasScrollX && !hasScrollY;
const showRightBorder = !isLastColumn
? rootProps.showCellRightBorder
: !removeLastBorderRight && rootProps.disableExtendRowFullWidth;
Expand Down Expand Up @@ -256,7 +256,6 @@ GridRow.propTypes = {
row: PropTypes.object.isRequired,
rowHeight: PropTypes.number.isRequired,
rowId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
scrollBarState: PropTypes.object.isRequired,
selected: PropTypes.bool.isRequired,
visibleColumns: PropTypes.arrayOf(PropTypes.object).isRequired,
} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ interface GridColumnHeaderItemProps {
sortIndex?: number;
filterItemsCounter?: number;
hasFocus?: boolean;
hasScrollX: boolean;
hasScrollY: boolean;
tabIndex: 0 | -1;
}

Expand Down Expand Up @@ -79,8 +77,6 @@ function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
filterItemsCounter,
hasFocus,
tabIndex,
hasScrollX,
hasScrollY,
extendRowFullWidth,
} = props;
const apiRef = useGridApiContext();
Expand All @@ -89,6 +85,10 @@ function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
const columnMenuId = useId();
const columnMenuButtonId = useId();
const iconButtonRef = React.useRef<HTMLButtonElement>(null);
const { hasScrollX, hasScrollY } = apiRef.current.getRootDimensions() ?? {
hasScrollX: false,
hasScrollY: false,
};

let headerComponent: React.ReactNode = null;
if (column.renderHeader) {
Expand Down Expand Up @@ -250,8 +250,6 @@ GridColumnHeaderItem.propTypes = {
extendRowFullWidth: PropTypes.bool.isRequired,
filterItemsCounter: PropTypes.number,
hasFocus: PropTypes.bool,
hasScrollX: PropTypes.bool.isRequired,
hasScrollY: PropTypes.bool.isRequired,
headerHeight: PropTypes.number.isRequired,
isDragging: PropTypes.bool.isRequired,
isLastColumn: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { styled } from '@mui/material/styles';
import { getDataGridUtilityClass } from '../../gridClasses';
import { useGridRootProps } from '../../hooks/utils/useGridRootProps';
import { GridComponentProps } from '../../GridComponentProps';
import { useGridSelector } from '../../hooks/utils/useGridSelector';
import { unstable_gridScrollBarSizeSelector } from '../../hooks/features/container/gridContainerSizesSelector';
import { useGridApiContext } from '../../hooks/utils/useGridApiContext';
import { gridClasses } from '../..';

Expand Down Expand Up @@ -57,11 +55,10 @@ export const GridColumnHeadersInner = React.forwardRef<HTMLDivElement, GridColum
const { isDragging, className, ...other } = props;
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const scrollBarState = useGridSelector(apiRef, unstable_gridScrollBarSizeSelector);

const ownerState = {
isDragging,
hasScrollX: scrollBarState.hasScrollX,
hasScrollX: apiRef.current.getRootDimensions()?.hasScrollX ?? false,
classes: rootProps.classes,
};
const classes = useUtilityClasses(ownerState);
Expand Down
4 changes: 4 additions & 0 deletions packages/grid/_modules_/grid/constants/eventsConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export enum GridEvents {
* Fired when the grid is resized with a debounced time of 60ms. Called with a [[ElementSize]] object.
*/
debouncedResize = 'debouncedResize',
/**
* Fired when the inner size of the viewport changes. Called with an [[ElementSize]] object.
*/
viewportInnerSizeChange = 'viewportInnerSizeChange',
/**
* Fired when an exception is thrown in the grid.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
visibleGridColumnsSelector,
gridColumnsMetaSelector,
} from '../columns/gridColumnsSelector';
import { unstable_gridScrollBarSizeSelector } from '../container/gridContainerSizesSelector';
import {
gridTabIndexColumnHeaderSelector,
gridTabIndexCellSelector,
Expand Down Expand Up @@ -36,7 +35,6 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
const apiRef = useGridApiContext();
const visibleColumns = useGridSelector(apiRef, visibleGridColumnsSelector);
const columnsMeta = useGridSelector(apiRef, gridColumnsMetaSelector);
const scrollBarState = useGridSelector(apiRef, unstable_gridScrollBarSizeSelector);
const tabIndexState = useGridSelector(apiRef, gridTabIndexColumnHeaderSelector);
const cellTabIndexState = useGridSelector(apiRef, gridTabIndexCellSelector);
const columnHeaderFocus = useGridSelector(apiRef, gridFocusColumnHeaderSelector);
Expand Down Expand Up @@ -173,8 +171,6 @@ export const useGridColumnHeaders = (props: UseGridColumnHeadersProps) => {
isResizing={resizeCol === column.field}
isLastColumn={columnIndex === columns.length - 1}
extendRowFullWidth={!rootProps.disableExtendRowFullWidth}
hasScrollX={scrollBarState.hasScrollX}
hasScrollY={scrollBarState.hasScrollY}
hasFocus={hasFocus}
tabIndex={tabIndex}
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ const upsertColumnsState = (columnUpdates: GridColDef[], prevColumnsState?: Grid
/**
* @requires useGridColumnsPreProcessing (method)
* @requires useGridParamsApi (method)
* @requires useGridContainerProps (state)
* @requires useGridDimensions (method, event) - can be after
* TODO: Impossible priority - useGridParamsApi also needs to be after useGridColumns
* TODO: Impossible priority - useGridContainerProps also needs to be after useGridColumns
*/
export function useGridColumns(
apiRef: GridApiRef,
Expand Down Expand Up @@ -153,11 +152,6 @@ export function useGridColumns(
});
const [, setGridState, forceUpdate] = useGridState(apiRef);

// On the first render, `useGridContainerProps` has not yet initialized its state because it is called after `useGridColumns`
// But it viewport width would always be 0 on the 1st render since the DOM Node is not mounted yet, so we can provide a safe fallback here
// TODO: Fix when removing `viewportSizes` from the state
const viewportSizes = apiRef.current.state.viewportSizes?.width ?? 0;

const setGridColumnsState = React.useCallback(
(columnsState: GridColumnsState, emit = true) => {
logger.debug('Updating columns state.');
Expand Down Expand Up @@ -211,12 +205,11 @@ export function useGridColumns(

const setColumnsState = React.useCallback(
(newState: RawGridColumnsState, emit?: boolean) => {
const dimensions = apiRef.current.getRootDimensions();
logger.debug('updating GridColumns with new state');

// Avoid dependency on gridState to avoid infinite loop
const viewportWidth = apiRef.current.state.viewportSizes.width;
let newColumns: GridColumns = newState.all.map((field) => newState.lookup[field]);
newColumns = hydrateColumnsWidth(newColumns, viewportWidth);
newColumns = hydrateColumnsWidth(newColumns, dimensions?.viewportInnerSize.width ?? 0);

const columnState: GridColumnsState = {
all: newColumns.map((col) => col.field),
Expand Down Expand Up @@ -341,19 +334,6 @@ export function useGridColumns(
setColumnsState(columnState);
}, [logger, apiRef, setColumnsState, props.columns, props.columnTypes]);

React.useEffect(() => {
logger.debug(`GridColumns gridState.viewportSizes.width, changed ${viewportSizes}`);

// This hook is meant to update the column's width when the viewport changes
// We can skip the whole block if the width is missing
if (viewportSizes === 0) {
return;
}

// Avoid dependency on gridState as I only want to update cols when viewport size changed.
setColumnsState(apiRef.current.state.columns);
}, [apiRef, setColumnsState, viewportSizes, logger]);

const handlePreProcessorRegister = React.useCallback(
(name) => {
if (name !== GridPreProcessingGroup.hydrateColumns) {
Expand All @@ -373,7 +353,16 @@ export function useGridColumns(
[apiRef, logger, setColumnsState, props.columns, props.columnTypes],
);

const prevInnerWidth = React.useRef<number | null>(null);
const handleGridSizeChange = (viewportInnerSize) => {
if (prevInnerWidth.current !== viewportInnerSize.width) {
prevInnerWidth.current = viewportInnerSize.width;
setColumnsState(apiRef.current.state.columns);
}
};

useGridApiEventHandler(apiRef, GridEvents.preProcessorRegister, handlePreProcessorRegister);
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);

// Grid Option Handlers
useGridApiOptionHandler(
Expand Down

This file was deleted.

Loading