14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- import React , { Fragment , useEffect } from "react" ;
17
+ import React , { Fragment , useCallback , useEffect , useState } from "react" ;
18
18
import { Theme } from "@mui/material/styles" ;
19
19
import createStyles from "@mui/styles/createStyles" ;
20
20
import withStyles from "@mui/styles/withStyles" ;
@@ -37,8 +37,11 @@ import ExportConfigButton from "./ExportConfigButton";
37
37
import ImportConfigButton from "./ImportConfigButton" ;
38
38
import { Box } from "@mui/material" ;
39
39
import HelpMenu from "../../HelpMenu" ;
40
- import { setHelpName } from "../../../../systemSlice" ;
40
+ import { setErrorSnackMessage , setHelpName } from "../../../../systemSlice" ;
41
41
import { useAppDispatch } from "../../../../store" ;
42
+ import { api } from "../../../../api" ;
43
+ import { IElement } from "../types" ;
44
+ import { errorToHandler } from "../../../../api/errors" ;
42
45
43
46
interface IConfigurationOptions {
44
47
classes : any ;
@@ -64,17 +67,56 @@ const getRoutePath = (path: string) => {
64
67
return `${ IAM_PAGES . SETTINGS } /${ path } ` ;
65
68
} ;
66
69
70
+ // region is not part of config subsystem list.
71
+ const NON_SUB_SYS_CONFIG_ITEMS = [ "region" ] ;
72
+ const IGNORED_CONFIG_SUB_SYS = [ "cache" ] ; // cache config is not supported.
73
+
67
74
const ConfigurationOptions = ( { classes } : IConfigurationOptions ) => {
68
75
const { pathname = "" } = useLocation ( ) ;
76
+ const dispatch = useAppDispatch ( ) ;
77
+
78
+ const [ configSubSysList , setConfigSubSysList ] = useState < string [ ] > ( [ ] ) ;
79
+ const fetchConfigSubSysList = useCallback ( async ( ) => {
80
+ api . configs
81
+ . listConfig ( ) // get a list of available config subsystems.
82
+ . then ( ( res ) => {
83
+ if ( res && res ?. data && res ?. data ?. configurations ) {
84
+ const confSubSysList = ( res ?. data ?. configurations || [ ] ) . reduce (
85
+ ( acc : string [ ] , { key = "" } ) => {
86
+ if ( ! IGNORED_CONFIG_SUB_SYS . includes ( key ) ) {
87
+ acc . push ( key ) ;
88
+ }
89
+ return acc ;
90
+ } ,
91
+ [ ] ,
92
+ ) ;
93
+
94
+ setConfigSubSysList ( confSubSysList ) ;
95
+ }
96
+ } )
97
+ . catch ( ( err ) => {
98
+ dispatch ( setErrorSnackMessage ( errorToHandler ( err ) ) ) ;
99
+ } ) ;
100
+ } , [ dispatch ] ) ;
69
101
70
102
let selConfigTab = pathname . substring ( pathname . lastIndexOf ( "/" ) + 1 ) ;
71
103
selConfigTab = selConfigTab === "settings" ? "region" : selConfigTab ;
72
- const dispatch = useAppDispatch ( ) ;
73
104
useEffect ( ( ) => {
105
+ fetchConfigSubSysList ( ) ;
74
106
dispatch ( setHelpName ( "settings_Region" ) ) ;
75
107
// eslint-disable-next-line react-hooks/exhaustive-deps
76
108
} , [ ] ) ;
77
109
110
+ const availableConfigSubSys = configurationElements . filter (
111
+ ( { configuration_id } : IElement ) => {
112
+ return (
113
+ NON_SUB_SYS_CONFIG_ITEMS . includes ( configuration_id ) ||
114
+ configSubSysList . includes ( configuration_id ) ||
115
+ ! configSubSysList . length
116
+ ) ;
117
+ } ,
118
+ ) ;
119
+
78
120
return (
79
121
< Fragment >
80
122
< PageHeaderWrapper label = { "Settings" } actions = { < HelpMenu /> } />
@@ -104,7 +146,7 @@ const ConfigurationOptions = ({ classes }: IConfigurationOptions) => {
104
146
isRouteTabs
105
147
routes = {
106
148
< Routes >
107
- { configurationElements . map ( ( element ) => (
149
+ { availableConfigSubSys . map ( ( element ) => (
108
150
< Route
109
151
key = { `configItem-${ element . configuration_label } ` }
110
152
path = { `${ element . configuration_id } ` }
@@ -118,7 +160,7 @@ const ConfigurationOptions = ({ classes }: IConfigurationOptions) => {
118
160
</ Routes >
119
161
}
120
162
>
121
- { configurationElements . map ( ( element ) => {
163
+ { availableConfigSubSys . map ( ( element ) => {
122
164
const { configuration_id, configuration_label, icon } = element ;
123
165
return {
124
166
tabConfig : {
0 commit comments