Skip to content

Commit

Permalink
[DataGrid] Make more apiRef methods private (#6700)
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii authored Nov 15, 2022
1 parent bc47590 commit 4d77507
Show file tree
Hide file tree
Showing 79 changed files with 809 additions and 447 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,45 @@ Below are described the steps you need to make to migrate from v5 to v6.
- The `apiRef.current.updateColumn` method was removed. Use `apiRef.current.updateColumns` instead.
- The `apiRef.current.getColumnsMeta` method was removed. Use `gridColumnsTotalWidthSelector` or `gridColumnPositionsSelector` selectors instead.
- The `apiRef.current.getRowIndex` method was removed. Use `apiRef.current.getRowIndexRelativeToVisibleRows` instead.
- Some internal undocumented `apiRef` methods and properties were removed.

If you don't use undocumented properties - you can skip the list below.
Otherwise, please check the list and [open an issue](https://github.com/mui/mui-x/issues/new/choose) if there's something missing in the `apiRef`.

<details>
<summary markdown="span">List of removed undocumented methods and properties</summary>

| |
| ------------------------------------------------- |
| `getLogger` |
| `windowRef` |
| `unstable_caches` |
| `unstable_eventManager` |
| `unstable_requestPipeProcessorsApplication` |
| `unstable_registerPipeProcessor` |
| `unstable_registerPipeApplier` |
| `unstable_storeDetailPanelHeight` |
| `unstable_detailPanelHasAutoHeight` |
| `unstable_calculateColSpan` |
| `unstable_rowHasAutoHeight` |
| `unstable_getLastMeasuredRowIndex` |
| `unstable_getViewportPageSize` |
| `unstable_updateGridDimensionsRef` |
| `unstable_getRenderContext` |
| `unstable_registerStrategyProcessor` |
| `unstable_applyStrategyProcessor` |
| `unstable_getActiveStrategy` |
| `unstable_setStrategyAvailability` |
| `unstable_setCellEditingEditCellValue` |
| `unstable_getRowWithUpdatedValuesFromCellEditing` |
| `unstable_setRowEditingEditCellValue` |
| `unstable_getRowWithUpdatedValuesFromRowEditing` |
| `unstable_runPendingEditCellValueMutation` |
| `unstable_moveFocusToRelativeCell` |
| `unstable_updateControlState` |
| `unstable_registerControlState` |

</details>

### Other exports

Expand Down
2 changes: 0 additions & 2 deletions docs/pages/x/api/data-grid/grid-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,8 @@ import { GridApi } from '@mui/x-data-grid-pro';
| <span class="prop-name">toggleDetailPanel [<span class="plan-pro" title="Pro plan"></span>](/x/introduction/licensing/#pro-plan)</span> | <span class="prop-type">(id: GridRowId) =&gt; void</span> | Expands or collapses the detail panel of a row. |
| <span class="prop-name">unpinColumn [<span class="plan-pro" title="Pro plan"></span>](/x/introduction/licensing/#pro-plan)</span> | <span class="prop-type">(field: string) =&gt; void</span> | Unpins a column. |
| <span class="prop-name">unstable_getAllGroupDetails</span> | <span class="prop-type">() =&gt; GridColumnGroupLookup</span> | Returns the column group lookup. |
| <span class="prop-name">unstable_getColumnGroupHeaderFocus</span> | <span class="prop-type">() =&gt; GridColumnGroupIdentifier \| null</span> | Gets the focus to the column group header at the given `field` and given depth. |
| <span class="prop-name">unstable_getColumnGroupPath</span> | <span class="prop-type">(field: string) =&gt; GridColumnGroup['groupId'][]</span> | Returns the id of the groups leading to the requested column.<br />The array is ordered by increasing depth (the last element is the direct parent of the column). |
| <span class="prop-name">unstable_replaceRows</span> | <span class="prop-type">(firstRowToReplace: number, newRows: GridRowModel[]) =&gt; void</span> | Replace a set of rows with new rows. |
| <span class="prop-name">unstable_setColumnGroupHeaderFocus</span> | <span class="prop-type">(field: string, depth: number, event?: MuiBaseEvent) =&gt; void</span> | Sets the focus to the column group header at the given `field` and given depth. |
| <span class="prop-name">unstable_setPinnedRows [<span class="plan-pro" title="Pro plan"></span>](/x/introduction/licensing/#pro-plan)</span> | <span class="prop-type">(pinnedRows?: GridPinnedRowsProp) =&gt; void</span> | Changes the pinned rows. |
| <span class="prop-name">updateColumns</span> | <span class="prop-type">(cols: GridColDef[]) =&gt; void</span> | Updates the definition of multiple columns at the same time. |
| <span class="prop-name">updateRows</span> | <span class="prop-type">(updates: GridRowModelUpdate[]) =&gt; void</span> | Allows to update, insert and delete rows. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
} from './gridAggregationInterfaces';
import { GridStatePremium } from '../../../models/gridStatePremium';
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
import { GridApiPremium } from '../../../models/gridApiPremium';
import { GridApiPremium, GridPrivateApiPremium } from '../../../models/gridApiPremium';

export const GRID_AGGREGATION_ROOT_FOOTER_ROW_ID = 'auto-generated-group-footer-root';

Expand Down Expand Up @@ -122,7 +122,7 @@ interface AddFooterRowsParams {
* If `true`, there are some aggregation rules to apply
*/
hasAggregationRule: boolean;
apiRef: React.MutableRefObject<GridApiPremium>;
apiRef: React.MutableRefObject<GridPrivateApiPremium>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@mui/x-data-grid-pro';
import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
import { GridApiPremium, GridPrivateApiPremium } from '../../../models/gridApiPremium';
import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
import { gridAggregationModelSelector } from './gridAggregationSelectors';
import { GridAggregationApi } from './gridAggregationInterfaces';
import {
Expand All @@ -18,9 +18,9 @@ import { createAggregationLookup } from './createAggregationLookup';

export const aggregationStateInitializer: GridStateInitializer<
Pick<DataGridPremiumProcessedProps, 'aggregationModel' | 'initialState'>,
GridApiPremium
GridPrivateApiPremium
> = (state, props, apiRef) => {
apiRef.current.unstable_caches.aggregation = {
apiRef.current.caches.aggregation = {
rulesOnLastColumnHydration: {},
rulesOnLastRowHydration: {},
};
Expand Down Expand Up @@ -99,7 +99,7 @@ export const useGridAggregation = (
*/
const checkAggregationRulesDiff = React.useCallback(() => {
const { rulesOnLastRowHydration, rulesOnLastColumnHydration } =
apiRef.current.unstable_caches.aggregation;
apiRef.current.caches.aggregation;

const aggregationRules = props.disableAggregation
? {}
Expand All @@ -111,13 +111,13 @@ export const useGridAggregation = (

// Re-apply the row hydration to add / remove the aggregation footers
if (!areAggregationRulesEqual(rulesOnLastRowHydration, aggregationRules)) {
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateRows');
apiRef.current.requestPipeProcessorsApplication('hydrateRows');
applyAggregation();
}

// Re-apply the column hydration to wrap / unwrap the aggregated columns
if (!areAggregationRulesEqual(rulesOnLastColumnHydration, aggregationRules)) {
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
apiRef.current.requestPipeProcessorsApplication('hydrateColumns');
}
}, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
GridRestoreStatePreProcessingContext,
useGridRegisterPipeProcessor,
} from '@mui/x-data-grid-pro/internals';
import { GridApiPremium } from '../../../models/gridApiPremium';
import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
import {
getAvailableAggregationFunctions,
addFooterRows,
Expand All @@ -27,15 +27,15 @@ function Divider() {
}

export const useGridAggregationPreProcessors = (
apiRef: React.MutableRefObject<GridApiPremium>,
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
'aggregationFunctions' | 'disableAggregation' | 'getAggregationPosition'
>,
) => {
const updateAggregatedColumns = React.useCallback<GridPipeProcessor<'hydrateColumns'>>(
(columnsState) => {
const { rulesOnLastColumnHydration } = apiRef.current.unstable_caches.aggregation;
const { rulesOnLastColumnHydration } = apiRef.current.caches.aggregation;

const aggregationRules = props.disableAggregation
? {}
Expand Down Expand Up @@ -68,7 +68,7 @@ export const useGridAggregationPreProcessors = (
columnsState.lookup[field] = column;
});

apiRef.current.unstable_caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
apiRef.current.caches.aggregation.rulesOnLastColumnHydration = aggregationRules;

return columnsState;
},
Expand All @@ -90,14 +90,13 @@ export const useGridAggregationPreProcessors = (
// If we did not have any aggregation footer before, and we still don't have any,
// Then we can skip this step
if (
Object.keys(apiRef.current.unstable_caches.aggregation.rulesOnLastRowHydration).length ===
0 &&
Object.keys(apiRef.current.caches.aggregation.rulesOnLastRowHydration).length === 0 &&
!hasAggregationRule
) {
return value;
}

apiRef.current.unstable_caches.aggregation.rulesOnLastRowHydration = aggregationRules;
apiRef.current.caches.aggregation.rulesOnLastRowHydration = aggregationRules;

return addFooterRows({
apiRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from '@mui/x-data-grid-pro';
import { buildWarning } from '@mui/x-data-grid/internals';
import { GridExceljsProcessInput, ColumnsStylesInterface } from '../gridExcelExportInterface';
import { GridPrivateApiPremium } from '../../../../models/gridApiPremium';

const getExcelJs = async () => {
const { default: excelJsDefault } = await import('exceljs');
Expand Down Expand Up @@ -50,7 +51,7 @@ const getFormattedValueOptions = (
const serializeRow = (
id: GridRowId,
columns: GridStateColDef[],
api: GridApi,
api: GridPrivateApiPremium,
defaultValueOptionsFormulae: { [field: string]: string },
) => {
const row: { [colField: string]: undefined | number | boolean | string | Date } = {};
Expand All @@ -61,7 +62,7 @@ const serializeRow = (
const outlineLevel = firstCellParams.rowNode.depth;

// `colSpan` is only calculated for rendered rows, so we need to calculate it during export for every row
api.unstable_calculateColSpan({
api.calculateColSpan({
rowId: id,
minFirstColumn: 0,
maxLastColumn: columns.length,
Expand Down Expand Up @@ -256,7 +257,7 @@ interface BuildExcelOptions {

export async function buildExcel(
options: BuildExcelOptions,
api: GridApi,
api: GridPrivateApiPremium,
): Promise<Excel.Workbook> {
const {
columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from './gridRowGroupingInterfaces';
import { GridStatePremium } from '../../../models/gridStatePremium';
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
import { GridApiPremium } from '../../../models/gridApiPremium';
import { GridPrivateApiPremium } from '../../../models/gridApiPremium';

export const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';

Expand Down Expand Up @@ -197,20 +197,20 @@ export const mergeStateWithRowGroupingModel =
});

export const setStrategyAvailability = (
apiRef: React.MutableRefObject<GridApiPremium>,
privateApiRef: React.MutableRefObject<GridPrivateApiPremium>,
disableRowGrouping: boolean,
) => {
let isAvailable: () => boolean;
if (disableRowGrouping) {
isAvailable = () => false;
} else {
isAvailable = () => {
const rowGroupingSanitizedModel = gridRowGroupingSanitizedModelSelector(apiRef);
const rowGroupingSanitizedModel = gridRowGroupingSanitizedModelSelector(privateApiRef);
return rowGroupingSanitizedModel.length > 0;
};
}

apiRef.current.unstable_setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
privateApiRef.current.setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
};

export const getCellGroupingCriteria = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Divider() {
export const rowGroupingStateInitializer: GridStateInitializer<
Pick<DataGridPremiumProcessedProps, 'rowGroupingModel' | 'initialState'>
> = (state, props, apiRef) => {
apiRef.current.unstable_caches.rowGrouping = {
apiRef.current.caches.rowGrouping = {
rulesOnLastRowTreeCreation: [],
};

Expand Down Expand Up @@ -259,22 +259,21 @@ export const useGridRowGrouping = (
GridEventListener<'columnsChange'>
>(() => {
const sanitizedRowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
const rulesOnLastRowTreeCreation =
apiRef.current.unstable_caches.rowGrouping.rulesOnLastRowTreeCreation;
const rulesOnLastRowTreeCreation = apiRef.current.caches.rowGrouping.rulesOnLastRowTreeCreation;

const groupingRules = getGroupingRules({
sanitizedRowGroupingModel,
columnsLookup: gridColumnLookupSelector(apiRef),
});

if (!areGroupingRulesEqual(rulesOnLastRowTreeCreation, groupingRules)) {
apiRef.current.unstable_caches.rowGrouping.rulesOnLastRowTreeCreation = groupingRules;
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
apiRef.current.caches.rowGrouping.rulesOnLastRowTreeCreation = groupingRules;
apiRef.current.requestPipeProcessorsApplication('hydrateColumns');
setStrategyAvailability(apiRef, props.disableRowGrouping);

// Refresh the row tree creation strategy processing
// TODO: Add a clean way to re-run a strategy processing without publishing a private event
if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
if (apiRef.current.getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import {
getCellGroupingCriteria,
getGroupingRules,
} from './gridRowGroupingUtils';
import { GridApiPremium } from '../../../models/gridApiPremium';
import { GridPrivateApiPremium } from '../../../models/gridApiPremium';

export const useGridRowGroupingPreProcessors = (
apiRef: React.MutableRefObject<GridApiPremium>,
apiRef: React.MutableRefObject<GridPrivateApiPremium>,
props: Pick<
DataGridPremiumProcessedProps,
| 'disableRowGrouping'
Expand Down Expand Up @@ -144,7 +144,7 @@ export const useGridRowGroupingPreProcessors = (
sanitizedRowGroupingModel,
columnsLookup,
});
apiRef.current.unstable_caches.rowGrouping.rulesOnLastRowTreeCreation = groupingRules;
apiRef.current.caches.rowGrouping.rulesOnLastRowTreeCreation = groupingRules;

const getRowTreeBuilderNode = (rowId: GridRowId) => {
const row = params.dataRowIdToModelLookup[rowId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
GridApiCommon,
GridColumnPinningApi,
GridDetailPanelApi,
GridDetailPanelPrivateApi,
GridRowPinningApi,
GridRowMultiSelectionApi,
} from '@mui/x-data-grid-pro';
Expand All @@ -26,4 +27,5 @@ export interface GridApiPremium

export interface GridPrivateApiPremium
extends GridApiPremium,
GridPrivateOnlyApiCommon<GridApiPremium, GridPrivateApiPremium> {}
GridPrivateOnlyApiCommon<GridApiPremium, GridPrivateApiPremium>,
GridDetailPanelPrivateApi {}
Loading

0 comments on commit 4d77507

Please sign in to comment.