fix: remove defaultProps in prep for react 19 (#50266)

This commit is contained in:
RJ 2024-08-06 20:20:45 +08:00 committed by GitHub
parent 783f6dd3c2
commit b74bd01ca1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 86 additions and 158 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: dev
Removed defaultProps from React functional components since they will be deprecated for React 19

View File

@ -9,17 +9,17 @@ import { uniqueId, noop } from 'lodash';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
const DateInput = ( { const DateInput = ( {
disabled, disabled = false,
value, value,
onChange, onChange,
dateFormat, dateFormat,
label, label,
describedBy, describedBy,
error, error,
onFocus, onFocus = () => {},
onBlur, onBlur = () => {},
onKeyDown, onKeyDown = noop,
errorPosition, errorPosition = 'bottom center',
} ) => { } ) => {
const classes = classnames( 'woocommerce-calendar__input', { const classes = classnames( 'woocommerce-calendar__input', {
'is-empty': value.length === 0, 'is-empty': value.length === 0,
@ -73,12 +73,4 @@ DateInput.propTypes = {
onKeyDown: PropTypes.func, onKeyDown: PropTypes.func,
}; };
DateInput.defaultProps = {
disabled: false,
onFocus: () => {},
onBlur: () => {},
errorPosition: 'bottom center',
onKeyDown: noop,
};
export default DateInput; export default DateInput;

View File

@ -15,7 +15,12 @@ import { createElement } from '@wordpress/element';
* @param {string} props.visibleFormat * @param {string} props.visibleFormat
* @return {Object} - * @return {Object} -
*/ */
const Date = ( { date, machineFormat, screenReaderFormat, visibleFormat } ) => { const Date = ( {
date,
machineFormat = 'Y-m-d H:i:s',
screenReaderFormat = 'F j, Y',
visibleFormat = 'Y-m-d',
} ) => {
return ( return (
<time dateTime={ formatDate( machineFormat, date ) }> <time dateTime={ formatDate( machineFormat, date ) }>
<span aria-hidden="true"> <span aria-hidden="true">
@ -48,10 +53,4 @@ Date.propTypes = {
visibleFormat: PropTypes.string, visibleFormat: PropTypes.string,
}; };
Date.defaultProps = {
machineFormat: 'Y-m-d H:i:s',
screenReaderFormat: 'F j, Y',
visibleFormat: 'Y-m-d',
};
export default Date; export default Date;

View File

@ -22,7 +22,11 @@ import Menu from './menu';
* @param {string} props.label * @param {string} props.label
* @return {Object} - * @return {Object} -
*/ */
const SummaryList = ( { children, isDropdownBreakpoint, label } ) => { const SummaryList = ( {
children,
isDropdownBreakpoint,
label = __( 'Performance Indicators', 'woocommerce' ),
} ) => {
const items = children( {} ); const items = children( {} );
// We default to "one" because we can't have empty children. // We default to "one" because we can't have empty children.
const itemCount = Children.count( items ) || 1; const itemCount = Children.count( items ) || 1;
@ -79,10 +83,6 @@ SummaryList.propTypes = {
label: PropTypes.string, label: PropTypes.string,
}; };
SummaryList.defaultProps = {
label: __( 'Performance Indicators', 'woocommerce' ),
};
export default withViewportMatch( { export default withViewportMatch( {
isDropdownBreakpoint: '< large', isDropdownBreakpoint: '< large',
} )( SummaryList ); } )( SummaryList );

View File

@ -39,18 +39,18 @@ import { Text } from '../experimental';
const SummaryNumber = ( { const SummaryNumber = ( {
children, children,
delta, delta,
href, href = '',
hrefType, hrefType = 'wc-admin',
isOpen, isOpen = false,
label, label,
labelTooltipText, labelTooltipText,
onToggle, onToggle,
prevLabel, prevLabel = __( 'Previous period:', 'woocommerce' ),
prevValue, prevValue,
reverseTrend, reverseTrend = false,
selected, selected = false,
value, value,
onLinkClickCallback, onLinkClickCallback = noop,
} ) => { } ) => {
const liClasses = classnames( 'woocommerce-summary__item-container', { const liClasses = classnames( 'woocommerce-summary__item-container', {
'is-dropdown-button': onToggle, 'is-dropdown-button': onToggle,
@ -238,14 +238,4 @@ SummaryNumber.propTypes = {
onLinkClickCallback: PropTypes.func, onLinkClickCallback: PropTypes.func,
}; };
SummaryNumber.defaultProps = {
href: '',
hrefType: 'wc-admin',
isOpen: false,
prevLabel: __( 'Previous period:', 'woocommerce' ),
reverseTrend: false,
selected: false,
onLinkClickCallback: noop,
};
export default SummaryNumber; export default SummaryNumber;

View File

@ -13,9 +13,16 @@ import { createElement } from '@wordpress/element';
import TimelineGroup from './timeline-group'; import TimelineGroup from './timeline-group';
import { sortByDateUsing, groupItemsUsing } from './util'; import { sortByDateUsing, groupItemsUsing } from './util';
const Timeline = ( props ) => { const Timeline = ( {
const { className, items, groupBy, orderBy, dateFormat, clockFormat } = className = '',
props; items = [],
groupBy = 'day',
orderBy = 'desc',
/* translators: PHP date format string used to display dates, see php.net/date. */
dateFormat = __( 'F j, Y', 'woocommerce' ),
/* translators: PHP clock format string used to display times, see php.net/date. */
clockFormat = __( 'g:ia', 'woocommerce' ),
} ) => {
const timelineClassName = classnames( 'woocommerce-timeline', className ); const timelineClassName = classnames( 'woocommerce-timeline', className );
// Early return in case no data was passed to the component. // Early return in case no data was passed to the component.
@ -111,16 +118,5 @@ Timeline.propTypes = {
clockFormat: PropTypes.string, clockFormat: PropTypes.string,
}; };
Timeline.defaultProps = {
className: '',
items: [],
groupBy: 'day',
orderBy: 'desc',
/* translators: PHP date format string used to display dates, see php.net/date. */
dateFormat: __( 'F j, Y', 'woocommerce' ),
/* translators: PHP clock format string used to display times, see php.net/date. */
clockFormat: __( 'g:ia', 'woocommerce' ),
};
export { orderByOptions, groupByOptions } from './util'; export { orderByOptions, groupByOptions } from './util';
export default Timeline; export default Timeline;

View File

@ -11,8 +11,12 @@ import { createElement } from '@wordpress/element';
import TimelineItem from './timeline-item'; import TimelineItem from './timeline-item';
import { sortByDateUsing } from './util'; import { sortByDateUsing } from './util';
const TimelineGroup = ( props ) => { const TimelineGroup = ( {
const { group, className, orderBy, clockFormat } = props; group = { title: '', items: [] },
className = '',
orderBy = 'desc',
clockFormat,
} ) => {
const groupClassName = classnames( const groupClassName = classnames(
'woocommerce-timeline-group', 'woocommerce-timeline-group',
className className
@ -102,13 +106,4 @@ TimelineGroup.propTypes = {
clockFormat: PropTypes.string, clockFormat: PropTypes.string,
}; };
TimelineGroup.defaultProps = {
className: '',
group: {
title: '',
items: [],
},
orderBy: 'desc',
};
export default TimelineGroup; export default TimelineGroup;

View File

@ -6,9 +6,7 @@ import { format } from '@wordpress/date';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { createElement } from '@wordpress/element'; import { createElement } from '@wordpress/element';
const TimelineItem = ( props ) => { const TimelineItem = ( { item = {}, className = '', clockFormat } ) => {
const { item, className, clockFormat } = props;
const itemClassName = classnames( 'woocommerce-timeline-item', className ); const itemClassName = classnames( 'woocommerce-timeline-item', className );
const itemTimeString = format( clockFormat, item.date ); const itemTimeString = format( clockFormat, item.date );
@ -74,9 +72,4 @@ TimelineItem.propTypes = {
} ).isRequired, } ).isRequired,
}; };
TimelineItem.defaultProps = {
className: '',
item: {},
};
export default TimelineItem; export default TimelineItem;

View File

@ -17,7 +17,7 @@ import Tag from '../tag';
* @param {Array} props.items * @param {Array} props.items
* @return {Object} - * @return {Object} -
*/ */
const ViewMoreList = ( { items } ) => { const ViewMoreList = ( { items = [] } ) => {
return ( return (
<Tag <Tag
className="woocommerce-view-more-list" className="woocommerce-view-more-list"
@ -49,8 +49,4 @@ ViewMoreList.propTypes = {
items: PropTypes.arrayOf( PropTypes.node ), items: PropTypes.arrayOf( PropTypes.node ),
}; };
ViewMoreList.defaultProps = {
items: [],
};
export default ViewMoreList; export default ViewMoreList;

View File

@ -15,7 +15,7 @@ import {
useUserPreferences, useUserPreferences,
getVisibleTasks, getVisibleTasks,
} from '@woocommerce/data'; } from '@woocommerce/data';
import { getHistory, addHistoryListener } from '@woocommerce/navigation'; import { addHistoryListener } from '@woocommerce/navigation';
import { recordEvent } from '@woocommerce/tracks'; import { recordEvent } from '@woocommerce/tracks';
import { useSlot } from '@woocommerce/experimental'; import { useSlot } from '@woocommerce/experimental';
import { import {
@ -503,8 +503,4 @@ export const ActivityPanel = ( { isEmbedded, query } ) => {
); );
}; };
ActivityPanel.defaultProps = {
getHistory,
};
export default ActivityPanel; export default ActivityPanel;

View File

@ -15,7 +15,7 @@ import {
SETTINGS_STORE_NAME, SETTINGS_STORE_NAME,
} from '@woocommerce/data'; } from '@woocommerce/data';
import { compose } from 'redux'; import { compose } from 'redux';
import { recordEvent } from '@woocommerce/tracks'; import { recordEvent as fallbackRecordEvent } from '@woocommerce/tracks';
/** /**
* Internal dependencies * Internal dependencies
@ -359,15 +359,18 @@ function getListItems( props ) {
} ) ); } ) );
} }
export const HelpPanel = ( props ) => { export const HelpPanel = ( {
const { taskName } = props; taskName,
recordEvent = fallbackRecordEvent,
...props
} ) => {
useEffect( () => { useEffect( () => {
props.recordEvent( 'help_panel_open', { recordEvent( 'help_panel_open', {
task_name: taskName || 'homescreen', task_name: taskName || 'homescreen',
} ); } );
}, [ taskName ] ); }, [ taskName, recordEvent ] );
const listItems = getListItems( props ); const listItems = getListItems( { taskName, recordEvent, ...props } );
return ( return (
<Fragment> <Fragment>
@ -382,10 +385,6 @@ export const HelpPanel = ( props ) => {
); );
}; };
HelpPanel.defaultProps = {
recordEvent,
};
export default compose( export default compose(
withSelect( ( select ) => { withSelect( ( select ) => {
const { getSettings } = select( SETTINGS_STORE_NAME ); const { getSettings } = select( SETTINGS_STORE_NAME );

View File

@ -7,7 +7,7 @@ import { Fragment, useRef, useState } from '@wordpress/element';
import { compose } from '@wordpress/compose'; import { compose } from '@wordpress/compose';
import { focus } from '@wordpress/dom'; import { focus } from '@wordpress/dom';
import { withDispatch, withSelect } from '@wordpress/data'; import { withDispatch, withSelect } from '@wordpress/data';
import { get, noop, partial, uniq } from 'lodash'; import { get, partial, uniq } from 'lodash';
import { __, sprintf } from '@wordpress/i18n'; import { __, sprintf } from '@wordpress/i18n';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { STORE_KEY as CES_STORE_KEY } from '@woocommerce/customer-effort-score'; import { STORE_KEY as CES_STORE_KEY } from '@woocommerce/customer-effort-score';
@ -50,17 +50,23 @@ const ReportTable = ( props ) => {
getRowsContent, getRowsContent,
getSummary, getSummary,
isRequesting, isRequesting,
primaryData, primaryData = {},
tableData, tableData = {
items: {
data: [],
totalResults: 0,
},
query: {},
},
endpoint, endpoint,
// These props are not used in the render function, but are destructured // These props are not used in the render function, but are destructured
// so they are not included in the `tableProps` variable. // so they are not included in the `tableProps` variable.
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
itemIdField, itemIdField,
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
tableQuery, tableQuery = {},
compareBy, compareBy,
compareParam, compareParam = 'filter',
searchBy, searchBy,
labels = {}, labels = {},
...tableProps ...tableProps
@ -249,7 +255,7 @@ const ReportTable = ( props ) => {
}; };
const onSearchChange = ( values ) => { const onSearchChange = ( values ) => {
const { baseSearchQuery, addCesSurveyForCustomerSearch } = props; const { baseSearchQuery = {}, addCesSurveyForCustomerSearch } = props;
// A comma is used as a separator between search terms, so we want to escape // A comma is used as a separator between search terms, so we want to escape
// any comma they contain. // any comma they contain.
const searchTerms = values.map( ( v ) => const searchTerms = values.map( ( v ) =>
@ -553,22 +559,6 @@ ReportTable.propTypes = {
title: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
}; };
ReportTable.defaultProps = {
primaryData: {},
tableData: {
items: {
data: [],
totalResults: 0,
},
query: {},
},
tableQuery: {},
compareParam: 'filter',
downloadable: false,
onSearch: noop,
baseSearchQuery: {},
};
const EMPTY_ARRAY = []; const EMPTY_ARRAY = [];
const EMPTY_OBJECT = {}; const EMPTY_OBJECT = {};

View File

@ -360,17 +360,8 @@ function OrdersPanel( { unreadOrdersCount, orderStatuses } ) {
} }
OrdersPanel.propTypes = { OrdersPanel.propTypes = {
isError: PropTypes.bool,
isRequesting: PropTypes.bool,
unreadOrdersCount: PropTypes.number, unreadOrdersCount: PropTypes.number,
orders: PropTypes.array.isRequired,
orderStatuses: PropTypes.array, orderStatuses: PropTypes.array,
}; };
OrdersPanel.defaultProps = {
orders: [],
isError: false,
isRequesting: false,
};
export default OrdersPanel; export default OrdersPanel;

View File

@ -24,8 +24,11 @@ const KnowledgeBase = ( {
posts, posts,
isLoading, isLoading,
error, error,
title, title = __( 'WooCommerce knowledge base', 'woocommerce' ),
description, description = __(
'Learn the ins and outs of successful marketing from the experts at WooCommerce.',
'woocommerce'
),
category, category,
} ) => { } ) => {
const [ page, updatePage ] = useState( 1 ); const [ page, updatePage ] = useState( 1 );
@ -227,14 +230,6 @@ KnowledgeBase.propTypes = {
category: PropTypes.string, category: PropTypes.string,
}; };
KnowledgeBase.defaultProps = {
title: __( 'WooCommerce knowledge base', 'woocommerce' ),
description: __(
'Learn the ins and outs of successful marketing from the experts at WooCommerce.',
'woocommerce'
),
};
export { KnowledgeBase }; export { KnowledgeBase };
export default compose( export default compose(

View File

@ -19,8 +19,11 @@ import Card from '../card';
const RecommendedExtensions = ( { const RecommendedExtensions = ( {
extensions, extensions,
isLoading, isLoading,
title, title = __( 'Recommended extensions', 'woocommerce' ),
description, description = __(
'Great marketing requires the right tools. Take your marketing to the next level with our recommended marketing extensions.',
'woocommerce'
),
category, category,
} ) => { } ) => {
if ( extensions.length === 0 && ! isLoading ) { if ( extensions.length === 0 && ! isLoading ) {
@ -95,14 +98,6 @@ RecommendedExtensions.propTypes = {
category: PropTypes.string, category: PropTypes.string,
}; };
RecommendedExtensions.defaultProps = {
title: __( 'Recommended extensions', 'woocommerce' ),
description: __(
'Great marketing requires the right tools. Take your marketing to the next level with our recommended marketing extensions.',
'woocommerce'
),
};
export { RecommendedExtensions }; export { RecommendedExtensions };
export { default as RecommendedExtensionsPlaceholder } from './placeholder'; export { default as RecommendedExtensionsPlaceholder } from './placeholder';

View File

@ -27,10 +27,10 @@ const ProductsControl = ( {
error, error,
onChange, onChange,
onSearch, onSearch,
selected, selected = [],
products, products = [],
isLoading, isLoading = true,
isCompact, isCompact = false,
} ) => { } ) => {
const messages = { const messages = {
clear: __( 'Clear all products', 'woocommerce' ), clear: __( 'Clear all products', 'woocommerce' ),
@ -90,11 +90,4 @@ ProductsControl.propTypes = {
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
}; };
ProductsControl.defaultProps = {
selected: [],
products: [],
isCompact: false,
isLoading: true,
};
export default withSearchedProducts( ProductsControl ); export default withSearchedProducts( ProductsControl );

View File

@ -0,0 +1,4 @@
Significance: minor
Type: dev
Removed defaultProps from React functional components since they will be deprecated for React 19