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

[DataGrid] Revert apiRef to be MutableRefObject for React versions < 19 #16279

Merged
merged 4 commits into from
Jan 24, 2025
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
useGridInitialization,
useGridInitializeState,
Expand Down Expand Up @@ -96,7 +96,7 @@ import {
import { useGridClipboardImport } from '../hooks/features/clipboard/useGridClipboardImport';

export const useDataGridPremiumComponent = (
inputApiRef: React.RefObject<GridApiPremium> | undefined,
inputApiRef: RefObject<GridApiPremium> | undefined,
props: DataGridPremiumProcessedProps,
) => {
const apiRef = useGridInitialization<GridPrivateApiPremium, GridApiPremium>(inputApiRef, props);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import Box from '@mui/material/Box';
import { useGridPrivateApiContext } from '@mui/x-data-grid-pro/internals';
Expand Down Expand Up @@ -38,7 +39,7 @@ interface GridGroupingCriteriaCellIconProps
}

function GridGroupingCriteriaCellIcon(props: GridGroupingCriteriaCellIconProps) {
const apiRef = useGridPrivateApiContext() as React.RefObject<GridPrivateApiPremium>;
const apiRef = useGridPrivateApiContext() as RefObject<GridPrivateApiPremium>;
const rootProps = useGridRootProps();
const classes = useUtilityClasses(rootProps);
const { rowNode, id, field, descendantCount } = props;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { styled } from '@mui/material/styles';
import composeClasses from '@mui/utils/composeClasses';
import useEventCallback from '@mui/utils/useEventCallback';
Expand Down Expand Up @@ -46,7 +47,7 @@ const GridToolbarPromptControlRoot = styled('div', {
flexDirection: 'row',
});

function sampleData(apiRef: React.RefObject<GridApiPremium>) {
function sampleData(apiRef: RefObject<GridApiPremium>) {
const columns = gridColumnDefinitionsSelector(apiRef);
const rows = Object.values(gridRowsLookupSelector(apiRef));
const columnExamples: Record<string, any[]> = {};
Expand All @@ -64,10 +65,7 @@ function sampleData(apiRef: React.RefObject<GridApiPremium>) {
return columnExamples;
}

function generateContext(
apiRef: React.RefObject<GridApiPremium>,
examples?: Record<string, any[]>,
) {
function generateContext(apiRef: RefObject<GridApiPremium>, examples?: Record<string, any[]>) {
const columns = gridColumnDefinitionsSelector(apiRef);
const columnsContext = columns.map((column) => ({
field: column.field,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
gridColumnLookupSelector,
gridFilteredRowsLookupSelector,
Expand All @@ -22,7 +22,7 @@ import { gridAggregationModelSelector } from './gridAggregationSelectors';

const getGroupAggregatedValue = (
groupId: GridRowId,
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
aggregationRowsScope: DataGridPremiumProcessedProps['aggregationRowsScope'],
aggregatedFields: string[],
aggregationRules: GridAggregationRules,
Expand Down Expand Up @@ -98,7 +98,7 @@ const getGroupAggregatedValue = (

const getGroupAggregatedValueDataSource = (
groupId: GridRowId,
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
aggregatedFields: string[],
position: GridAggregationPosition,
) => {
Expand All @@ -123,7 +123,7 @@ export const createAggregationLookup = ({
getAggregationPosition,
isDataSource,
}: {
apiRef: React.RefObject<GridPrivateApiPremium>;
apiRef: RefObject<GridPrivateApiPremium>;
aggregationFunctions:
| Record<string, GridAggregationFunction>
| Record<string, GridAggregationFunctionDataSource>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { unstable_capitalize as capitalize } from '@mui/utils';
import { GRID_ID_AUTOGENERATED } from '@mui/x-data-grid/internals';
import {
Expand Down Expand Up @@ -140,7 +140,7 @@ interface AddFooterRowsParams {
* If `true`, there are some aggregation rules to apply
*/
hasAggregationRule: boolean;
apiRef: React.RefObject<GridPrivateApiPremium>;
apiRef: RefObject<GridPrivateApiPremium>;
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ export const getAggregationFunctionLabel = ({
apiRef,
aggregationRule,
}: {
apiRef: React.RefObject<GridApiPremium>;
apiRef: RefObject<GridApiPremium>;
aggregationRule: GridAggregationRule;
}): string => {
if (aggregationRule.aggregationFunction.label != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
gridColumnLookupSelector,
useGridApiEventHandler,
Expand Down Expand Up @@ -38,7 +39,7 @@ export const aggregationStateInitializer: GridStateInitializer<
};

export const useGridAggregation = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'onAggregationModelChange'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { gridColumnLookupSelector } from '@mui/x-data-grid-pro';
import {
GridPipeProcessor,
Expand All @@ -22,7 +23,7 @@ import { GridInitialStatePremium } from '../../../models/gridStatePremium';
import { GridAggregationRules } from './gridAggregationInterfaces';

export const useGridAggregationPreProcessors = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'aggregationFunctions'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { GridColDef, GridFilterOperator, GridRowId } from '@mui/x-data-grid-pro';
import { GridBaseColDef } from '@mui/x-data-grid-pro/internals';
import { GridApiPremium } from '../../../models/gridApiPremium';
Expand Down Expand Up @@ -31,7 +32,7 @@ interface GridColDefWithAggregationWrappers extends GridBaseColDef {
}

type ColumnPropertyWrapper<P extends WrappableColumnProperty> = (params: {
apiRef: React.RefObject<GridApiPremium>;
apiRef: RefObject<GridApiPremium>;
value: GridBaseColDef[P];
colDef: GridBaseColDef;
aggregationRule: GridAggregationRule;
Expand Down Expand Up @@ -188,7 +189,7 @@ export const wrapColumnWithAggregationValue = ({
aggregationRule,
}: {
column: GridBaseColDef;
apiRef: React.RefObject<GridApiPremium>;
apiRef: RefObject<GridApiPremium>;
aggregationRule: GridAggregationRule;
}): GridBaseColDef => {
const getCellAggregationResult = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import ownerDocument from '@mui/utils/ownerDocument';
import useEventCallback from '@mui/utils/useEventCallback';
import {
Expand Down Expand Up @@ -49,7 +50,7 @@ const AUTO_SCROLL_SENSITIVITY = 50; // The distance from the edge to start scrol
const AUTO_SCROLL_SPEED = 20; // The speed to scroll once the mouse enters the sensitivity area

export const useGridCellSelection = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'cellSelection'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
GridColDef,
GridRowId,
Expand Down Expand Up @@ -89,7 +90,7 @@ class CellValueUpdater {
updateRow: (row: GridRowModel) => void;

options: {
apiRef: React.RefObject<GridPrivateApiPremium>;
apiRef: RefObject<GridPrivateApiPremium>;
processRowUpdate: DataGridPremiumProcessedProps['processRowUpdate'];
onProcessRowUpdateError: DataGridPremiumProcessedProps['onProcessRowUpdateError'];
getRowId: DataGridPremiumProcessedProps['getRowId'];
Expand Down Expand Up @@ -212,7 +213,7 @@ function defaultPasteResolver({
paginationMode,
}: {
pastedData: string[][];
apiRef: React.RefObject<GridApiPremium>;
apiRef: RefObject<GridApiPremium>;
updateCell: CellValueUpdater['updateCell'];
pagination: DataGridPremiumProcessedProps['pagination'];
paginationMode: DataGridPremiumProcessedProps['paginationMode'];
Expand Down Expand Up @@ -321,7 +322,7 @@ function defaultPasteResolver({
}

export const useGridClipboardImport = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'pagination'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
useGridApiEventHandler as addEventHandler,
useGridApiMethod,
Expand Down Expand Up @@ -28,7 +29,7 @@ const options = {
};

export const useGridDataSourcePremium = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: DataGridPremiumProcessedProps,
) => {
const { api, strategyProcessor, events } = useGridDataSourceBase<GridPrivateApiPremium>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type * as Excel from 'exceljs';
import { RefObject } from '@mui/x-internals/types';
import {
GridRowId,
GridColDef,
Expand Down Expand Up @@ -66,7 +67,7 @@ interface SerializedRow {
export const serializeRowUnsafe = (
id: GridRowId,
columns: GridStateColDef[],
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
defaultValueOptionsFormulae: { [field: string]: { address: string } },
options: Pick<BuildExcelOptions, 'escapeFormulas'>,
): SerializedRow => {
Expand Down Expand Up @@ -403,7 +404,7 @@ interface BuildExcelOptions

export async function buildExcel(
options: BuildExcelOptions,
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
): Promise<Excel.Workbook> {
const {
columns,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
useGridApiMethod,
useGridLogger,
Expand Down Expand Up @@ -36,7 +37,7 @@ import { GridExcelExportMenuItem } from '../../../components';
* @requires useGridParamsApi (method)
*/
export const useGridExcelExport = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: DataGridPremiumProps,
): void => {
const logger = useGridLogger(apiRef, 'useGridExcelExport');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
GRID_STRING_COL_DEF,
GridColDef,
Expand Down Expand Up @@ -264,7 +265,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
};

interface CreateGroupingColDefSeveralCriteriaParams {
apiRef: React.RefObject<GridApiPremium>;
apiRef: RefObject<GridApiPremium>;
columnsLookup: GridColumnRawLookup;
/**
* The fields from which we are grouping the rows.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
GridRowId,
GridRowTreeConfig,
Expand Down Expand Up @@ -54,7 +54,7 @@ interface FilterRowTreeFromTreeDataParams {
rowTree: GridRowTreeConfig;
isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
filterModel: GridFilterModel;
apiRef: React.RefObject<GridPrivateApiPremium>;
apiRef: RefObject<GridPrivateApiPremium>;
}

/**
Expand Down Expand Up @@ -196,7 +196,7 @@ export const mergeStateWithRowGroupingModel =
});

export const setStrategyAvailability = (
privateApiRef: React.RefObject<GridPrivateApiPremium>,
privateApiRef: RefObject<GridPrivateApiPremium>,
disableRowGrouping: boolean,
dataSource?: GridDataSource,
) => {
Expand Down Expand Up @@ -224,7 +224,7 @@ export const getCellGroupingCriteria = ({
row: GridRowModel;
colDef: GridColDef;
groupingRule: GridGroupingRule;
apiRef: React.RefObject<GridPrivateApiPremium>;
apiRef: RefObject<GridPrivateApiPremium>;
}) => {
let key: GridKeyValue | null | undefined;
if (groupingRule.groupingValueGetter) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import { GridRowId, gridRowTreeSelector, gridColumnLookupSelector } from '@mui/x-data-grid-pro';
import {
GridStrategyProcessor,
Expand All @@ -16,7 +17,7 @@ import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';

export const useGridDataSourceRowGroupingPreProcessors = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'disableRowGrouping'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
GridEventListener,
useGridApiEventHandler,
Expand Down Expand Up @@ -51,7 +52,7 @@ export const rowGroupingStateInitializer: GridStateInitializer<
* @requires useGridParamsApi (method) - can be after, async only
*/
export const useGridRowGrouping = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'initialState'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
gridColumnLookupSelector,
GridRowId,
Expand Down Expand Up @@ -40,7 +41,7 @@ import {
import { GridPrivateApiPremium } from '../../../models/gridApiPremium';

export const useGridRowGroupingPreProcessors = (
apiRef: React.RefObject<GridPrivateApiPremium>,
apiRef: RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'disableRowGrouping'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
GridApi,
GridColumnVisibilityModel,
Expand Down Expand Up @@ -36,7 +37,7 @@ const updateColumnVisibilityModel = (
*/
export const useKeepGroupedColumnsHidden = (
props: {
apiRef: React.RefObject<GridApi>;
apiRef: RefObject<GridApi>;
} & Pick<DataGridPremiumProps, 'initialState' | 'rowGroupingModel'>,
) => {
const initialProps = React.useRef(props);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import { RefObject } from '@mui/x-internals/types';
import {
GridCallbackDetails,
GridValidRowModel,
Expand Down Expand Up @@ -129,7 +129,7 @@ export interface DataGridPremiumPropsWithoutDefaultValue<R extends GridValidRowM
/**
* The ref object that allows grid manipulation. Can be instantiated with `useGridApiRef()`.
*/
apiRef?: React.RefObject<GridApiPremium>;
apiRef?: RefObject<GridApiPremium>;
/**
* The initial state of the DataGridPremium.
* The data in it is set in the state on initialization but isn't controlled.
Expand Down
Loading
Loading