-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Improve column definition typing #7224
Conversation
@@ -112,13 +112,8 @@ const parseInterfaceSymbol = ( | |||
|
|||
const exportedSymbol = project.exports[interfaceName]; | |||
const type = project.checker.getDeclaredTypeOfSymbol(exportedSymbol); | |||
const typeDeclaration = type.symbol.declarations?.[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to remove typeDeclaration
check since GridColDef
is now TypeAlias
, not Interface
.
Otherwise it was throwing an error here.
These are the results for the performance tests:
|
const getApplyFilterFn = ( | ||
filterItem: GridFilterItem, | ||
column: GridStateColDef, | ||
const getApplyFilterFn: GridFilterOperator['getApplyFilterFn'] = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually better to type the whole function rather than arguments. And this way we can avoid exporting GridStateColDef
| <span class="prop-name optional">width<sup><abbr title="optional">?</abbr></sup></span> | <span class="prop-type">number</span> | <span class="prop-default">100</span> | Set the width of the column. | | ||
| Name | Type | Default | Description | | ||
| :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| <span class="prop-name optional">aggregable<sup><abbr title="optional">?</abbr></sup> [<span class="plan-premium" title="Premium plan"></span>](/x/introduction/licensing/#premium-plan)</span> | <span class="prop-type">boolean</span> | <span class="prop-default">true</span> | If `true`, the cells of the column can be aggregated based. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Premium properties weren't documented here before, so this is a useful side-effect :)
@@ -173,7 +172,7 @@ const defaultColumnsStyles = { | |||
[GRID_DATETIME_COL_DEF.type as string]: { numFmt: 'dd.mm.yyyy hh:mm' }, | |||
}; | |||
|
|||
const serializeColumn = (column: GridStateColDef, columnsStyles: ColumnsStylesInterface) => { | |||
const serializeColumn = (column: GridColDef, columnsStyles: ColumnsStylesInterface) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use GridStateColDef
here, since we don't use any properties specific to GridStateColDef
, like computedWidth
groupedByColDef: GridColDef | GridStateColDef, | ||
applyHeaderName: boolean, | ||
) => { | ||
const getGroupingCriteriaProperties = (groupedByColDef: GridColDef, applyHeaderName: boolean) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as #7224 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
It's a nice dx
update, I too was confused on a couple of occasions about when to use which type, it's much better now 👍
Closes #7188
Changelog
Breaking changes
GridColumns
type was removed. UseGridColDef[]
instead.GridActionsColDef
interface was removed. UseGridColDef
instead.GridEnrichedColDef
type was removed. UseGridColDef
instead.GridStateColDef
type was removed.If you use it to type
searchPredicate
- useGridColumnsPanelProps['searchPredicate']
instead.If you use it to type
getApplyFilterFn
- useGridFilterOperator['getApplyFilterFn']
instead.