github.com/minio/console@v1.4.1/web-app/src/screens/Console/kbar-actions.tsx (about)

     1  //  This file is part of MinIO Console Server
     2  //  Copyright (c) 2022 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 { Action } from "kbar/lib/types";
    18  import { BucketsIcon } from "mds";
    19  import { validRoutes } from "./valid-routes";
    20  import { IAM_PAGES } from "../../common/SecureComponent/permissions";
    21  import { Bucket } from "../../api/consoleApi";
    22  
    23  export const routesAsKbarActions = (
    24    buckets: Bucket[],
    25    navigate: (url: string) => void,
    26    features?: string[],
    27  ) => {
    28    const initialActions: Action[] = [];
    29    const allowedMenuItems = validRoutes(features);
    30    for (const i of allowedMenuItems) {
    31      if (i.children && i.children.length > 0) {
    32        for (const childI of i.children) {
    33          const a: Action = {
    34            id: `${childI.id}`,
    35            name: childI.name,
    36            section: i.name,
    37            perform: () => navigate(`${childI.path}`),
    38            icon: childI.icon,
    39          };
    40          initialActions.push(a);
    41        }
    42      } else {
    43        const a: Action = {
    44          id: `${i.id}`,
    45          name: i.name,
    46          section: "Navigation",
    47          perform: () => navigate(`${i.path}`),
    48          icon: i.icon,
    49        };
    50        initialActions.push(a);
    51      }
    52    }
    53  
    54    // Add additional actions
    55    const a: Action = {
    56      id: `create-bucket`,
    57      name: "Create Bucket",
    58      section: "Buckets",
    59      perform: () => navigate(IAM_PAGES.ADD_BUCKETS),
    60      icon: <BucketsIcon />,
    61    };
    62    initialActions.push(a);
    63  
    64    if (buckets) {
    65      buckets.map((buck) => [
    66        initialActions.push({
    67          id: buck.name,
    68          name: buck.name,
    69          section: "List of Buckets",
    70          perform: () => {
    71            navigate(`/browser/${buck.name}`);
    72          },
    73          icon: <BucketsIcon />,
    74        }),
    75      ]);
    76    }
    77  
    78    return initialActions;
    79  };