github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/ConfigurationPanels/ConfigurationOptions.tsx (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 React, { Fragment, useCallback, useEffect, useState } from "react"; 18 import { 19 Box, 20 Grid, 21 HelpBox, 22 PageLayout, 23 ScreenTitle, 24 SettingsIcon, 25 Tabs, 26 } from "mds"; 27 28 import { configurationElements } from "../utils"; 29 import { 30 Navigate, 31 Route, 32 Routes, 33 useLocation, 34 useNavigate, 35 } from "react-router-dom"; 36 37 import ConfigurationForm from "./ConfigurationForm"; 38 import { IAM_PAGES } from "../../../../common/SecureComponent/permissions"; 39 import PageHeaderWrapper from "../../Common/PageHeaderWrapper/PageHeaderWrapper"; 40 import ExportConfigButton from "./ExportConfigButton"; 41 import ImportConfigButton from "./ImportConfigButton"; 42 43 import HelpMenu from "../../HelpMenu"; 44 import { setErrorSnackMessage, setHelpName } from "../../../../systemSlice"; 45 import { useAppDispatch } from "../../../../store"; 46 import { api } from "../../../../api"; 47 import { IElement } from "../types"; 48 import { errorToHandler } from "../../../../api/errors"; 49 50 const getRoutePath = (path: string) => { 51 return `${IAM_PAGES.SETTINGS}/${path}`; 52 }; 53 54 // region is not part of config subsystem list. 55 const NON_SUB_SYS_CONFIG_ITEMS = ["region"]; 56 const IGNORED_CONFIG_SUB_SYS = ["cache"]; // cache config is not supported. 57 58 const ConfigurationOptions = () => { 59 const { pathname = "" } = useLocation(); 60 const dispatch = useAppDispatch(); 61 const navigate = useNavigate(); 62 63 const [configSubSysList, setConfigSubSysList] = useState<string[]>([]); 64 const fetchConfigSubSysList = useCallback(async () => { 65 api.configs 66 .listConfig() // get a list of available config subsystems. 67 .then((res) => { 68 if (res && res?.data && res?.data?.configurations) { 69 const confSubSysList = (res?.data?.configurations || []).reduce( 70 (acc: string[], { key = "" }) => { 71 if (!IGNORED_CONFIG_SUB_SYS.includes(key)) { 72 acc.push(key); 73 } 74 return acc; 75 }, 76 [], 77 ); 78 79 setConfigSubSysList(confSubSysList); 80 } 81 }) 82 .catch((err) => { 83 dispatch(setErrorSnackMessage(errorToHandler(err))); 84 }); 85 }, [dispatch]); 86 87 useEffect(() => { 88 fetchConfigSubSysList(); 89 dispatch(setHelpName("settings_Region")); 90 // eslint-disable-next-line react-hooks/exhaustive-deps 91 }, []); 92 93 const availableConfigSubSys = configurationElements.filter( 94 ({ configuration_id }: IElement) => { 95 return ( 96 NON_SUB_SYS_CONFIG_ITEMS.includes(configuration_id) || 97 configSubSysList.includes(configuration_id) || 98 !configSubSysList.length 99 ); 100 }, 101 ); 102 103 return ( 104 <Fragment> 105 <PageHeaderWrapper label={"Configuration"} actions={<HelpMenu />} /> 106 <PageLayout> 107 <Grid item xs={12} id={"settings-container"}> 108 <ScreenTitle 109 icon={<SettingsIcon />} 110 title={"MinIO Configuration:"} 111 actions={ 112 <Box 113 sx={{ 114 display: "flex", 115 gap: 10, 116 }} 117 > 118 <ImportConfigButton /> 119 <ExportConfigButton /> 120 </Box> 121 } 122 sx={{ marginBottom: 15 }} 123 /> 124 <Tabs 125 currentTabOrPath={pathname} 126 onTabClick={(path) => { 127 navigate(path); 128 }} 129 useRouteTabs 130 options={availableConfigSubSys.map((element) => { 131 const { configuration_id, configuration_label, icon } = element; 132 return { 133 tabConfig: { 134 id: `settings-tab-${configuration_label}`, 135 label: configuration_label, 136 value: configuration_id, 137 icon: icon, 138 to: getRoutePath(configuration_id), 139 }, 140 }; 141 })} 142 routes={ 143 <Routes> 144 {availableConfigSubSys.map((element) => ( 145 <Route 146 key={`configItem-${element.configuration_label}`} 147 path={`${element.configuration_id}`} 148 element={<ConfigurationForm />} 149 /> 150 ))} 151 <Route 152 path={"/"} 153 element={<Navigate to={`${IAM_PAGES.SETTINGS}/region`} />} 154 /> 155 </Routes> 156 } 157 /> 158 </Grid> 159 <Grid item xs={12} sx={{ paddingTop: "15px" }}> 160 <HelpBox 161 title={"Learn more about Configurations"} 162 iconComponent={<SettingsIcon />} 163 help={ 164 <Fragment> 165 MinIO supports a variety of configurations ranging from 166 encryption, compression, region, notifications, etc. 167 <br /> 168 <br /> 169 You can learn more at our{" "} 170 <a 171 href="https://min.io/docs/minio/linux/reference/minio-mc-admin/mc-admin-config.html?ref=con#id4" 172 target="_blank" 173 rel="noopener" 174 > 175 documentation 176 </a> 177 . 178 </Fragment> 179 } 180 /> 181 </Grid> 182 </PageLayout> 183 </Fragment> 184 ); 185 }; 186 187 export default ConfigurationOptions;