diff --git a/js/src/components/app-table-card/index.js b/js/src/components/app-table-card/index.js index 7d5274c7a0..e9314a7206 100644 --- a/js/src/components/app-table-card/index.js +++ b/js/src/components/app-table-card/index.js @@ -7,22 +7,43 @@ import { TableCard } from '@woocommerce/components'; * Internal dependencies */ import recordColumnToggleEvent from './recordColumnToggleEvent'; +import { recordTableSortEvent } from '../../utils/recordEvent'; import './index.scss'; const AppTableCard = ( props ) => { - const { trackEventReportId, onColumnsChange = () => {}, ...rest } = props; + const { trackEventReportId, ...rest } = props; + /** + * Returns a function that records a track event before executing an original handler. + * + * @param {String} handlerName The name of the event handler. + * @param {Function} recordEvent The function to record the event. + * + * @returns {decorateHandlerWithTrackEvent~decoratedHandler} Decorated handler. + */ + const decorateHandlerWithTrackEvent = ( handlerName, recordEvent ) => { + /** + * Records track event with specified `trackEventReportId` and any args given, + * then calls original handler if any. + */ + return function decoratedHandler( ...args ) { + if ( trackEventReportId ) { + recordEvent( trackEventReportId, ...args ); + } - const handleColumnsChange = ( shown, toggled ) => { - if ( trackEventReportId ) { - recordColumnToggleEvent( trackEventReportId, shown, toggled ); + // Call the original handler if given. + const handler = props.handlerName; + if( handler ){ + handler( ...args ); + } } - - onColumnsChange( shown, toggled ); - }; + } return (