UNPKG

@mui/x-data-grid-premium

Version:

The Premium plan edition of the MUI X Data Grid Components.

41 lines (36 loc) 1.83 kB
"use strict"; 'use client'; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default; Object.defineProperty(exports, "__esModule", { value: true }); exports.useIsCellEditable = void 0; var React = _interopRequireWildcard(require("react")); var _internals = require("@mui/x-data-grid-pro/internals"); var _gridAggregationSelectors = require("../aggregation/gridAggregationSelectors"); /** * Implementation of the cell editable condition hook of the Data Grid Premium */ const useIsCellEditable = (apiRef, props) => { const isCellEditableCommunity = (0, _internals.useIsCellEditable)(); return React.useCallback(params => { const isCellEditable = isCellEditableCommunity(params); // If the cell is not editable by the community hook, return false immediately if (!isCellEditable) { return false; } // If the data source is not used or aggregation is disabled or both tree data and row grouping are disabled, return the community hook result if (!props.dataSource || props.disableAggregation || !props.treeData && props.disableRowGrouping) { return isCellEditable; } // If the cell is not a part of the aggregation model, return the community hook result const aggregationModelFields = Object.keys((0, _gridAggregationSelectors.gridAggregationModelSelector)(apiRef)); if (!aggregationModelFields.includes(params.field)) { return isCellEditable; } // The cell is a part of the aggregation model and it is retrieved from the server-side data. // Allow editing only for the non-grouped rows. return params.rowNode.type !== 'group'; }, [apiRef, props.dataSource, props.treeData, props.disableAggregation, props.disableRowGrouping, isCellEditableCommunity]); }; exports.useIsCellEditable = useIsCellEditable;