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] Don't export internal utils #2233

Merged
merged 8 commits into from
Jul 30, 2021

Conversation

flaviendelangle
Copy link
Member

@flaviendelangle flaviendelangle commented Jul 29, 2021

Part of #2227

The following variables and types are not exported anymore from @material-ui/data-grid and @material-ui/x-grid

// utils.domUtils.ts

- findParentElementFromClassName
- getRowEl
- isGridCellRoot
- isGridHeaderCellRoot
- getIdFromRowElem
- getFieldFromHeaderElem
- findHeaderElementFromField
- findGridCellElementsFromCol
- escapeOperandAttributeSelector
- getGridColumnHeaderElement
- getGridRowElement
- getGridCellElement
- isOverflown

// utils/exportAs.ts
- exportAs

// utils/getGridLocalization
- LocalizationV4
- LocalizationV5
- Localization
- getGridLocalization

// utils/keyboardUtils.ts
- isHomeOrEndKeys
- isPageKeys
- isDeleteKeys
- printableCharRegex
- isPrintableKey
- GRID_MULTIPLE_SELECTION_KEYS
- GRID_CELL_EXIT_EDIT_MODE_KEYS
- GRID_CELL_EDIT_COMMIT_KEYS
- isMultipleKey
- isCellEnterEditModeKeys
- isCellExitEditModeKeys
- isCellEditCommitKeys
- isNavigationKey
- isKeyboardEvent
- isHideMenuKey

// utils/material-ui-utils.ts
- DistributiveOmit
- InternalStandardProps
- useEventCallback
- useEnhancedEffect
- useThemeProps
- composeClasses
- generateUtilityClass
- generateUtilityClasses

// utils/mergeUtils.ts
- mergeGridColTypes
- removeUndefinedProps
- mergeGridOptions

// utils/sortingUtils.ts
- nextGridSortDirection
- isDesc
- gridNillComparer
- gridStringNumberComparer
- gridNumberComparer
- gridDateComparer

// utils/utils.ts
- isDeepEqual
- isNumber
- isFunction
- isObject
- getMuiVersion
- muiStyleAlpha
- createTheme
- localStorageAvailable
- Optional
- getDataGridUtilityClass
- escapeRegExp
- getThemePaletteMode

These three utils are used in the demo.
Do we want to export them or let the user re-implement them ?

- getThemePaletteMode
- escapeRegExp
- isOverflown

For escapeRegExp and isOverflown, I don't think it's the role of MUI to provide such generic methods.
For getThemePaletteMode, the core could export it but if it does not I suppose we shouldn't do it

@flaviendelangle flaviendelangle self-assigned this Jul 29, 2021
@flaviendelangle flaviendelangle changed the title Exports clean utils [core] Exports clean utils Jul 29, 2021
@flaviendelangle flaviendelangle added the core Infrastructure work going on behind the scenes label Jul 29, 2021
@flaviendelangle flaviendelangle changed the title [core] Exports clean utils [core] Remove the utils from the public API of @material-ui/data-grid and @material-ui/x-grid Jul 29, 2021
@flaviendelangle flaviendelangle changed the title [core] Remove the utils from the public API of @material-ui/data-grid and @material-ui/x-grid [core] Remove the internal utils from the public API of @material-ui/data-grid and @material-ui/x-grid Jul 29, 2021
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import clsx from 'clsx';
import { useFakeTimers } from 'sinon';
import { withStyles } from '@material-ui/styles';
import { createTheme } from '@material-ui/data-grid';
import { createTheme } from '../../packages/grid/_modules_/grid/utils/utils';
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, we can't use @material-ui/data-grid/utils/utils because of the _modules_ folder structure. This folder structure prevents us to split MIT and Commercially licensed code. So we need to move most of the modules away. Once we do how do XGrid and DataGrid share the utils? I guess we have to either keep the utils in or export them as unstable_. Anyway, it's a problem for our future self. Making the utils private is the right thing to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, removing the unnecessary exports is a first step to help us reorganize the codebase between the MIT and the Commercially licensed code.

And there is some code that is not Grid related and should not be exported and not be in a grid folder but probably in a _shared_ directory that will be accessed by the grids but also the new X components.
That's the case for a lot of the utils.

Copy link
Member

@oliviertassinari oliviertassinari Jul 31, 2021

Choose a reason for hiding this comment

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

but probably in a shared directory that will be accessed by the grids but also the new X components.

If it needs to be access cross components, then we need a similar package to @material-ui/utils. Maybe we should name them:

  • @mui/core-utils (prev @material-ui/utils)
  • @mui/x-utils

Related to https://www.notion.so/mui-org/Rearranging-the-packages-2f700caf8b5e48559fe86ebb648ed91a

@oliviertassinari oliviertassinari changed the title [core] Remove the internal utils from the public API of @material-ui/data-grid and @material-ui/x-grid [DataGrid] Don't export the internal utils Jul 29, 2021
@oliviertassinari oliviertassinari added breaking change component: data grid This is the name of the generic UI component, not the React module! labels Jul 29, 2021
@oliviertassinari
Copy link
Member

Do we want to export them or let the user re-implement them ?

+1 for re-implementation

@flaviendelangle flaviendelangle merged commit 363a7a1 into mui:master Jul 30, 2021
@flaviendelangle flaviendelangle deleted the exports-clean-utils branch July 30, 2021 11:07
@oliviertassinari oliviertassinari changed the title [DataGrid] Don't export the internal utils [core] Don't export the internal utils Jul 31, 2021
@oliviertassinari oliviertassinari changed the title [core] Don't export the internal utils [core] Don't export internal utils Jul 31, 2021
@ru4ert
Copy link

ru4ert commented Aug 7, 2021

OK, copied that there have been changes applied.

pre Update
there was this way to access the object shapes.

import { createTheme, DataGrid, GridCellParams, GridColDef, GridEditCellPropsParams, GridRowModel, GridRowSelectedParams, GridSelectionModelChangeParams, GRID_CELL_EDIT_PROPS_CHANGE } from '@material-ui/data-grid'
[...]

const renderEditCell = (params: GridCellParams) => {
    return <EditTypeOfProduct {...params} Companys={values.Companys} />
}

After the update

Module '"@material-ui/data-grid"' has no exported member 'createTheme'.
Module '"@material-ui/data-grid"' has no exported member 'GridRowSelectedParams'.
Module '"@material-ui/data-grid"' has no exported member 'GridSelectionModelChangeParams'.

Is there a new alternative way?

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 7, 2021

@Rupert-com

  • createTheme import from the core package:
import { createTheme } from '@material-ui/core/styles';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: data grid This is the name of the generic UI component, not the React module! core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants