github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/statements/diagnostics/diagnosticsUtils.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  
    11  import { isUndefined } from "lodash";
    12  
    13  import { cockroach } from "src/js/protos";
    14  import IStatementDiagnosticsReport = cockroach.server.serverpb.IStatementDiagnosticsReport;
    15  import {DiagnosticStatuses} from "src/views/statements/diagnostics/diagnosticStatuses";
    16  
    17  export function getDiagnosticsStatus(diagnosticsRequest: IStatementDiagnosticsReport): DiagnosticStatuses {
    18    if (diagnosticsRequest.completed) {
    19      return "READY";
    20    }
    21  
    22    return "WAITING FOR QUERY";
    23  }
    24  
    25  export function sortByRequestedAtField(a: IStatementDiagnosticsReport, b: IStatementDiagnosticsReport) {
    26    const activatedOnA = a.requested_at?.seconds?.toNumber();
    27    const activatedOnB = b.requested_at?.seconds?.toNumber();
    28    if (isUndefined(activatedOnA) && isUndefined(activatedOnB)) { return 0; }
    29    if (activatedOnA < activatedOnB) { return -1; }
    30    if (activatedOnA > activatedOnB) { return 1; }
    31    return 0;
    32  }
    33  
    34  export function sortByCompletedField(a: IStatementDiagnosticsReport, b: IStatementDiagnosticsReport) {
    35    const completedA = a.completed ? 1 : -1;
    36    const completedB = b.completed ? 1 : -1;
    37    if (completedA < completedB) { return -1; }
    38    if (completedA > completedB) { return 1; }
    39    return 0;
    40  }
    41  
    42  export function sortByStatementFingerprintField(a: IStatementDiagnosticsReport, b: IStatementDiagnosticsReport) {
    43    const statementFingerprintA = a.statement_fingerprint;
    44    const statementFingerprintB = b.statement_fingerprint;
    45    if (isUndefined(statementFingerprintA) && isUndefined(statementFingerprintB)) { return 0; }
    46    if (statementFingerprintA < statementFingerprintB) { return -1; }
    47    if (statementFingerprintA > statementFingerprintB) { return 1; }
    48    return 0;
    49  }