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] Type all references as RefObject #16124

Merged
merged 1 commit into from
Jan 10, 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
Expand Up @@ -50,7 +50,7 @@ export default function ColumnSizingPersistWidthOrder() {
}

const useColumnsState = (
apiRef: React.MutableRefObject<GridApiPro>,
apiRef: React.RefObject<GridApiPro>,
columns: GridColDef[],
) => {
const [widths, setWidths] = React.useState<Record<GridColDef['field'], number>>(
Expand Down
2 changes: 1 addition & 1 deletion docs/data/data-grid/components/CustomColumnsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function ColumnGroup({
}: {
group: GridColumnGroup;
columnLookup: GridColumnLookup;
apiRef: React.MutableRefObject<GridApi>;
apiRef: React.RefObject<GridApi>;
columnVisibilityModel: GridColumnVisibilityModel;
}) {
const leaves = React.useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/data-grid/export/CustomExport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import MenuItem from '@mui/material/MenuItem';
import { ButtonProps } from '@mui/material/Button';

const getJson = (apiRef: React.MutableRefObject<GridApi>) => {
const getJson = (apiRef: React.RefObject<GridApi>) => {
// Select rows and columns
const filteredSortedRowIds = gridFilteredSortedRowIdsSelector(apiRef);
const visibleColumnsField = gridVisibleColumnFieldsSelector(apiRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import {
import { useGridClipboardImport } from '../hooks/features/clipboard/useGridClipboardImport';

export const useDataGridPremiumComponent = (
inputApiRef: React.MutableRefObject<GridApiPremium> | undefined,
inputApiRef: React.RefObject<GridApiPremium> | undefined,
props: DataGridPremiumProcessedProps,
) => {
const apiRef = useGridInitialization<GridPrivateApiPremium, GridApiPremium>(inputApiRef, props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface GridGroupingCriteriaCellIconProps
}

function GridGroupingCriteriaCellIcon(props: GridGroupingCriteriaCellIconProps) {
const apiRef = useGridPrivateApiContext() as React.MutableRefObject<GridPrivateApiPremium>;
const apiRef = useGridPrivateApiContext() as React.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
Expand Up @@ -46,7 +46,7 @@ const GridToolbarPromptControlRoot = styled('div', {
flexDirection: 'row',
});

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

function generateContext(
apiRef: React.MutableRefObject<GridApiPremium>,
apiRef: React.RefObject<GridApiPremium>,
examples?: Record<string, any[]>,
) {
const columns = gridColumnDefinitionsSelector(apiRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { gridAggregationModelSelector } from './gridAggregationSelectors';

const getGroupAggregatedValue = (
groupId: GridRowId,
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.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.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
aggregatedFields: string[],
position: GridAggregationPosition,
) => {
Expand All @@ -123,7 +123,7 @@ export const createAggregationLookup = ({
getAggregationPosition,
isDataSource,
}: {
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
apiRef: React.RefObject<GridPrivateApiPremium>;
aggregationFunctions:
| Record<string, GridAggregationFunction>
| Record<string, GridAggregationFunctionDataSource>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ interface AddFooterRowsParams {
* If `true`, there are some aggregation rules to apply
*/
hasAggregationRule: boolean;
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
apiRef: React.RefObject<GridPrivateApiPremium>;
}

/**
Expand Down Expand Up @@ -265,7 +265,7 @@ export const getAggregationFunctionLabel = ({
apiRef,
aggregationRule,
}: {
apiRef: React.MutableRefObject<GridApiPremium>;
apiRef: React.RefObject<GridApiPremium>;
aggregationRule: GridAggregationRule;
}): string => {
if (aggregationRule.aggregationFunction.label != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const aggregationStateInitializer: GridStateInitializer<
};

export const useGridAggregation = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'onAggregationModelChange'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { GridInitialStatePremium } from '../../../models/gridStatePremium';
import { GridAggregationRules } from './gridAggregationInterfaces';

export const useGridAggregationPreProcessors = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'aggregationFunctions'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface GridColDefWithAggregationWrappers extends GridBaseColDef {
}

type ColumnPropertyWrapper<P extends WrappableColumnProperty> = (params: {
apiRef: React.MutableRefObject<GridApiPremium>;
apiRef: React.RefObject<GridApiPremium>;
value: GridBaseColDef[P];
colDef: GridBaseColDef;
aggregationRule: GridAggregationRule;
Expand Down Expand Up @@ -188,7 +188,7 @@ export const wrapColumnWithAggregationValue = ({
aggregationRule,
}: {
column: GridBaseColDef;
apiRef: React.MutableRefObject<GridApiPremium>;
apiRef: React.RefObject<GridApiPremium>;
aggregationRule: GridAggregationRule;
}): GridBaseColDef => {
const getCellAggregationResult = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CellValueUpdater {
updateRow: (row: GridRowModel) => void;

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

export const useGridClipboardImport = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'pagination'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const options = {
};

export const useGridDataSourcePremium = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: DataGridPremiumProcessedProps,
) => {
const { api, strategyProcessor, events } = useGridDataSourceBase<GridPrivateApiPremium>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ interface SerializedRow {
export const serializeRowUnsafe = (
id: GridRowId,
columns: GridStateColDef[],
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
defaultValueOptionsFormulae: { [field: string]: { address: string } },
options: Pick<BuildExcelOptions, 'escapeFormulas'>,
): SerializedRow => {
Expand Down Expand Up @@ -403,7 +403,7 @@ interface BuildExcelOptions

export async function buildExcel(
options: BuildExcelOptions,
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
): Promise<Excel.Workbook> {
const {
columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { GridExcelExportMenuItem } from '../../../components';
* @requires useGridParamsApi (method)
*/
export const useGridExcelExport = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: DataGridPremiumProps,
): void => {
const logger = useGridLogger(apiRef, 'useGridExcelExport');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
};

interface CreateGroupingColDefSeveralCriteriaParams {
apiRef: React.MutableRefObject<GridApiPremium>;
apiRef: React.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
Expand Up @@ -54,7 +54,7 @@ interface FilterRowTreeFromTreeDataParams {
rowTree: GridRowTreeConfig;
isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
filterModel: GridFilterModel;
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
apiRef: React.RefObject<GridPrivateApiPremium>;
}

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

export const setStrategyAvailability = (
privateApiRef: React.MutableRefObject<GridPrivateApiPremium>,
privateApiRef: React.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.MutableRefObject<GridPrivateApiPremium>;
apiRef: React.RefObject<GridPrivateApiPremium>;
}) => {
let key: GridKeyValue | null | undefined;
if (groupingRule.groupingValueGetter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';

export const useGridDataSourceRowGroupingPreProcessors = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'disableRowGrouping'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const rowGroupingStateInitializer: GridStateInitializer<
* @requires useGridParamsApi (method) - can be after, async only
*/
export const useGridRowGrouping = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'initialState'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import { GridPrivateApiPremium } from '../../../models/gridApiPremium';

export const useGridRowGroupingPreProcessors = (
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
apiRef: React.RefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'disableRowGrouping'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const updateColumnVisibilityModel = (
*/
export const useKeepGroupedColumnsHidden = (
props: {
apiRef: React.MutableRefObject<GridApi>;
apiRef: React.RefObject<GridApi>;
} & Pick<DataGridPremiumProps, 'initialState' | 'rowGroupingModel'>,
) => {
const initialProps = React.useRef(props);
Expand Down
Original file line number Diff line number Diff line change
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.MutableRefObject<GridApiPremium>;
apiRef?: React.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
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export type GridGroupingValueGetter<
value: TValue,
row: R,
column: GridColDef<R>,
apiRef: React.MutableRefObject<GridApiPremium>,
apiRef: React.RefObject<GridApiPremium>,
) => GridKeyValue | null | undefined;
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export type GridPastedValueParser<
value: string,
row: R,
column: GridColDef<R, V, F>,
apiRef: React.MutableRefObject<GridApiPremium>,
apiRef: React.RefObject<GridApiPremium>,
) => V | undefined;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('<DataGrid /> - Quick filter', () => {
columns: [{ field: 'brand' }],
};

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

function TestCase(props: Partial<DataGridProps>) {
apiRef = useGridApiRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const baselineProps: DataGridPremiumProps = {
describe('<DataGridPremium /> - Aggregation', () => {
const { render, clock } = createRenderer({ clock: 'fake' });

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

function Test(props: Partial<DataGridPremiumProps>) {
apiRef = useGridApiRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isJSDOM, describeSkipIf } from 'test/utils/skipIf';
describe('<DataGridPremium /> - Cell selection', () => {
const { render } = createRenderer();

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

function TestDataGridSelection({
rowLength = 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isJSDOM, describeSkipIf } from 'test/utils/skipIf';
describe('<DataGridPremium /> - Clipboard', () => {
const { render } = createRenderer();

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

function Test({
rowLength = 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const isJSDOM = /jsdom/.test(window.navigator.userAgent);
describe('<DataGridPremium /> - Data source aggregation', () => {
const { render } = createRenderer();

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;
let getRowsSpy: SinonSpy;
let mockServer: ReturnType<typeof useMockServer>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const isJSDOM = /jsdom/.test(window.navigator.userAgent);
describe('<DataGridPremium /> - Export Excel', () => {
const { render } = createRenderer();

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

const columns: GridColDef[] = [{ field: 'id' }, { field: 'brand', headerName: 'Brand' }];
const rows = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const baselineProps: BaselineProps = {
describe('<DataGridPremium /> - Row grouping', () => {
const { render, clock } = createRenderer();

let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

function Test(props: Partial<DataGridPremiumProps>) {
apiRef = useGridApiRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('<DataGridPremium /> - Row selection', () => {
const { render } = createRenderer();

describe('props: rowSelectionPropagation = { descendants: true, parents: true }', () => {
let apiRef: React.MutableRefObject<GridApi>;
let apiRef: React.RefObject<GridApi>;

function Test(props: Partial<DataGridPremiumProps>) {
apiRef = useGridApiRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ interface GridTreeDataGroupingCellIconProps
}

function GridTreeDataGroupingCellIcon(props: GridTreeDataGroupingCellIconProps) {
const apiRef = useGridPrivateApiContext() as React.MutableRefObject<GridPrivateApiPro>;
const apiRef = useGridPrivateApiContext() as React.RefObject<GridPrivateApiPro>;
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
Expand Up @@ -51,7 +51,7 @@ export interface GridHeaderFilterCellProps extends Pick<GridStateColDef, 'header
tabIndex: 0 | -1;
width: number;
colDef: GridColDef;
headerFilterMenuRef: React.MutableRefObject<HTMLButtonElement | null>;
headerFilterMenuRef: React.RefObject<HTMLButtonElement | null>;
item: GridFilterItem;
showClearIcon?: boolean;
InputComponentProps: GridFilterOperator['InputComponentProps'];
Expand Down
Loading
Loading