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 (
- +
); }; diff --git a/js/src/reports/compare-programs-table-card.js b/js/src/reports/compare-programs-table-card.js index a46b6839b1..062637aa91 100644 --- a/js/src/reports/compare-programs-table-card.js +++ b/js/src/reports/compare-programs-table-card.js @@ -151,7 +151,7 @@ const CompareProgramsTableCard = () => { return ( diff --git a/js/src/utils/recordEvent.js b/js/src/utils/recordEvent.js index dd4900a48f..e7497cd1b6 100644 --- a/js/src/utils/recordEvent.js +++ b/js/src/utils/recordEvent.js @@ -11,6 +11,10 @@ export const recordTableHeaderToggleEvent = ( report, column, status ) => { } ); }; +export const recordTableSortEvent = ( report, column, direction ) => { + recordEvent( 'gla_table_sort', { report, column, direction } ); +}; + export const recordSetupMCEvent = ( target, trigger = 'click' ) => { recordEvent( 'gla_setup_mc', { target,