From dd98382e7b1657235c12c1334e44a68fa003bd4a Mon Sep 17 00:00:00 2001 From: Rajat Date: Mon, 9 Sep 2024 16:25:49 +0530 Subject: [PATCH] [core] Move warning methods to `@mui/x-internals` (#14528) Co-authored-by: Lukas --- .../ChartsXReferenceLine.tsx | 2 +- .../ChartsYReferenceLine.tsx | 2 +- .../clipboard/useGridClipboardImport.ts | 2 +- .../export/serializer/excelSerializer.ts | 2 +- .../features/editing/useGridCellEditing.ts | 2 +- .../features/editing/useGridRowEditing.ts | 2 +- .../export/serializers/csvSerializer.ts | 2 +- .../hooks/features/filter/gridFilterUtils.ts | 2 +- .../features/sorting/gridSortingUtils.ts | 2 +- .../src/hooks/utils/useGridSelector.ts | 2 +- .../x-data-grid/src/internals/utils/index.ts | 1 - .../src/internals/utils/propValidation.ts | 2 +- .../src/internals/utils/warning.ts | 25 ------------------- .../x-data-grid/src/utils/createSelector.ts | 2 +- .../DateRangeCalendar/DateRangeCalendar.tsx | 2 +- .../src/AdapterDayjs/AdapterDayjs.ts | 2 +- .../internals/hooks/usePicker/usePicker.ts | 2 +- .../x-date-pickers/src/internals/index.ts | 1 - .../src/internals/utils/warning.ts | 25 ------------------- packages/x-internals/src/warning/index.ts | 1 + .../src/warning}/warning.ts | 3 +-- .../src/RichTreeViewPro/RichTreeViewPro.tsx | 3 ++- .../useTreeViewItemsReordering.ts | 3 ++- .../src/RichTreeView/RichTreeView.tsx | 2 +- .../src/SimpleTreeView/SimpleTreeView.tsx | 2 +- packages/x-tree-view/src/internals/index.ts | 1 - .../useTreeViewLabel/useTreeViewLabel.ts | 2 +- .../src/internals/utils/warning.ts | 25 ------------------- test/utils/mochaHooks.js | 2 +- 29 files changed, 25 insertions(+), 101 deletions(-) delete mode 100644 packages/x-data-grid/src/internals/utils/warning.ts delete mode 100644 packages/x-date-pickers/src/internals/utils/warning.ts create mode 100644 packages/x-internals/src/warning/index.ts rename packages/{x-charts/src/internals => x-internals/src/warning}/warning.ts (82%) delete mode 100644 packages/x-tree-view/src/internals/utils/warning.ts diff --git a/packages/x-charts/src/ChartsReferenceLine/ChartsXReferenceLine.tsx b/packages/x-charts/src/ChartsReferenceLine/ChartsXReferenceLine.tsx index 5f7bb3a9ce18..c09589d5359b 100644 --- a/packages/x-charts/src/ChartsReferenceLine/ChartsXReferenceLine.tsx +++ b/packages/x-charts/src/ChartsReferenceLine/ChartsXReferenceLine.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import composeClasses from '@mui/utils/composeClasses'; +import { warnOnce } from '@mui/x-internals/warning'; import { useDrawingArea, useXScale } from '../hooks'; import { CommonChartsReferenceLineProps, ReferenceLineRoot } from './common'; import { ChartsText } from '../ChartsText'; @@ -7,7 +8,6 @@ import { ChartsReferenceLineClasses, getReferenceLineUtilityClass, } from './chartsReferenceLineClasses'; -import { warnOnce } from '../internals/warning'; export type ChartsXReferenceLineProps< TValue extends string | number | Date = string | number | Date, diff --git a/packages/x-charts/src/ChartsReferenceLine/ChartsYReferenceLine.tsx b/packages/x-charts/src/ChartsReferenceLine/ChartsYReferenceLine.tsx index 5a18d38bd34f..565d827bd42e 100644 --- a/packages/x-charts/src/ChartsReferenceLine/ChartsYReferenceLine.tsx +++ b/packages/x-charts/src/ChartsReferenceLine/ChartsYReferenceLine.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import composeClasses from '@mui/utils/composeClasses'; +import { warnOnce } from '@mui/x-internals/warning'; import { useDrawingArea, useYScale } from '../hooks'; import { CommonChartsReferenceLineProps, ReferenceLineRoot } from './common'; import { ChartsText } from '../ChartsText'; @@ -7,7 +8,6 @@ import { ChartsReferenceLineClasses, getReferenceLineUtilityClass, } from './chartsReferenceLineClasses'; -import { warnOnce } from '../internals/warning'; export type ChartsYReferenceLineProps< TValue extends string | number | Date = string | number | Date, diff --git a/packages/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts b/packages/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts index 8311264e1568..90b061ae5396 100644 --- a/packages/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts +++ b/packages/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts @@ -14,7 +14,6 @@ import { gridExpandedSortedRowIdsSelector, } from '@mui/x-data-grid'; import { - warnOnce, getRowIdFromRowModel, getActiveElement, GridPipeProcessor, @@ -23,6 +22,7 @@ import { isPasteShortcut, useGridLogger, } from '@mui/x-data-grid/internals'; +import { warnOnce } from '@mui/x-internals/warning'; import { GRID_DETAIL_PANEL_TOGGLE_FIELD, GRID_REORDER_COL_DEF } from '@mui/x-data-grid-pro'; import { unstable_debounce as debounce } from '@mui/utils'; import { GridApiPremium, GridPrivateApiPremium } from '../../../models/gridApiPremium'; diff --git a/packages/x-data-grid-premium/src/hooks/features/export/serializer/excelSerializer.ts b/packages/x-data-grid-premium/src/hooks/features/export/serializer/excelSerializer.ts index 6ae00a3a3aeb..61dba42a4ab7 100644 --- a/packages/x-data-grid-premium/src/hooks/features/export/serializer/excelSerializer.ts +++ b/packages/x-data-grid-premium/src/hooks/features/export/serializer/excelSerializer.ts @@ -9,7 +9,6 @@ import { GridValidRowModel, } from '@mui/x-data-grid-pro'; import { - warnOnce, GridStateColDef, GridSingleSelectColDef, isObject, @@ -17,6 +16,7 @@ import { isSingleSelectColDef, gridHasColSpanSelector, } from '@mui/x-data-grid/internals'; +import { warnOnce } from '@mui/x-internals/warning'; import { ColumnsStylesInterface, GridExcelExportOptions } from '../gridExcelExportInterface'; import { GridPrivateApiPremium } from '../../../../models/gridApiPremium'; diff --git a/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts b/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts index fa6afb47afaf..9a25971f2323 100644 --- a/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts +++ b/packages/x-data-grid/src/hooks/features/editing/useGridCellEditing.ts @@ -3,6 +3,7 @@ import { unstable_useEventCallback as useEventCallback, unstable_useEnhancedEffect as useEnhancedEffect, } from '@mui/utils'; +import { warnOnce } from '@mui/x-internals/warning'; import { useGridApiEventHandler, useGridApiOptionHandler, @@ -30,7 +31,6 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod'; import { gridEditRowsStateSelector } from './gridEditingSelectors'; import { GridRowId } from '../../../models/gridRows'; import { isPrintableKey, isPasteShortcut } from '../../../utils/keyboardUtils'; -import { warnOnce } from '../../../internals/utils/warning'; import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector'; import { deepClone } from '../../../utils/utils'; import { diff --git a/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts b/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts index fe07ea384681..ff755e43b9b6 100644 --- a/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts +++ b/packages/x-data-grid/src/hooks/features/editing/useGridRowEditing.ts @@ -3,6 +3,7 @@ import { unstable_useEventCallback as useEventCallback, unstable_useEnhancedEffect as useEnhancedEffect, } from '@mui/utils'; +import { warnOnce } from '@mui/x-internals/warning'; import { useGridApiEventHandler, useGridApiOptionHandler, @@ -36,7 +37,6 @@ import { gridVisibleColumnFieldsSelector, } from '../columns/gridColumnsSelector'; import { GridCellParams } from '../../../models/params/gridCellParams'; -import { warnOnce } from '../../../internals/utils/warning'; import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector'; import { deepClone } from '../../../utils/utils'; import { diff --git a/packages/x-data-grid/src/hooks/features/export/serializers/csvSerializer.ts b/packages/x-data-grid/src/hooks/features/export/serializers/csvSerializer.ts index 385b5a41cf43..60f01a2288b7 100644 --- a/packages/x-data-grid/src/hooks/features/export/serializers/csvSerializer.ts +++ b/packages/x-data-grid/src/hooks/features/export/serializers/csvSerializer.ts @@ -1,9 +1,9 @@ +import { warnOnce } from '@mui/x-internals/warning'; import type { GridColumnGroup, GridCsvExportOptions, GridRowId } from '../../../../models'; import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef'; import type { GridCellParams } from '../../../../models/params/gridCellParams'; import type { GridStateColDef } from '../../../../models/colDef/gridColDef'; import type { GridApiCommunity } from '../../../../models/api/gridApiCommunity'; -import { warnOnce } from '../../../../internals/utils/warning'; function sanitizeCellValue(value: unknown, csvOptions: CSVOptions): string { if (value === null || value === undefined) { diff --git a/packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts b/packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts index 5a6f64bce4dc..482caf7a26f0 100644 --- a/packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts +++ b/packages/x-data-grid/src/hooks/features/filter/gridFilterUtils.ts @@ -1,4 +1,5 @@ import * as React from 'react'; +import { warnOnce } from '@mui/x-internals/warning'; import { GridColDef, GridFilterItem, @@ -14,7 +15,6 @@ import { GridFilterItemResult, GridQuickFilterValueResult, } from './gridFilterState'; -import { warnOnce } from '../../../internals/utils/warning'; import { getPublicApiRef } from '../../../utils/getPublicApiRef'; import { gridColumnFieldsSelector, diff --git a/packages/x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts b/packages/x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts index ce7138653a28..039947a05495 100644 --- a/packages/x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts +++ b/packages/x-data-grid/src/hooks/features/sorting/gridSortingUtils.ts @@ -1,4 +1,5 @@ import * as React from 'react'; +import { warnOnce } from '@mui/x-internals/warning'; import { GridSortingModelApplier } from './gridSortingState'; import type { GridRowId, GridTreeNode } from '../../../models'; import { GridApiCommunity } from '../../../models/api/gridApiCommunity'; @@ -10,7 +11,6 @@ import { GridSortModel, GridSortCellParams, } from '../../../models/gridSortModel'; -import { warnOnce } from '../../../internals/utils/warning'; type GridSortingFieldComparator = { getSortCellParams: (id: GridRowId) => GridSortCellParams; diff --git a/packages/x-data-grid/src/hooks/utils/useGridSelector.ts b/packages/x-data-grid/src/hooks/utils/useGridSelector.ts index 470c7a554db6..e9ac0e0f44bd 100644 --- a/packages/x-data-grid/src/hooks/utils/useGridSelector.ts +++ b/packages/x-data-grid/src/hooks/utils/useGridSelector.ts @@ -1,10 +1,10 @@ import * as React from 'react'; import { fastObjectShallowCompare } from '@mui/x-internals/fastObjectShallowCompare'; +import { warnOnce } from '@mui/x-internals/warning'; import type { GridApiCommon } from '../../models/api/gridApiCommon'; import { OutputSelector, OutputSelectorV8 } from '../../utils/createSelector'; import { useLazyRef } from './useLazyRef'; import { useOnMount } from './useOnMount'; -import { warnOnce } from '../../internals/utils/warning'; import type { GridCoreApi } from '../../models/api/gridCoreApi'; function isOutputSelector( diff --git a/packages/x-data-grid/src/internals/utils/index.ts b/packages/x-data-grid/src/internals/utils/index.ts index 20749d11ceb9..5bdfb7c8c66f 100644 --- a/packages/x-data-grid/src/internals/utils/index.ts +++ b/packages/x-data-grid/src/internals/utils/index.ts @@ -1,4 +1,3 @@ export * from './computeSlots'; export * from './useProps'; export * from './propValidation'; -export * from './warning'; diff --git a/packages/x-data-grid/src/internals/utils/propValidation.ts b/packages/x-data-grid/src/internals/utils/propValidation.ts index e6dbaad64390..d6aa58f35c80 100644 --- a/packages/x-data-grid/src/internals/utils/propValidation.ts +++ b/packages/x-data-grid/src/internals/utils/propValidation.ts @@ -1,4 +1,4 @@ -import { warnOnce } from './warning'; +import { warnOnce } from '@mui/x-internals/warning'; import { isNumber } from '../../utils/utils'; import { DataGridProcessedProps } from '../../models/props/DataGridProps'; import { GridSignature } from '../../hooks/utils/useGridApiEventHandler'; diff --git a/packages/x-data-grid/src/internals/utils/warning.ts b/packages/x-data-grid/src/internals/utils/warning.ts deleted file mode 100644 index f0d34fc59f68..000000000000 --- a/packages/x-data-grid/src/internals/utils/warning.ts +++ /dev/null @@ -1,25 +0,0 @@ -const warnedOnceCache = new Set(); - -// TODO move to @mui/x-internals -// TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper. -export function warnOnce(message: string | string[], gravity: 'warning' | 'error' = 'warning') { - if (process.env.NODE_ENV === 'production') { - return; - } - - const cleanMessage = Array.isArray(message) ? message.join('\n') : message; - - if (!warnedOnceCache.has(cleanMessage)) { - warnedOnceCache.add(cleanMessage); - - if (gravity === 'error') { - console.error(cleanMessage); - } else { - console.warn(cleanMessage); - } - } -} - -export function clearWarningsCache() { - warnedOnceCache.clear(); -} diff --git a/packages/x-data-grid/src/utils/createSelector.ts b/packages/x-data-grid/src/utils/createSelector.ts index 194090510c94..965b07ed5c2b 100644 --- a/packages/x-data-grid/src/utils/createSelector.ts +++ b/packages/x-data-grid/src/utils/createSelector.ts @@ -1,7 +1,7 @@ import * as React from 'react'; import { lruMemoize, createSelectorCreator, Selector, SelectorResultArray } from 'reselect'; +import { warnOnce } from '@mui/x-internals/warning'; import type { GridCoreApi } from '../models/api/gridCoreApi'; -import { warnOnce } from '../internals/utils/warning'; type CacheKey = { id: number }; diff --git a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.tsx b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.tsx index 0cc267212084..f5ca4c0dcb02 100644 --- a/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.tsx +++ b/packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.tsx @@ -22,10 +22,10 @@ import { PickerSelectionState, useNow, DEFAULT_DESKTOP_MODE_MEDIA_QUERY, - warnOnce, useControlledValueWithTimezone, useViews, } from '@mui/x-date-pickers/internals'; +import { warnOnce } from '@mui/x-internals/warning'; import { PickerValidDate } from '@mui/x-date-pickers/models'; import { getReleaseInfo } from '../internals/utils/releaseInfo'; import { diff --git a/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.ts b/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.ts index cf564eb4e6ac..e70903c3a77d 100644 --- a/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.ts +++ b/packages/x-date-pickers/src/AdapterDayjs/AdapterDayjs.ts @@ -5,6 +5,7 @@ import customParseFormatPlugin from 'dayjs/plugin/customParseFormat'; import localizedFormatPlugin from 'dayjs/plugin/localizedFormat'; import isBetweenPlugin from 'dayjs/plugin/isBetween'; import advancedFormatPlugin from 'dayjs/plugin/advancedFormat'; +import { warnOnce } from '@mui/x-internals/warning'; import { FieldFormatTokenMap, MuiPickersAdapter, @@ -13,7 +14,6 @@ import { PickersTimezone, DateBuilderReturnType, } from '../models'; -import { warnOnce } from '../internals/utils/warning'; defaultDayjs.extend(localizedFormatPlugin); defaultDayjs.extend(weekOfYearPlugin); diff --git a/packages/x-date-pickers/src/internals/hooks/usePicker/usePicker.ts b/packages/x-date-pickers/src/internals/hooks/usePicker/usePicker.ts index b150b8fe3dee..4ac218f211b0 100644 --- a/packages/x-date-pickers/src/internals/hooks/usePicker/usePicker.ts +++ b/packages/x-date-pickers/src/internals/hooks/usePicker/usePicker.ts @@ -1,9 +1,9 @@ +import { warnOnce } from '@mui/x-internals/warning'; import { UsePickerParams, UsePickerProps, UsePickerResponse } from './usePicker.types'; import { usePickerValue } from './usePickerValue'; import { usePickerViews } from './usePickerViews'; import { usePickerLayoutProps } from './usePickerLayoutProps'; import { InferError } from '../useValidation'; -import { warnOnce } from '../../utils/warning'; import { FieldSection, PickerValidDate } from '../../../models'; import { DateOrTimeViewWithMeridiem } from '../../models'; diff --git a/packages/x-date-pickers/src/internals/index.ts b/packages/x-date-pickers/src/internals/index.ts index bf9c07dd4c1f..58b3764966d7 100644 --- a/packages/x-date-pickers/src/internals/index.ts +++ b/packages/x-date-pickers/src/internals/index.ts @@ -151,7 +151,6 @@ export { validateDate } from './utils/validation/validateDate'; export { validateDateTime } from './utils/validation/validateDateTime'; export { validateTime } from './utils/validation/validateTime'; export { applyDefaultViewProps } from './utils/views'; -export { warnOnce } from './utils/warning'; export { DayCalendar } from '../DateCalendar/DayCalendar'; export type { diff --git a/packages/x-date-pickers/src/internals/utils/warning.ts b/packages/x-date-pickers/src/internals/utils/warning.ts deleted file mode 100644 index f0d34fc59f68..000000000000 --- a/packages/x-date-pickers/src/internals/utils/warning.ts +++ /dev/null @@ -1,25 +0,0 @@ -const warnedOnceCache = new Set(); - -// TODO move to @mui/x-internals -// TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper. -export function warnOnce(message: string | string[], gravity: 'warning' | 'error' = 'warning') { - if (process.env.NODE_ENV === 'production') { - return; - } - - const cleanMessage = Array.isArray(message) ? message.join('\n') : message; - - if (!warnedOnceCache.has(cleanMessage)) { - warnedOnceCache.add(cleanMessage); - - if (gravity === 'error') { - console.error(cleanMessage); - } else { - console.warn(cleanMessage); - } - } -} - -export function clearWarningsCache() { - warnedOnceCache.clear(); -} diff --git a/packages/x-internals/src/warning/index.ts b/packages/x-internals/src/warning/index.ts new file mode 100644 index 000000000000..9bab02f38e90 --- /dev/null +++ b/packages/x-internals/src/warning/index.ts @@ -0,0 +1 @@ +export { warnOnce, clearWarningsCache } from './warning'; diff --git a/packages/x-charts/src/internals/warning.ts b/packages/x-internals/src/warning/warning.ts similarity index 82% rename from packages/x-charts/src/internals/warning.ts rename to packages/x-internals/src/warning/warning.ts index f0d34fc59f68..e4d004e26e5e 100644 --- a/packages/x-charts/src/internals/warning.ts +++ b/packages/x-internals/src/warning/warning.ts @@ -1,7 +1,6 @@ const warnedOnceCache = new Set(); -// TODO move to @mui/x-internals -// TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper. +// TODO move to @base_ui/internals. Base UI, etc. need this helper. export function warnOnce(message: string | string[], gravity: 'warning' | 'error' = 'warning') { if (process.env.NODE_ENV === 'production') { return; diff --git a/packages/x-tree-view-pro/src/RichTreeViewPro/RichTreeViewPro.tsx b/packages/x-tree-view-pro/src/RichTreeViewPro/RichTreeViewPro.tsx index c08210e09782..6259d7d4c427 100644 --- a/packages/x-tree-view-pro/src/RichTreeViewPro/RichTreeViewPro.tsx +++ b/packages/x-tree-view-pro/src/RichTreeViewPro/RichTreeViewPro.tsx @@ -4,7 +4,8 @@ import composeClasses from '@mui/utils/composeClasses'; import { useLicenseVerifier, Watermark } from '@mui/x-license'; import useSlotProps from '@mui/utils/useSlotProps'; import { TreeItem, TreeItemProps } from '@mui/x-tree-view/TreeItem'; -import { useTreeView, TreeViewProvider, warnOnce } from '@mui/x-tree-view/internals'; +import { useTreeView, TreeViewProvider } from '@mui/x-tree-view/internals'; +import { warnOnce } from '@mui/x-internals/warning'; import { styled, createUseThemeProps } from '../internals/zero-styled'; import { getRichTreeViewProUtilityClass } from './richTreeViewProClasses'; import { RichTreeViewProProps } from './RichTreeViewPro.types'; diff --git a/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.ts b/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.ts index a19c0c491e0e..a840f2d074b4 100644 --- a/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.ts +++ b/packages/x-tree-view-pro/src/internals/plugins/useTreeViewItemsReordering/useTreeViewItemsReordering.ts @@ -1,5 +1,6 @@ import * as React from 'react'; -import { warnOnce, TreeViewPlugin } from '@mui/x-tree-view/internals'; +import { TreeViewPlugin } from '@mui/x-tree-view/internals'; +import { warnOnce } from '@mui/x-internals/warning'; import { TreeViewItemsReorderingAction } from '@mui/x-tree-view/models'; import { TreeViewItemItemReorderingValidActions, diff --git a/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx b/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx index 5c46c54794d1..ecc2ba95a2ff 100644 --- a/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx +++ b/packages/x-tree-view/src/RichTreeView/RichTreeView.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import composeClasses from '@mui/utils/composeClasses'; import useSlotProps from '@mui/utils/useSlotProps'; +import { warnOnce } from '@mui/x-internals/warning'; import { getRichTreeViewUtilityClass } from './richTreeViewClasses'; import { RichTreeViewProps } from './RichTreeView.types'; import { styled, createUseThemeProps } from '../internals/zero-styled'; @@ -9,7 +10,6 @@ import { useTreeView } from '../internals/useTreeView'; import { TreeViewProvider } from '../internals/TreeViewProvider'; import { RICH_TREE_VIEW_PLUGINS, RichTreeViewPluginSignatures } from './RichTreeView.plugins'; import { TreeItem, TreeItemProps } from '../TreeItem'; -import { warnOnce } from '../internals/utils/warning'; const useThemeProps = createUseThemeProps('MuiRichTreeView'); diff --git a/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx b/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx index b508c5f92bd4..1556d2df9941 100644 --- a/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx +++ b/packages/x-tree-view/src/SimpleTreeView/SimpleTreeView.tsx @@ -2,13 +2,13 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import composeClasses from '@mui/utils/composeClasses'; import useSlotProps from '@mui/utils/useSlotProps'; +import { warnOnce } from '@mui/x-internals/warning'; import { styled, createUseThemeProps } from '../internals/zero-styled'; import { getSimpleTreeViewUtilityClass } from './simpleTreeViewClasses'; import { SimpleTreeViewProps } from './SimpleTreeView.types'; import { useTreeView } from '../internals/useTreeView'; import { TreeViewProvider } from '../internals/TreeViewProvider'; import { SIMPLE_TREE_VIEW_PLUGINS, SimpleTreeViewPluginSignatures } from './SimpleTreeView.plugins'; -import { warnOnce } from '../internals/utils/warning'; const useThemeProps = createUseThemeProps('MuiSimpleTreeView'); diff --git a/packages/x-tree-view/src/internals/index.ts b/packages/x-tree-view/src/internals/index.ts index fa8077673775..515113988bab 100644 --- a/packages/x-tree-view/src/internals/index.ts +++ b/packages/x-tree-view/src/internals/index.ts @@ -66,4 +66,3 @@ export type { } from './plugins/useTreeViewJSXItems'; export { isTargetInDescendants } from './utils/tree'; -export { warnOnce } from './utils/warning'; diff --git a/packages/x-tree-view/src/internals/plugins/useTreeViewLabel/useTreeViewLabel.ts b/packages/x-tree-view/src/internals/plugins/useTreeViewLabel/useTreeViewLabel.ts index 72c692b40fe5..1a314fff4a9a 100644 --- a/packages/x-tree-view/src/internals/plugins/useTreeViewLabel/useTreeViewLabel.ts +++ b/packages/x-tree-view/src/internals/plugins/useTreeViewLabel/useTreeViewLabel.ts @@ -1,5 +1,5 @@ import * as React from 'react'; -import { warnOnce } from '../../utils/warning'; +import { warnOnce } from '@mui/x-internals/warning'; import { TreeViewPlugin } from '../../models'; import { TreeViewItemId } from '../../../models'; import { UseTreeViewLabelSignature } from './useTreeViewLabel.types'; diff --git a/packages/x-tree-view/src/internals/utils/warning.ts b/packages/x-tree-view/src/internals/utils/warning.ts deleted file mode 100644 index f0d34fc59f68..000000000000 --- a/packages/x-tree-view/src/internals/utils/warning.ts +++ /dev/null @@ -1,25 +0,0 @@ -const warnedOnceCache = new Set(); - -// TODO move to @mui/x-internals -// TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper. -export function warnOnce(message: string | string[], gravity: 'warning' | 'error' = 'warning') { - if (process.env.NODE_ENV === 'production') { - return; - } - - const cleanMessage = Array.isArray(message) ? message.join('\n') : message; - - if (!warnedOnceCache.has(cleanMessage)) { - warnedOnceCache.add(cleanMessage); - - if (gravity === 'error') { - console.error(cleanMessage); - } else { - console.warn(cleanMessage); - } - } -} - -export function clearWarningsCache() { - warnedOnceCache.clear(); -} diff --git a/test/utils/mochaHooks.js b/test/utils/mochaHooks.js index 5e774ee1be5c..e7d0a9df9f61 100644 --- a/test/utils/mochaHooks.js +++ b/test/utils/mochaHooks.js @@ -3,7 +3,7 @@ import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGrid import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGridPro } from '@mui/x-data-grid-pro'; import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingTreeView } from '@mui/x-tree-view'; import { unstable_cleanupDOM as unstable_cleanupDOMCharts } from '@mui/x-charts/internals'; -import { clearWarningsCache } from '@mui/x-data-grid/internals'; +import { clearWarningsCache } from '@mui/x-internals/warning'; import { generateTestLicenseKey, setupTestLicenseKey } from './testLicense'; export function createXMochaHooks(coreMochaHooks = {}) {