github.com/minio/console@v1.4.1/web-app/src/utils/sortFunctions.ts (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2021 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  import { Policy, User } from "api/consoleApi";
    18  
    19  interface policyDetailsInterface {
    20    policy: string;
    21  }
    22  
    23  export const usersSort = (a: User, b: User) => {
    24    if (a.accessKey && b.accessKey) {
    25      if (a.accessKey > b.accessKey) {
    26        return 1;
    27      }
    28      if (a.accessKey < b.accessKey) {
    29        return -1;
    30      }
    31    }
    32    // a must be equal to b
    33    return 0;
    34  };
    35  
    36  export const policySort = (a: Policy, b: Policy) => {
    37    if (a.name! > b.name!) {
    38      return 1;
    39    }
    40    if (a.name! < b.name!) {
    41      return -1;
    42    }
    43    // a must be equal to b
    44    return 0;
    45  };
    46  
    47  export const stringSort = (a: string, b: string) => {
    48    if (a > b) {
    49      return 1;
    50    }
    51    if (a < b) {
    52      return -1;
    53    }
    54    // a must be equal to b
    55    return 0;
    56  };
    57  
    58  export const policyDetailsSort = (
    59    a: policyDetailsInterface,
    60    b: policyDetailsInterface,
    61  ) => {
    62    if (a.policy > b.policy) {
    63      return 1;
    64    }
    65    if (a.policy < b.policy) {
    66      return -1;
    67    }
    68    // a must be equal to b
    69    return 0;
    70  };