-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
propValidation.ts
54 lines (51 loc) · 2.11 KB
/
propValidation.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { warnOnce } from './warning';
import { isNumber } from '../../utils/utils';
import { DataGridProcessedProps } from '../../models/props/DataGridProps';
import { GridSignature } from '../../hooks/utils/useGridApiEventHandler';
export type PropValidator<TProps> = (props: TProps) => string | undefined;
export const propValidatorsDataGrid: PropValidator<DataGridProcessedProps>[] = [
(props) =>
(props.autoPageSize &&
props.autoHeight &&
[
'MUI X: `<DataGrid autoPageSize={true} autoHeight={true} />` are not valid props.',
'You cannot use both the `autoPageSize` and `autoHeight` props at the same time because `autoHeight` scales the height of the Data Grid according to the `pageSize`.',
'',
'Please remove one of these two props.',
].join('\n')) ||
undefined,
(props) =>
(props.paginationMode === 'client' &&
props.paginationMeta != null &&
[
'MUI X: Usage of the `paginationMeta` prop with client-side pagination (`paginationMode="client"`) has no effect.',
'`paginationMeta` is only meant to be used with `paginationMode="server"`.',
].join('\n')) ||
undefined,
(props) =>
(props.signature === GridSignature.DataGrid &&
props.paginationMode === 'client' &&
isNumber(props.rowCount) &&
[
'MUI X: Usage of the `rowCount` prop with client side pagination (`paginationMode="client"`) has no effect.',
'`rowCount` is only meant to be used with `paginationMode="server"`.',
].join('\n')) ||
undefined,
(props) =>
(props.paginationMode === 'server' &&
props.rowCount == null &&
!props.unstable_dataSource &&
[
"MUI X: The `rowCount` prop must be passed using `paginationMode='server'`",
'For more detail, see http://mui.com/components/data-grid/pagination/#index-based-pagination',
].join('\n')) ||
undefined,
];
export function validateProps<TProps>(props: TProps, validators: PropValidator<TProps>[]) {
validators.forEach((validator) => {
const message = validator(props);
if (message) {
warnOnce(message, 'error');
}
});
}