github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/util/analytics/trackTableSort.ts (about)

     1  // Copyright 2020 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  import { analytics } from "src/redux/analytics";
    11  import { SortableColumn, SortSetting } from "src/views/shared/components/sortabletable";
    12  
    13  export const track = (fn: Function) => (
    14    name?: String,
    15    col?: SortableColumn,
    16    sortSetting?: SortSetting,
    17  ) => {
    18    const tableName = name || "";
    19    const columnName = col && col.title || "";
    20    const sortDirection = sortSetting && (sortSetting.ascending) ? "asc" : "desc";
    21  
    22    fn({
    23      event: "Table Sort",
    24      properties: {
    25        tableName,
    26        columnName,
    27        sortDirection,
    28      },
    29    });
    30  };
    31  
    32  export default function trackTableSort(
    33    name?: String,
    34    col?: SortableColumn,
    35    sortSetting?: SortSetting,
    36  ) {
    37    const boundTrack = analytics.track.bind(analytics);
    38    track(boundTrack)(name, col, sortSetting);
    39  }