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

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2023 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 React, { Fragment, useEffect } from "react";
    18  import {
    19    IAM_PAGES,
    20    IAM_PERMISSIONS,
    21    IAM_ROLES,
    22    IAM_SCOPES,
    23  } from "../../../common/SecureComponent/permissions";
    24  import { SecureComponent } from "../../../common/SecureComponent";
    25  import TooltipWrapper from "../Common/TooltipWrapper/TooltipWrapper";
    26  import { BackLink, Button, SettingsIcon, Grid } from "mds";
    27  import AutoColorIcon from "../Common/Components/AutoColorIcon";
    28  import { useSelector } from "react-redux";
    29  import { selFeatures } from "../consoleSlice";
    30  import hasPermission from "../../../common/SecureComponent/accessControl";
    31  import { useNavigate } from "react-router-dom";
    32  import SearchBox from "../Common/SearchBox";
    33  import { setSearchVersions } from "./objectBrowserSlice";
    34  import { AppState, useAppDispatch } from "../../../store";
    35  import FilterObjectsSB from "./FilterObjectsSB";
    36  import PageHeaderWrapper from "../Common/PageHeaderWrapper/PageHeaderWrapper";
    37  import ObjectManagerButton from "../Common/ObjectManager/ObjectManagerButton";
    38  import HelpMenu from "../HelpMenu";
    39  import { setHelpName } from "../../../systemSlice";
    40  
    41  interface IOBHeader {
    42    bucketName: string;
    43  }
    44  
    45  const OBHeader = ({ bucketName }: IOBHeader) => {
    46    const dispatch = useAppDispatch();
    47    const features = useSelector(selFeatures);
    48  
    49    const versionsMode = useSelector(
    50      (state: AppState) => state.objectBrowser.versionsMode,
    51    );
    52    const versionedFile = useSelector(
    53      (state: AppState) => state.objectBrowser.versionedFile,
    54    );
    55    const searchVersions = useSelector(
    56      (state: AppState) => state.objectBrowser.searchVersions,
    57    );
    58  
    59    const obOnly = !!features?.includes("object-browser-only");
    60  
    61    const navigate = useNavigate();
    62  
    63    const configureBucketAllowed = hasPermission(bucketName, [
    64      IAM_SCOPES.S3_GET_BUCKET_POLICY,
    65      IAM_SCOPES.S3_PUT_BUCKET_POLICY,
    66      IAM_SCOPES.S3_GET_BUCKET_VERSIONING,
    67      IAM_SCOPES.S3_PUT_BUCKET_VERSIONING,
    68      IAM_SCOPES.S3_GET_BUCKET_ENCRYPTION_CONFIGURATION,
    69      IAM_SCOPES.S3_PUT_BUCKET_ENCRYPTION_CONFIGURATION,
    70      IAM_SCOPES.S3_DELETE_BUCKET,
    71      IAM_SCOPES.S3_GET_BUCKET_NOTIFICATIONS,
    72      IAM_SCOPES.S3_PUT_BUCKET_NOTIFICATIONS,
    73      IAM_SCOPES.S3_GET_REPLICATION_CONFIGURATION,
    74      IAM_SCOPES.S3_PUT_REPLICATION_CONFIGURATION,
    75      IAM_SCOPES.S3_GET_LIFECYCLE_CONFIGURATION,
    76      IAM_SCOPES.S3_PUT_LIFECYCLE_CONFIGURATION,
    77      IAM_SCOPES.ADMIN_GET_BUCKET_QUOTA,
    78      IAM_SCOPES.ADMIN_SET_BUCKET_QUOTA,
    79      IAM_SCOPES.S3_PUT_BUCKET_TAGGING,
    80      IAM_SCOPES.S3_GET_BUCKET_TAGGING,
    81      IAM_SCOPES.S3_LIST_BUCKET_VERSIONS,
    82      IAM_SCOPES.S3_GET_BUCKET_POLICY_STATUS,
    83      IAM_SCOPES.S3_DELETE_BUCKET_POLICY,
    84      IAM_SCOPES.S3_GET_ACTIONS,
    85      IAM_SCOPES.S3_PUT_ACTIONS,
    86    ]);
    87  
    88    const searchBar = (
    89      <Fragment>
    90        {!versionsMode ? (
    91          <SecureComponent
    92            scopes={[IAM_SCOPES.S3_LIST_BUCKET, IAM_SCOPES.S3_ALL_LIST_BUCKET]}
    93            resource={bucketName}
    94            errorProps={{ disabled: true }}
    95          >
    96            <FilterObjectsSB />
    97          </SecureComponent>
    98        ) : (
    99          <Fragment>
   100            <SearchBox
   101              placeholder={`Start typing to filter versions of ${versionedFile}`}
   102              onChange={(value) => {
   103                dispatch(setSearchVersions(value));
   104              }}
   105              value={searchVersions}
   106            />
   107          </Fragment>
   108        )}
   109      </Fragment>
   110    );
   111  
   112    useEffect(() => {
   113      dispatch(setHelpName("object_browser"));
   114      // eslint-disable-next-line react-hooks/exhaustive-deps
   115    }, []);
   116  
   117    return (
   118      <Fragment>
   119        {!obOnly ? (
   120          <PageHeaderWrapper
   121            label={
   122              <BackLink
   123                label={"Object Browser"}
   124                onClick={() => {
   125                  navigate(IAM_PAGES.OBJECT_BROWSER_VIEW);
   126                }}
   127              />
   128            }
   129            actions={
   130              <Fragment>
   131                <SecureComponent
   132                  scopes={IAM_PERMISSIONS[IAM_ROLES.BUCKET_ADMIN]}
   133                  resource={bucketName}
   134                  errorProps={{ disabled: true }}
   135                >
   136                  <TooltipWrapper
   137                    tooltip={
   138                      configureBucketAllowed
   139                        ? "Configure Bucket"
   140                        : "You do not have the required permissions to configure this bucket. Please contact your MinIO administrator to request " +
   141                          IAM_ROLES.BUCKET_ADMIN +
   142                          " permisions."
   143                    }
   144                  >
   145                    <Button
   146                      id={"configure-bucket-main"}
   147                      color="primary"
   148                      aria-label="Configure Bucket"
   149                      onClick={() => navigate(`/buckets/${bucketName}/admin`)}
   150                      icon={
   151                        <SettingsIcon
   152                          style={{ width: 20, height: 20, marginTop: -3 }}
   153                        />
   154                      }
   155                      style={{
   156                        padding: "0 10px",
   157                      }}
   158                    />
   159                  </TooltipWrapper>
   160                </SecureComponent>
   161                <HelpMenu />
   162              </Fragment>
   163            }
   164            middleComponent={searchBar}
   165          />
   166        ) : (
   167          <Grid
   168            container
   169            sx={{
   170              padding: "20px 32px 0",
   171            }}
   172          >
   173            <Grid>
   174              <AutoColorIcon marginRight={30} marginTop={10} />
   175            </Grid>
   176            <Grid
   177              item
   178              xs
   179              sx={{
   180                display: "flex",
   181                gap: 10,
   182              }}
   183            >
   184              {searchBar}
   185              <ObjectManagerButton />
   186            </Grid>
   187          </Grid>
   188        )}
   189      </Fragment>
   190    );
   191  };
   192  
   193  export default OBHeader;