From 4d1a99824650391e11c5586b53dccb0e518d2d4e Mon Sep 17 00:00:00 2001 From: zombieJ Date: Wed, 27 Feb 2019 15:32:29 +0800 Subject: [PATCH] add component param in warning (#15078) * add component param in warning * update snapshot --- components/_util/warning.tsx | 4 ++-- components/breadcrumb/Breadcrumb.tsx | 4 +++- components/breadcrumb/__tests__/Breadcrumb.test.js | 2 +- components/card/index.tsx | 6 ++++-- components/cascader/__tests__/index.test.js | 2 +- components/cascader/index.tsx | 3 ++- components/date-picker/RangePicker.tsx | 6 +++++- components/date-picker/createPicker.tsx | 1 + components/drawer/index.tsx | 1 + components/dropdown/dropdown.tsx | 1 + components/form/Form.tsx | 2 +- components/form/FormItem.tsx | 3 ++- components/form/__tests__/message.test.js | 2 +- components/icon/__tests__/index.test.js | 2 +- components/icon/index.tsx | 7 ++++++- components/icon/utils.ts | 2 +- components/input/Input.tsx | 1 + components/menu/index.tsx | 4 +++- components/modal/confirm.tsx | 1 + components/popover/index.tsx | 3 ++- components/select/index.tsx | 3 ++- components/table/Table.tsx | 3 +++ components/table/__tests__/Table.test.js | 2 +- components/tabs/index.tsx | 3 ++- components/time-picker/__tests__/index.test.js | 2 +- components/time-picker/index.tsx | 3 ++- components/transfer/__tests__/index.test.js | 2 +- components/transfer/__tests__/search.test.js | 2 +- components/transfer/index.tsx | 7 ++++--- components/tree-select/index.tsx | 1 + 30 files changed, 58 insertions(+), 27 deletions(-) diff --git a/components/_util/warning.tsx b/components/_util/warning.tsx index 8dd4a8ce69..0fdb0b0f27 100644 --- a/components/_util/warning.tsx +++ b/components/_util/warning.tsx @@ -1,9 +1,9 @@ import warning from 'warning'; const warned: Record = {}; -export default (valid: boolean, message: string): void => { +export default (valid: boolean, component: string, message: string): void => { if (!valid && !warned[message]) { - warning(false, message); + warning(false, `[antd: ${component}] ${message}`); warned[message] = true; } }; diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx index 5007929c83..e47de7ec64 100755 --- a/components/breadcrumb/Breadcrumb.tsx +++ b/components/breadcrumb/Breadcrumb.tsx @@ -64,6 +64,7 @@ export default class Breadcrumb extends React.Component { const props = this.props; warning( !('linkRender' in props || 'nameRender' in props), + 'Breadcrumb', '`linkRender` and `nameRender` are removed, please use `itemRender` instead, ' + 'see: https://u.ant.design/item-render.', ); @@ -106,7 +107,8 @@ export default class Breadcrumb extends React.Component { } warning( element.type && element.type.__ANT_BREADCRUMB_ITEM, - "Breadcrumb only accepts Breadcrumb.Item as it's children", + 'Breadcrumb', + "Only accepts Breadcrumb.Item as it's children", ); return cloneElement(element, { separator, diff --git a/components/breadcrumb/__tests__/Breadcrumb.test.js b/components/breadcrumb/__tests__/Breadcrumb.test.js index c3b1d6bb0a..0a3bd98673 100644 --- a/components/breadcrumb/__tests__/Breadcrumb.test.js +++ b/components/breadcrumb/__tests__/Breadcrumb.test.js @@ -23,7 +23,7 @@ describe('Breadcrumb', () => { ); expect(errorSpy.mock.calls).toHaveLength(1); expect(errorSpy.mock.calls[0][0]).toMatch( - "Breadcrumb only accepts Breadcrumb.Item as it's children", + "Warning: [antd: Breadcrumb] Only accepts Breadcrumb.Item as it's children", ); }); diff --git a/components/card/index.tsx b/components/card/index.tsx index 7fe13a3da0..0f17850d85 100644 --- a/components/card/index.tsx +++ b/components/card/index.tsx @@ -71,11 +71,13 @@ export default class Card extends React.Component { if ('noHovering' in this.props) { warning( !this.props.noHovering, - '`noHovering` of Card is deprecated, you can remove it safely or use `hoverable` instead.', + 'Card', + '`noHovering` is deprecated, you can remove it safely or use `hoverable` instead.', ); warning( !!this.props.noHovering, - '`noHovering={false}` of Card is deprecated, use `hoverable` instead.', + 'Card', + '`noHovering={false}` is deprecated, use `hoverable` instead.', ); } } diff --git a/components/cascader/__tests__/index.test.js b/components/cascader/__tests__/index.test.js index fa84eaf18c..29f02344f8 100644 --- a/components/cascader/__tests__/index.test.js +++ b/components/cascader/__tests__/index.test.js @@ -425,7 +425,7 @@ describe('Cascader', () => { wrapper.find('input').simulate('change', { target: { value: 'a' } }); expect(wrapper.find('.ant-cascader-menu-item').length).toBe(2); expect(errorSpy).toBeCalledWith( - "Warning: 'limit' of showSearch in Cascader should be positive number or false.", + "Warning: [antd: Cascader] 'limit' of showSearch should be positive number or false.", ); }); }); diff --git a/components/cascader/index.tsx b/components/cascader/index.tsx index eb62a95e79..968f28e4a1 100644 --- a/components/cascader/index.tsx +++ b/components/cascader/index.tsx @@ -366,7 +366,8 @@ class Cascader extends React.Component { } else { warning( typeof limit !== 'number', - "'limit' of showSearch in Cascader should be positive number or false.", + 'Cascader', + "'limit' of showSearch should be positive number or false.", ); filtered = flattenOptions.filter(path => filter(this.state.inputValue, path, names)); } diff --git a/components/date-picker/RangePicker.tsx b/components/date-picker/RangePicker.tsx index 9eabea0a75..af65933920 100644 --- a/components/date-picker/RangePicker.tsx +++ b/components/date-picker/RangePicker.tsx @@ -291,7 +291,11 @@ class RangePicker extends React.Component { fixLocale(value, localeCode); fixLocale(showDate, localeCode); - warning(!('onOK' in props), 'It should be `RangePicker[onOk]`, instead of `onOK`!'); + warning( + !('onOK' in props), + 'RangePicker', + 'It should be `RangePicker[onOk]`, instead of `onOK`!', + ); const calendarClassName = classNames({ [`${prefixCls}-time`]: showTime, diff --git a/components/date-picker/createPicker.tsx b/components/date-picker/createPicker.tsx index 1069059872..2f99c557b6 100644 --- a/components/date-picker/createPicker.tsx +++ b/components/date-picker/createPicker.tsx @@ -172,6 +172,7 @@ export default function createPicker(TheCalendar: React.ComponentClass): any { warning( !('onOK' in props), + 'DatePicker', 'It should be `DatePicker[onOk]` or `MonthPicker[onOk]`, instead of `onOK`!', ); const calendar = ( diff --git a/components/drawer/index.tsx b/components/drawer/index.tsx index 7f176c7bfe..40b271b95c 100644 --- a/components/drawer/index.tsx +++ b/components/drawer/index.tsx @@ -235,6 +235,7 @@ class Drawer extends React.Component { // Warning if use other mode warning( !overlayProps.mode || overlayProps.mode === 'vertical', + 'Dropdown', `mode="${overlayProps.mode}" is not supported for Dropdown\'s Menu.`, ); diff --git a/components/form/Form.tsx b/components/form/Form.tsx index d8d0452157..b4bea3546c 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -226,7 +226,7 @@ export default class Form extends React.Component { constructor(props: FormProps) { super(props); - warning(!props.form, 'It is unnecessary to pass `form` to `Form` after antd@1.7.0.'); + warning(!props.form, 'Form', 'It is unnecessary to pass `form` to `Form` after antd@1.7.0.'); } getChildContext() { diff --git a/components/form/FormItem.tsx b/components/form/FormItem.tsx index 8520a60687..9735e32a0e 100644 --- a/components/form/FormItem.tsx +++ b/components/form/FormItem.tsx @@ -70,7 +70,8 @@ export default class FormItem extends React.Component { warning( this.getControls(children, true).length <= 1 || (help !== undefined || validateStatus !== undefined), - '`Form.Item` cannot generate `validateStatus` and `help` automatically, ' + + 'Form.Item', + 'Cannot generate `validateStatus` and `help` automatically, ' + 'while there are more than one `getFieldDecorator` in it.', ); } diff --git a/components/form/__tests__/message.test.js b/components/form/__tests__/message.test.js index 98b61ace5a..054302b1cc 100644 --- a/components/form/__tests__/message.test.js +++ b/components/form/__tests__/message.test.js @@ -103,7 +103,7 @@ describe('Form', () => { mount(); expect(errorSpy).toBeCalledWith( - 'Warning: `Form.Item` cannot generate `validateStatus` and `help` automatically, while there are more than one `getFieldDecorator` in it.', + 'Warning: [antd: Form.Item] Cannot generate `validateStatus` and `help` automatically, while there are more than one `getFieldDecorator` in it.', ); errorSpy.mockRestore(); }); diff --git a/components/icon/__tests__/index.test.js b/components/icon/__tests__/index.test.js index 94ac450b81..f2623fd553 100644 --- a/components/icon/__tests__/index.test.js +++ b/components/icon/__tests__/index.test.js @@ -121,7 +121,7 @@ describe('Icon', () => { it('warns', () => { mount(); expect(errorSpy).toBeCalledWith( - "Warning: The icon name 'clock-circle-o' already specify a theme 'outlined', the 'theme' prop 'filled' will be ignored.", + "Warning: [antd: Icon] The icon name 'clock-circle-o' already specify a theme 'outlined', the 'theme' prop 'filled' will be ignored.", ); }); }); diff --git a/components/icon/index.tsx b/components/icon/index.tsx index 4df284e9f0..4530a1536e 100755 --- a/components/icon/index.tsx +++ b/components/icon/index.tsx @@ -90,7 +90,8 @@ const Icon: IconComponent = props => { warning( Boolean(type || Component || children), - 'Icon should have `type` prop or `component` prop or `children`.', + 'Icon', + 'Should have `type` prop or `component` prop or `children`.', ); const classString = classNames( @@ -136,6 +137,7 @@ const Icon: IconComponent = props => { (React.Children.count(children) === 1 && React.isValidElement(children) && React.Children.only(children).type === 'use'), + 'Icon', 'Make sure that you provide correct `viewBox`' + ' prop (default `0 0 1024 1024`) to the icon.', ); @@ -152,6 +154,7 @@ const Icon: IconComponent = props => { const themeInName = getThemeFromTypeName(type); warning( !themeInName || theme === themeInName, + 'Icon', `The icon name '${type}' already specify a theme '${themeInName}',` + ` the 'theme' prop '${theme}' will be ignored.`, ); @@ -195,6 +198,7 @@ const Icon: IconComponent = props => { function unstable_ChangeThemeOfIconsDangerously(theme?: ThemeType) { warning( false, + 'Icon', `You are using the unstable method 'Icon.unstable_ChangeThemeOfAllIconsDangerously', ` + `make sure that all the icons with theme '${theme}' display correctly.`, ); @@ -204,6 +208,7 @@ function unstable_ChangeThemeOfIconsDangerously(theme?: ThemeType) { function unstable_ChangeDefaultThemeOfIcons(theme: ThemeType) { warning( false, + 'Icon', `You are using the unstable method 'Icon.unstable_ChangeDefaultThemeOfIcons', ` + `make sure that all the icons with theme '${theme}' display correctly.`, ); diff --git a/components/icon/utils.ts b/components/icon/utils.ts index df20df85af..a9777adf35 100644 --- a/components/icon/utils.ts +++ b/components/icon/utils.ts @@ -43,7 +43,7 @@ export function withThemeSuffix(type: string, theme: ThemeType) { } else if (theme === 'twoTone') { result += '-twotone'; } else { - warning(false, `This icon '${type}' has unknown theme '${theme}'`); + warning(false, 'Icon', `This icon '${type}' has unknown theme '${theme}'`); } return result; } diff --git a/components/input/Input.tsx b/components/input/Input.tsx index b8710735b0..e00382a016 100644 --- a/components/input/Input.tsx +++ b/components/input/Input.tsx @@ -93,6 +93,7 @@ class Input extends React.Component { if (hasPrefixSuffix(prevProps) !== hasPrefixSuffix(this.props)) { warning( this.input !== document.activeElement, + 'Input', `When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ`, ); } diff --git a/components/menu/index.tsx b/components/menu/index.tsx index f2c984dd09..a688c0b3bb 100644 --- a/components/menu/index.tsx +++ b/components/menu/index.tsx @@ -88,13 +88,15 @@ export default class Menu extends React.Component { warning( !('onOpen' in props || 'onClose' in props), + 'Menu', '`onOpen` and `onClose` are removed, please use `onOpenChange` instead, ' + 'see: https://u.ant.design/menu-on-open-change.', ); warning( !('inlineCollapsed' in props && props.mode !== 'inline'), - "`inlineCollapsed` should only be used when Menu's `mode` is inline.", + 'Menu', + '`inlineCollapsed` should only be used when `mode` is inline.', ); let openKeys; diff --git a/components/modal/confirm.tsx b/components/modal/confirm.tsx index b3a7f25728..ced2c214ae 100644 --- a/components/modal/confirm.tsx +++ b/components/modal/confirm.tsx @@ -33,6 +33,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => { } = props; warning( !('iconType' in props), + 'Modal', `The property 'iconType' is deprecated. Use the property 'icon' instead.`, ); const icon = props.icon ? props.icon : iconType; diff --git a/components/popover/index.tsx b/components/popover/index.tsx index f1e6c9761f..6b0300f23b 100644 --- a/components/popover/index.tsx +++ b/components/popover/index.tsx @@ -28,7 +28,8 @@ export default class Popover extends React.Component { const { title, content } = this.props; warning( !('overlay' in this.props), - 'Popover[overlay] is removed, please use Popover[content] instead, ' + + 'Popover', + '`overlay` is removed, please use `content` instead, ' + 'see: https://u.ant.design/popover-content', ); return ( diff --git a/components/select/index.tsx b/components/select/index.tsx index 1875bf3958..247eca7eb5 100755 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -131,7 +131,8 @@ export default class Select extends React.Component extends React.Component, TableState< warning( !('columnsPageRange' in props || 'columnsPageSize' in props), + 'Table', '`columnsPageRange` and `columnsPageSize` are removed, please use ' + 'fixed columns instead, see: https://u.ant.design/fixed-columns.', ); warning( !('expandedRowRender' in props) || !('scroll' in props), + 'Table', '`expandedRowRender` and `scroll` are not compatible. Please use one of them at one time.', ); @@ -731,6 +733,7 @@ export default class Table extends React.Component, TableState< typeof rowKey === 'function' ? rowKey(record, index) : (record as any)[rowKey!]; warning( recordKey !== undefined, + 'Table', 'Each record in dataSource of table should have a unique `key` prop, ' + 'or set `rowKey` of Table to an unique primary key, ' + 'see https://u.ant.design/table-row-key', diff --git a/components/table/__tests__/Table.test.js b/components/table/__tests__/Table.test.js index 7e19002371..b9db54cc9c 100644 --- a/components/table/__tests__/Table.test.js +++ b/components/table/__tests__/Table.test.js @@ -90,7 +90,7 @@ describe('Table', () => { it('warning if both `expandedRowRender` & `scroll` are used', () => { mount( null} scroll={{}} />); expect(warnSpy).toBeCalledWith( - 'Warning: `expandedRowRender` and `scroll` are not compatible. Please use one of them at one time.', + 'Warning: [antd: Table] `expandedRowRender` and `scroll` are not compatible. Please use one of them at one time.', ); }); }); diff --git a/components/tabs/index.tsx b/components/tabs/index.tsx index 499dab8bd9..accce0caa0 100755 --- a/components/tabs/index.tsx +++ b/components/tabs/index.tsx @@ -110,7 +110,8 @@ export default class Tabs extends React.Component { warning( !(type.indexOf('card') >= 0 && (size === 'small' || size === 'large')), - "Tabs[type=card|editable-card] doesn't have small or large size, it's by design.", + 'Tabs', + "`type=card|editable-card` doesn't have small or large size, it's by design.", ); const prefixCls = getPrefixCls('tabs', customizePrefixCls); const cls = classNames(className, { diff --git a/components/time-picker/__tests__/index.test.js b/components/time-picker/__tests__/index.test.js index 17762599a4..b7c121345e 100644 --- a/components/time-picker/__tests__/index.test.js +++ b/components/time-picker/__tests__/index.test.js @@ -30,7 +30,7 @@ describe('TimePicker', () => { it('allowEmpty deprecated', () => { mount(); expect(errorSpy).toBeCalledWith( - 'Warning: `allowEmpty` in TimePicker is deprecated. Please use `allowClear` instead.', + 'Warning: [antd: TimePicker] `allowEmpty` is deprecated. Please use `allowClear` instead.', ); }); diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx index 6148ec0435..0dbdb9b95f 100644 --- a/components/time-picker/index.tsx +++ b/components/time-picker/index.tsx @@ -98,7 +98,8 @@ class TimePicker extends React.Component { warning( !('allowEmpty' in props), - '`allowEmpty` in TimePicker is deprecated. Please use `allowClear` instead.', + 'TimePicker', + '`allowEmpty` is deprecated. Please use `allowClear` instead.', ); } diff --git a/components/transfer/__tests__/index.test.js b/components/transfer/__tests__/index.test.js index 61467912f8..90f020f57e 100644 --- a/components/transfer/__tests__/index.test.js +++ b/components/transfer/__tests__/index.test.js @@ -269,7 +269,7 @@ describe('Transfer', () => { ).toEqual('old1'); expect(consoleErrorSpy).toBeCalledWith( - 'Warning: Transfer[notFoundContent] and Transfer[searchPlaceholder] will be removed, please use Transfer[locale] instead.', + 'Warning: [antd: Transfer] `notFoundContent` and `searchPlaceholder` will be removed, please use `locale` instead.', ); consoleErrorSpy.mockRestore(); }); diff --git a/components/transfer/__tests__/search.test.js b/components/transfer/__tests__/search.test.js index 2b3147bf9a..54c306eb8c 100644 --- a/components/transfer/__tests__/search.test.js +++ b/components/transfer/__tests__/search.test.js @@ -83,7 +83,7 @@ describe('Search', () => { .simulate('change', { target: { value: 'a' } }); expect(errorSpy.mock.calls[0][0]).toMatch( - 'Warning: `onSearchChange` in Transfer is deprecated. Please use `onSearch` instead.', + 'Warning: [antd: Transfer] `onSearchChange` is deprecated. Please use `onSearch` instead.', ); expect(onSearchChange.mock.calls[0][0]).toEqual('left'); expect(onSearchChange.mock.calls[0][1].target.value).toEqual('a'); diff --git a/components/transfer/index.tsx b/components/transfer/index.tsx index d3afc3467d..4595e33e26 100644 --- a/components/transfer/index.tsx +++ b/components/transfer/index.tsx @@ -110,8 +110,9 @@ export default class Transfer extends React.Component { warning( !('notFoundContent' in props || 'searchPlaceholder' in props), - 'Transfer[notFoundContent] and Transfer[searchPlaceholder] will be removed, ' + - 'please use Transfer[locale] instead.', + 'Transfer', + '`notFoundContent` and `searchPlaceholder` will be removed, ' + + 'please use `locale` instead.', ); const { selectedKeys = [], targetKeys = [] } = props; @@ -277,7 +278,7 @@ export default class Transfer extends React.Component { [`${direction}Filter`]: value, }); if (onSearchChange) { - warning(false, '`onSearchChange` in Transfer is deprecated. Please use `onSearch` instead.'); + warning(false, 'Transfer', '`onSearchChange` is deprecated. Please use `onSearch` instead.'); onSearchChange(direction, e); } if (onSearch) { diff --git a/components/tree-select/index.tsx b/components/tree-select/index.tsx index 16564e39e6..92b508eed9 100644 --- a/components/tree-select/index.tsx +++ b/components/tree-select/index.tsx @@ -29,6 +29,7 @@ export default class TreeSelect extends React.Component { warning( props.multiple !== false || !props.treeCheckable, + 'TreeSelect', '`multiple` will alway be `true` when `treeCheckable` is true', ); }