From c4d8c4770c8811a64c217f157ea0f4258f53eef7 Mon Sep 17 00:00:00 2001 From: Benjy Cui Date: Fri, 2 Dec 2016 15:07:33 +0800 Subject: [PATCH] Add upgrade warning (#4028) * chore: add upgrade warning for time related value * chore: update warning * chore: update demo url --- components/breadcrumb/Breadcrumb.tsx | 3 ++- components/calendar/index.tsx | 9 ++++++++- components/date-picker/RangePicker.tsx | 12 +++++++++++- components/date-picker/createPicker.tsx | 9 ++++++++- components/date-picker/wrapPicker.tsx | 10 +++++----- components/form/Form.tsx | 3 ++- components/menu/index.tsx | 3 ++- components/popover/index.tsx | 7 ++++++- components/table/Table.tsx | 3 +-- components/time-picker/index.tsx | 10 ++++++++-- 10 files changed, 53 insertions(+), 16 deletions(-) diff --git a/components/breadcrumb/Breadcrumb.tsx b/components/breadcrumb/Breadcrumb.tsx index 1342d3df53..a933ab2a5f 100755 --- a/components/breadcrumb/Breadcrumb.tsx +++ b/components/breadcrumb/Breadcrumb.tsx @@ -56,7 +56,8 @@ export default class Breadcrumb extends React.Component { const props = this.props; warning( !('linkRender' in props || 'nameRender' in props), - '`linkRender` and `nameRender` are removed, please use `itemRender` instead.' + '`linkRender` and `nameRender` are removed, please use `itemRender` instead, ' + + 'see: http://u.ant.design/item-render.' ); } diff --git a/components/calendar/index.tsx b/components/calendar/index.tsx index 116abdb7b0..d0d35e1178 100644 --- a/components/calendar/index.tsx +++ b/components/calendar/index.tsx @@ -64,8 +64,15 @@ export default class Calendar extends React.Component { constructor(props) { super(props); + const value = props.value || props.defaultValue || moment(); + if (!(value instanceof moment)) { + throw new Error( + 'The value/defaultValue of Calendar must be a moment object after `antd@2.0`, ' + + 'see: http://u.ant.design/calendar-value' + ); + } this.state = { - value: props.value || props.defaultValue || moment(), + value, mode: props.mode, }; } diff --git a/components/date-picker/RangePicker.tsx b/components/date-picker/RangePicker.tsx index c36e118226..ba6e3a54fc 100644 --- a/components/date-picker/RangePicker.tsx +++ b/components/date-picker/RangePicker.tsx @@ -14,8 +14,18 @@ export default class RangePicker extends React.Component { constructor(props) { super(props); + const value = props.value || props.defaultValue || []; + if ( + value[0] && !(value[0] instanceof moment) || + value[1] && !(value[1] instanceof moment) + ) { + throw new Error( + 'The value/defaultValue of RangePicker must be a moment object array after `antd@2.0`, ' + + 'see: http://u.ant.design/date-picker-value' + ); + } this.state = { - value: props.value || props.defaultValue || [], + value, open: props.open, }; } diff --git a/components/date-picker/createPicker.tsx b/components/date-picker/createPicker.tsx index 12fd1f8799..73771cd44f 100644 --- a/components/date-picker/createPicker.tsx +++ b/components/date-picker/createPicker.tsx @@ -24,8 +24,15 @@ export default function createPicker(TheCalendar) { getInitialState() { const props = this.props; + const value = props.value || props.defaultValue; + if (value && !(value instanceof moment)) { + throw new Error( + 'The value/defaultValue of DatePicker or MonthPicker must be ' + + 'a moment object after `antd@2.0`, see: http://u.ant.design/date-picker-value' + ); + } return { - value: props.value || props.defaultValue, + value, tempValue: undefined, }; }, diff --git a/components/date-picker/wrapPicker.tsx b/components/date-picker/wrapPicker.tsx index 2d46210ab2..31713acdf2 100644 --- a/components/date-picker/wrapPicker.tsx +++ b/components/date-picker/wrapPicker.tsx @@ -22,6 +22,10 @@ function getColumns({ showHour, showMinute, showSecond }) { export default function wrapPicker(Picker, defaultFormat?) { const PickerWrapper = React.createClass({ + contextTypes: { + antLocale: PropTypes.object, + }, + getDefaultProps() { return { format: defaultFormat || 'YYYY-MM-DD', @@ -42,10 +46,6 @@ export default function wrapPicker(Picker, defaultFormat?) { }; }, - contextTypes: { - antLocale: PropTypes.object, - }, - handleOpenChange(open) { const { onOpenChange, toggleOpen } = this.props; onOpenChange(open); @@ -54,7 +54,7 @@ export default function wrapPicker(Picker, defaultFormat?) { warning( false, '`toggleOpen` is deprecated and will be removed in the future, ' + - 'please use `onOpenChange` instead' + 'please use `onOpenChange` instead, see: http://u.ant.design/date-picker-on-open-change' ); toggleOpen({open}); } diff --git a/components/form/Form.tsx b/components/form/Form.tsx index d2c0fc2475..90e7c78a5d 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -126,7 +126,8 @@ export default class Form extends React.Component { deprecatedGetFieldProps(name, option) { warning( false, - '`getFieldProps` is not recommended, please use `getFieldDecorator` instead' + '`getFieldProps` is not recommended, please use `getFieldDecorator` instead, ' + + 'see: http://u.ant.design/get-field-decorator' ); return this.__getFieldProps(name, option); }, diff --git a/components/menu/index.tsx b/components/menu/index.tsx index f72b94a79a..5044063274 100644 --- a/components/menu/index.tsx +++ b/components/menu/index.tsx @@ -67,7 +67,8 @@ export default class Menu extends React.Component { warning( !('onOpen' in props || 'onClose' in props), - '`onOpen` and `onClose` are removed, please use `onOpenChange` instead.' + '`onOpen` and `onClose` are removed, please use `onOpenChange` instead, ' + + 'see: http://u.ant.design/menu-on-open-change.' ); this.state = { diff --git a/components/popover/index.tsx b/components/popover/index.tsx index 3f79be6956..a8672af845 100644 --- a/components/popover/index.tsx +++ b/components/popover/index.tsx @@ -2,6 +2,7 @@ import React from 'react'; import assign from 'object-assign'; import Tooltip from '../tooltip'; import { AbstractTooltipProps } from '../tooltip'; +import warning from '../_util/warning'; export interface PopoverProps extends AbstractTooltipProps { title?: React.ReactNode; @@ -29,7 +30,11 @@ export default class Popover extends React.Component { getOverlay() { const { title, prefixCls, content } = this.props; - + warning( + !('overlay' in this.props), + 'Popover[overlay] is removed, please use Popover[content] instead, ' + + 'see: http://u.ant.design/popover-content' + ); return (
{title &&
{title}
} diff --git a/components/table/Table.tsx b/components/table/Table.tsx index 827e539d8d..271bd57455 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -131,8 +131,7 @@ export default class Table extends React.Component, any> { warning( !('columnsPageRange' in props || 'columnsPageSize' in props), '`columnsPageRange` and `columnsPageSize` are removed, please use ' + - '[fixed columns](http://ant.design/components/table/#components-table-demo-fixed-columns) ' + - 'instead.' + 'fixed columns instead, see: http://u.ant.design/fixed-columns.' ); const pagination = props.pagination || {}; diff --git a/components/time-picker/index.tsx b/components/time-picker/index.tsx index 68e36632b2..f8ad92e502 100644 --- a/components/time-picker/index.tsx +++ b/components/time-picker/index.tsx @@ -63,9 +63,15 @@ export default class TimePicker extends React.Component { constructor(props) { super(props); - + const value = props.value || props.defaultValue; + if (value && !(value instanceof moment)) { + throw new Error( + 'The value/defaultValue of TimePicker must be a moment object after `antd@2.0`, ' + + 'see: http://u.ant.design/time-picker-value' + ); + } this.state = { - value: props.value || props.defaultValue, + value, }; }