Skip to content
Open
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 @@ -15,6 +15,7 @@ import {
isObject,
isSingleSelectColDef,
gridHasColSpanSelector,
throwMissingRowError,
} from '@mui/x-data-grid/internals';
import { warnOnce } from '@mui/x-internals/warning';
import type { ColumnsStylesInterface, GridExcelExportOptions } from '../gridExcelExportInterface';
Expand Down Expand Up @@ -82,7 +83,7 @@ export const serializeRowUnsafe = (
const row = apiRef.current.getRow(id);
const rowNode = apiRef.current.getRowNode(id);
if (!row || !rowNode) {
throw new Error(`MUI X: No row with id #${id} found`);
throwMissingRowError(id);
}
const outlineLevel = rowNode.depth;
const hasColSpan = gridHasColSpanSelector(apiRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useGridRowsOverridableMethodsCommunity,
useGridRowsOverridableMethodsPro,
useGridSelector,
throwMissingRowError,
type ReorderExecutionContext,
} from '@mui/x-data-grid-pro/internals';
import type { RefObject } from '@mui/x-internals/types';
Expand Down Expand Up @@ -43,11 +44,11 @@ export const useGridRowsOverridableMethods = (
const targetNode = gridRowNodeSelector(apiRef, targetRowId);

if (!sourceNode) {
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
throwMissingRowError(sourceRowId);
}

if (!targetNode) {
throw new Error(`MUI X: No row with id #${targetRowId} found.`);
throwMissingRowError(targetRowId);
}

if (sourceNode.type === 'footer') {
Expand Down Expand Up @@ -104,7 +105,7 @@ export const useGridRowsOverridableMethods = (
const sourceNode = gridRowNodeSelector(apiRef, sourceRowId);

if (!sourceNode) {
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
throwMissingRowError(sourceRowId);
}

if (sourceNode.type === 'footer') {
Expand Down
4 changes: 4 additions & 0 deletions packages/x-data-grid/src/hooks/features/rows/gridRowsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { gridRowNodeSelector } from './gridRowsSelector';
export const GRID_ROOT_GROUP_ID: GridRowId = `auto-generated-group-node-root`;
export const GRID_ID_AUTOGENERATED = Symbol('mui.id_autogenerated');

export function throwMissingRowError(id: GridRowId): never {
throw new Error(`MUI X: No row with id #${id} found.`);
}

export const buildRootGroup = (): GridGroupNode => ({
type: 'group',
id: GRID_ROOT_GROUP_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFo
import type { DataGridProcessedProps } from '../../../models/props/DataGridProps';
import { gridListColumnSelector } from '../listView/gridListViewSelectors';
import { gridRowNodeSelector } from './gridRowsSelector';
import { throwMissingRowError } from './gridRowsUtils';
import type { GridConfiguration } from '../../../models/configuration/gridConfiguration';

Comment on lines +17 to 19
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a valid concern. Please change the returned error to the original one.

class MissingRowIdError extends Error {}

/**
* @requires useGridColumns (method)
* @requires useGridRows (method)
Expand All @@ -44,7 +43,7 @@ export function useGridParamsApi(
const row = apiRef.current.getRow(id);

if (!row) {
throw new MissingRowIdError(`MUI X: No row with id #${id} found`);
throwMissingRowError(id);
}

const params: GridRowParams = {
Expand Down Expand Up @@ -106,7 +105,7 @@ export function useGridParamsApi(
const rowNode = gridRowNodeSelector(apiRef, id);

if (!row || !rowNode) {
throw new MissingRowIdError(`MUI X: No row with id #${id} found`);
throwMissingRowError(id);
}

const cellFocus = gridFocusCellSelector(apiRef);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import type { RefObject } from '@mui/x-internals/types';
import { getRowValue as getRowValueFn } from './gridRowsUtils';
import { getRowValue as getRowValueFn, throwMissingRowError } from './gridRowsUtils';
import type { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
import type { GridParamsApi } from '../../../models/api/gridParamsApi';

Expand All @@ -11,7 +11,7 @@ export const useGridParamsOverridableMethods = (apiRef: RefObject<GridPrivateApi

const row = apiRef.current.getRow(id);
if (!row) {
throw new Error(`MUI X: No row with id #${id} found`);
throwMissingRowError(id);
}

if (!colDef || !colDef.valueGetter) {
Expand Down
3 changes: 2 additions & 1 deletion packages/x-data-grid/src/hooks/features/rows/useGridRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
isAutogeneratedRowNode,
GRID_ROOT_GROUP_ID,
GRID_ID_AUTOGENERATED,
throwMissingRowError,
updateCacheWithNewRows,
getTopLevelRowCount,
getRowIdFromRowModel,
Expand Down Expand Up @@ -293,7 +294,7 @@ You need to upgrade to DataGridPro or DataGridPremium component to unlock this f
(id, isExpanded) => {
const currentNode = gridRowNodeSelector(apiRef, id);
if (!currentNode) {
throw new Error(`MUI X: No row with id #${id} found.`);
throwMissingRowError(id);
}

if (currentNode.type !== 'group') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RefObject } from '@mui/x-internals/types';
import type { GridRowId, GridGroupNode } from '../../../models/gridRows';
import { gridRowTreeSelector, gridRowNodeSelector } from './gridRowsSelector';
import { gridExpandedSortedRowIndexLookupSelector } from '../filter/gridFilterSelector';
import { GRID_ROOT_GROUP_ID } from './gridRowsUtils';
import { GRID_ROOT_GROUP_ID, throwMissingRowError } from './gridRowsUtils';
import type { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
import type { GridRowProApi } from '../../../models/api/gridRowApi';

Expand All @@ -14,11 +14,11 @@ export const useGridRowsOverridableMethods = (apiRef: RefObject<GridPrivateApiCo
const targetNode = gridRowNodeSelector(apiRef, targetRowId);

if (!sourceNode) {
throw new Error(`MUI X: No row with id #${sourceRowId} found.`);
throwMissingRowError(sourceRowId);
}

if (!targetNode) {
throw new Error(`MUI X: No row with id #${targetRowId} found.`);
throwMissingRowError(targetRowId);
}

if (sourceNode.type !== 'leaf') {
Expand Down
1 change: 1 addition & 0 deletions packages/x-data-grid/src/internals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export {
getRowIdFromRowModel,
GRID_ID_AUTOGENERATED,
getRowValue,
throwMissingRowError,
} from '../hooks/features/rows/gridRowsUtils';
export {
gridAdditionalRowGroupsSelector,
Expand Down
Loading