Skip to content

Commit

Permalink
[DataGrid] Rename API method (mui#4148)
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw authored Mar 10, 2022
1 parent 1ac64ba commit 37766c8
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/pages/api-docs/data-grid/grid-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { GridApi } from '@mui/x-data-grid-pro';
| <span class="prop-name">getRowElement</span> | <span class="prop-type">(id: GridRowId) =&gt; HTMLDivElement \| null</span> | Gets the underlying DOM element for a row at the given `id`. |
| <span class="prop-name">getRowIdFromRowIndex</span> | <span class="prop-type">(index: number) =&gt; GridRowId</span> | Gets the `GridRowId` of a row at a specific index.<br />The index is based on the sorted but unfiltered row list. |
| <span class="prop-name">getRowIndex</span> | <span class="prop-type">(id: GridRowId) =&gt; number</span> | Gets the row index of a row with a given id.<br />The index is based on the sorted but unfiltered row list. |
| <span class="prop-name">getRowIndexRelativeToCurrentPage</span> | <span class="prop-type">(id: GridRowId) =&gt; number</span> | Gets the index of a row relative to the rows that are visible in the current page. |
| <span class="prop-name">getRowIndexRelativeToVisibleRows</span> | <span class="prop-type">(id: GridRowId) =&gt; number</span> | Gets the index of a row relative to the rows that are reachable by scroll. |
| <span class="prop-name">getRowMode</span> | <span class="prop-type">(id: GridRowId) =&gt; GridRowMode</span> | Gets the mode of a row. |
| <span class="prop-name">getRowModels</span> | <span class="prop-type">() =&gt; Map&lt;GridRowId, GridRowModel&gt;</span> | Gets the full set of rows as Map&lt;GridRowId, GridRowModel&gt;. |
| <span class="prop-name">getRowNode</span> | <span class="prop-type">(id: GridRowId) =&gt; GridRowTreeNodeConfig \| null</span> | Gets the row node from the internal tree structure. |
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/data-grid/grid-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { GridApi } from '@mui/x-data-grid-pro';
| <span class="prop-name">getRowElement</span> | <span class="prop-type">(id: GridRowId) =&gt; HTMLDivElement \| null</span> | Gets the underlying DOM element for a row at the given `id`. |
| <span class="prop-name">getRowIdFromRowIndex</span> | <span class="prop-type">(index: number) =&gt; GridRowId</span> | Gets the `GridRowId` of a row at a specific index.<br />The index is based on the sorted but unfiltered row list. |
| <span class="prop-name">getRowIndex</span> | <span class="prop-type">(id: GridRowId) =&gt; number</span> | Gets the row index of a row with a given id.<br />The index is based on the sorted but unfiltered row list. |
| <span class="prop-name">getRowIndexRelativeToCurrentPage</span> | <span class="prop-type">(id: GridRowId) =&gt; number</span> | Gets the index of a row relative to the rows that are visible in the current page. |
| <span class="prop-name">getRowIndexRelativeToVisibleRows</span> | <span class="prop-type">(id: GridRowId) =&gt; number</span> | Gets the index of a row relative to the rows that are reachable by scroll. |
| <span class="prop-name">getRowMode</span> | <span class="prop-type">(id: GridRowId) =&gt; GridRowMode</span> | Gets the mode of a row. |
| <span class="prop-name">getRowModels</span> | <span class="prop-type">() =&gt; Map&lt;GridRowId, GridRowModel&gt;</span> | Gets the full set of rows as Map&lt;GridRowId, GridRowModel&gt;. |
| <span class="prop-name">getRowNode</span> | <span class="prop-type">(id: GridRowId) =&gt; GridRowTreeNodeConfig \| null</span> | Gets the row node from the internal tree structure. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const DataGridProVirtualScroller = React.forwardRef<
const content = detailPanelsContent[id];

// Check if the id exists in the current page
const rowIndex = apiRef.current.getRowIndexRelativeToCurrentPage(id);
const rowIndex = apiRef.current.getRowIndexRelativeToVisibleRows(id);
const exists = rowIndex !== undefined;

if (React.isValidElement(content) && exists) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
gridVisibleColumnDefinitionsSelector,
gridRowsMetaSelector,
} from '@mui/x-data-grid';
import { useCurrentPageRows } from '@mui/x-data-grid/internals';
import { useGridVisibleRows } from '@mui/x-data-grid/internals';
import { GridRowScrollEndParams } from '../../../models';
import { GridApiPro } from '../../../models/gridApiPro';
import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
Expand All @@ -28,7 +28,7 @@ export const useGridInfiniteLoader = (
>,
): void => {
const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
const currentPage = useCurrentPageRows(apiRef, props);
const currentPage = useGridVisibleRows(apiRef, props);
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
const contentHeight = Math.max(rowsMeta.currentPageTotalHeight, 1);

Expand Down
4 changes: 2 additions & 2 deletions packages/grid/x-data-grid/src/components/GridRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { GridCellIdentifier } from '../hooks/features/focus/gridFocusState';
import { gridColumnsTotalWidthSelector } from '../hooks/features/columns/gridColumnsSelector';
import { useGridSelector } from '../hooks/utils/useGridSelector';
import { GridRowClassNameParams } from '../models/params/gridRowParams';
import { useCurrentPageRows } from '../hooks/utils/useCurrentPageRows';
import { useGridVisibleRows } from '../hooks/utils/useGridVisibleRows';
import { findParentElementFromClassName } from '../utils/domUtils';
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../colDef/gridCheckboxSelectionColDef';
import { GRID_ACTIONS_COLUMN_TYPE } from '../colDef/gridActionsColDef';
Expand Down Expand Up @@ -106,7 +106,7 @@ function GridRow(props: React.HTMLAttributes<HTMLDivElement> & GridRowProps) {
const ariaRowIndex = index + 2; // 1 for the header row and 1 as it's 1-based
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const currentPage = useCurrentPageRows(apiRef, rootProps);
const currentPage = useGridVisibleRows(apiRef, rootProps);
const columnsTotalWidth = useGridSelector(apiRef, gridColumnsTotalWidthSelector);
const { hasScrollX, hasScrollY } = apiRef.current.getRootDimensions() ?? {
hasScrollX: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { GridDimensions, GridDimensionsApi } from './gridDimensionsApi';
import { gridColumnsTotalWidthSelector } from '../columns';
import { gridDensityHeaderHeightSelector, gridDensityRowHeightSelector } from '../density';
import { useGridSelector } from '../../utils';
import { getCurrentPageRows } from '../../utils/useCurrentPageRows';
import { getVisibleRows } from '../../utils/useGridVisibleRows';
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';

const isTestEnvironment = process.env.NODE_ENV === 'test';
Expand Down Expand Up @@ -158,7 +158,7 @@ export function useGridDimensions(
return 0;
}

const currentPage = getCurrentPageRows(apiRef, {
const currentPage = getVisibleRows(apiRef, {
pagination: props.pagination,
paginationMode: props.paginationMode,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useGridLogger } from '../../utils/useGridLogger';
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
import { gridVisibleSortedRowEntriesSelector } from '../filter/gridFilterSelector';
import { useCurrentPageRows } from '../../utils/useCurrentPageRows';
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../colDef/gridCheckboxSelectionColDef';
import { gridClasses } from '../../../constants/gridClasses';

Expand All @@ -27,7 +27,7 @@ export const useGridKeyboardNavigation = (
props: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>,
): void => {
const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
const currentPage = useCurrentPageRows(apiRef, props);
const currentPage = useGridVisibleRows(apiRef, props);

const goToCell = React.useCallback(
(colIndex: number, rowIndex: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from './gridRowsSelector';
import { GridSignature, useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
import { GridStateInitializer } from '../../utils/useGridInitializeState';
import { useCurrentPageRows } from '../../utils/useCurrentPageRows';
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
import {
GridRowsInternalCacheState,
GridRowInternalCacheValue,
Expand Down Expand Up @@ -145,7 +145,7 @@ export const useGridRows = (

const logger = useGridLogger(apiRef, 'useGridRows');
const rowsCache = React.useRef(apiRef.current.state.rowsCache); // To avoid listing rowsCache as useEffect dep
const currentPage = useCurrentPageRows(apiRef, props);
const currentPage = useGridVisibleRows(apiRef, props);

const getRow = React.useCallback<GridRowApi['getRow']>(
(id) => gridRowsLookupSelector(apiRef)[id] ?? null,
Expand All @@ -161,7 +161,7 @@ export const useGridRows = (
[currentPage.rows],
);

const getRowIndexRelativeToCurrentPage = React.useCallback((id) => lookup[id], [lookup]);
const getRowIndexRelativeToVisibleRows = React.useCallback((id) => lookup[id], [lookup]);

const throttledRowsChange = React.useCallback(
(newState: GridRowsInternalCacheState, throttle: boolean) => {
Expand Down Expand Up @@ -403,7 +403,7 @@ export const useGridRows = (
updateRows,
setRowChildrenExpansion,
getRowNode,
getRowIndexRelativeToCurrentPage,
getRowIndexRelativeToVisibleRows,
};

useGridApiMethod(apiRef, rowApi, 'GridRowApi');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
import { GridRowsMetaApi } from '../../../models/api/gridRowsMetaApi';
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
import { useCurrentPageRows } from '../../utils/useCurrentPageRows';
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
import { useGridApiMethod } from '../../utils/useGridApiMethod';
import { GridRowId } from '../../../models/gridRows';
import { useGridSelector } from '../../utils/useGridSelector';
Expand Down Expand Up @@ -45,7 +45,7 @@ export const useGridRowsMeta = (
const filterState = useGridSelector(apiRef, gridFilterStateSelector);
const paginationState = useGridSelector(apiRef, gridPaginationSelector);
const sortingState = useGridSelector(apiRef, gridSortingStateSelector);
const currentPage = useCurrentPageRows(apiRef, props);
const currentPage = useGridVisibleRows(apiRef, props);

const hydrateRowsMeta = React.useCallback(() => {
apiRef.current.setState((state) => {
Expand Down Expand Up @@ -75,7 +75,7 @@ export const useGridRowsMeta = (
const initialHeights: Record<string, number> = { base: baseRowHeight };

if (getRowSpacing) {
const index = apiRef.current.getRowIndexRelativeToCurrentPage(row.id);
const index = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);

const spacing = getRowSpacing({
...row,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { gridVisibleSortedRowIdsSelector } from '../filter/gridFilterSelector';
import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
import { GridCellModes } from '../../../models/gridEditRowModel';
import { isKeyboardEvent } from '../../../utils/keyboardUtils';
import { getCurrentPageRows } from '../../utils/useCurrentPageRows';
import { getVisibleRows } from '../../utils/useGridVisibleRows';
import { GridStateInitializer } from '../../utils/useGridInitializeState';
import { GridSelectionModel } from '../../../models';

Expand Down Expand Up @@ -457,7 +457,7 @@ export const useGridSelection = (
const currentSelection = gridSelectionStateSelector(apiRef.current.state);

if (!canHaveMultipleSelection && currentSelection.length > 1) {
const { rows: currentPageRows } = getCurrentPageRows(apiRef, {
const { rows: currentPageRows } = getVisibleRows(apiRef, {
pagination,
paginationMode,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { gridDensityRowHeightSelector } from '../density/densitySelector';
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
import { gridEditRowsStateSelector } from '../editRows/gridEditRowsSelector';
import { useCurrentPageRows } from '../../utils/useCurrentPageRows';
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
import { GridEventListener, GridEvents } from '../../../models/events';
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
import { clamp } from '../../../utils/utils';
Expand Down Expand Up @@ -73,7 +73,7 @@ export const useGridVirtualScroller = (props: UseGridVirtualScrollerProps) => {
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
const editRowsState = useGridSelector(apiRef, gridEditRowsStateSelector);
const selectedRowsLookup = useGridSelector(apiRef, selectedIdsLookupSelector);
const currentPage = useCurrentPageRows(apiRef, rootProps);
const currentPage = useGridVisibleRows(apiRef, rootProps);
const renderZoneRef = React.useRef<HTMLDivElement>(null);
const rootRef = React.useRef<HTMLDivElement>(null);
const handleRef = useForkRef<HTMLDivElement>(ref, rootRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { gridVisibleSortedRowEntriesSelector } from '../features/filter/gridFilterSelector';
import type { GridApiCommon, GridRowEntry } from '../../models';

export const getCurrentPageRows = <Api extends GridApiCommon>(
export const getVisibleRows = <Api extends GridApiCommon>(
apiRef: React.MutableRefObject<Api>,
props: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>,
) => {
Expand All @@ -30,16 +30,17 @@ export const getCurrentPageRows = <Api extends GridApiCommon>(
};

/**
* Compute the list of the rows in the current page
* - If the pagination is disabled or in server mode, it equals all the visible rows
* - If the row tree has several layers, it contains up to `state.pageSize` top level rows and all their descendants
* - If the row tree is flat, it only contains up to `state.pageSize` rows
* Computes the list of rows that are reachable by scroll.
* Depending on whether pagination is enabled, it will return the rows in the current page.
* - If the pagination is disabled or in server mode, it equals all the visible rows.
* - If the row tree has several layers, it contains up to `state.pageSize` top level rows and all their descendants.
* - If the row tree is flat, it only contains up to `state.pageSize` rows.
*/
export const useCurrentPageRows = <Api extends GridApiCommon>(
export const useGridVisibleRows = <Api extends GridApiCommon>(
apiRef: React.MutableRefObject<Api>,
props: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>,
) => {
const response = getCurrentPageRows(apiRef, props);
const response = getVisibleRows(apiRef, props);

return React.useMemo(
() => ({
Expand Down
Loading

0 comments on commit 37766c8

Please sign in to comment.