Send tracks event when table sorting is changed.

This commit is contained in:
Jeff Stieler 2019-07-09 14:38:53 -06:00
parent f7c48e6738
commit a13487265c
2 changed files with 22 additions and 2 deletions

View File

@ -38,6 +38,7 @@ class ReportTable extends Component {
this.onColumnsChange = this.onColumnsChange.bind( this ); this.onColumnsChange = this.onColumnsChange.bind( this );
this.onPageChange = this.onPageChange.bind( this ); this.onPageChange = this.onPageChange.bind( this );
this.onSort = this.onSort.bind( this );
this.scrollPointRef = createRef(); this.scrollPointRef = createRef();
} }
@ -76,6 +77,19 @@ class ReportTable extends Component {
} }
} }
onSort( key, direction ) {
onQueryChange( 'sort' )( key, direction );
const { endpoint } = this.props;
const eventProps = {
report: endpoint,
column: key,
direction,
};
recordEvent( 'analytics_table_sort', eventProps );
}
filterShownHeaders( headers, hiddenKeys ) { filterShownHeaders( headers, hiddenKeys ) {
if ( ! hiddenKeys || ! hiddenKeys.length ) { if ( ! hiddenKeys || ! hiddenKeys.length ) {
return headers; return headers;
@ -160,6 +174,7 @@ class ReportTable extends Component {
isLoading={ isLoading } isLoading={ isLoading }
onQueryChange={ onQueryChange } onQueryChange={ onQueryChange }
onColumnsChange={ this.onColumnsChange } onColumnsChange={ this.onColumnsChange }
onSort={ this.onSort }
onPageChange={ this.onPageChange } onPageChange={ this.onPageChange }
rows={ rows } rows={ rows }
rowsPerPage={ parseInt( query.per_page ) || QUERY_DEFAULTS.pageSize } rowsPerPage={ parseInt( query.per_page ) || QUERY_DEFAULTS.pageSize }

View File

@ -266,6 +266,7 @@ class TableCard extends Component {
isLoading, isLoading,
onClickDownload, onClickDownload,
onQueryChange, onQueryChange,
onSort,
query, query,
rowHeader, rowHeader,
rowsPerPage, rowsPerPage,
@ -376,7 +377,6 @@ class TableCard extends Component {
rowHeader={ rowHeader } rowHeader={ rowHeader }
caption={ title } caption={ title }
query={ query } query={ query }
onSort={ onQueryChange( 'sort' ) }
/> />
</Fragment> </Fragment>
) : ( ) : (
@ -386,7 +386,7 @@ class TableCard extends Component {
rowHeader={ rowHeader } rowHeader={ rowHeader }
caption={ title } caption={ title }
query={ query } query={ query }
onSort={ onQueryChange( 'sort' ) } onSort={ onSort || onQueryChange( 'sort' ) }
/> />
) } ) }
@ -453,6 +453,10 @@ TableCard.propTypes = {
* A function which returns a callback function which is called upon the user changing the visiblity of columns. * A function which returns a callback function which is called upon the user changing the visiblity of columns.
*/ */
onColumnsChange: PropTypes.func, onColumnsChange: PropTypes.func,
/**
* A function which is called upon the user changing the sorting of the table.
*/
onSort: PropTypes.func,
/** /**
* Whether the table must be downloadable. If true, the download button will appear. * Whether the table must be downloadable. If true, the download button will appear.
*/ */
@ -522,6 +526,7 @@ TableCard.defaultProps = {
isLoading: false, isLoading: false,
onQueryChange: noop, onQueryChange: noop,
onColumnsChange: noop, onColumnsChange: noop,
onSort: undefined,
query: {}, query: {},
rowHeader: 0, rowHeader: 0,
rows: [], rows: [],