github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/TiersConfiguration/RegionSelectWrapper.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 React, { useState } from "react";
    18  import { Autocomplete, InputBox, SelectorType } from "mds";
    19  
    20  import s3Regions from "./s3-regions";
    21  import gcsRegions from "./gcs-regions";
    22  import azRegions from "./azure-regions";
    23  
    24  const getRegions = (type: string): any => {
    25    let regions: SelectorType[] = [];
    26  
    27    if (type === "s3") {
    28      regions = s3Regions;
    29    }
    30    if (type === "gcs") {
    31      regions = gcsRegions;
    32    }
    33    if (type === "azure") {
    34      regions = azRegions;
    35    }
    36  
    37    return regions.map((item) => ({
    38      value: item.value,
    39      label: `${item.label} - ${item.value}`,
    40    }));
    41  };
    42  
    43  interface RegionSelectBoxProps {
    44    label: string;
    45    onChange: (value: string) => void;
    46    value?: string | boolean;
    47    id: string;
    48    disabled?: boolean;
    49    type: "minio" | "s3" | "gcs" | "azure";
    50    tooltip?: string;
    51    required?: boolean;
    52    placeholder?: string;
    53  }
    54  
    55  const RegionSelectWrapper = ({
    56    label,
    57    onChange,
    58    type,
    59    tooltip = "",
    60    required = false,
    61    disabled,
    62    placeholder,
    63  }: RegionSelectBoxProps) => {
    64    const regionList = getRegions(type);
    65    const [value, setValue] = useState<string>("");
    66  
    67    if (type === "minio") {
    68      return (
    69        <InputBox
    70          label={label}
    71          disabled={disabled}
    72          required={required}
    73          tooltip={tooltip}
    74          value={value}
    75          placeholder={placeholder}
    76          id={"region-list"}
    77          onChange={(e) => {
    78            setValue(e.target.value);
    79            onChange(e.target.value);
    80          }}
    81        />
    82      );
    83    }
    84  
    85    return (
    86      <Autocomplete
    87        label={label}
    88        disabled={disabled}
    89        required={required}
    90        tooltip={tooltip}
    91        options={regionList}
    92        value={value}
    93        placeholder={placeholder}
    94        id={"region-list"}
    95        onChange={(newValue) => {
    96          setValue(newValue);
    97          onChange(newValue);
    98        }}
    99      />
   100    );
   101  };
   102  
   103  export default RegionSelectWrapper;