1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
17- import React , { Fragment , useEffect } from "react" ;
17+ import React , { Fragment , useCallback , useEffect , useState } from "react" ;
1818import { Theme } from "@mui/material/styles" ;
1919import createStyles from "@mui/styles/createStyles" ;
2020import withStyles from "@mui/styles/withStyles" ;
@@ -39,6 +39,8 @@ import { Box } from "@mui/material";
3939import HelpMenu from "../../HelpMenu" ;
4040import { setHelpName } from "../../../../systemSlice" ;
4141import { useAppDispatch } from "../../../../store" ;
42+ import { api } from "../../../../api" ;
43+ import { IElement } from "../types" ;
4244
4345interface IConfigurationOptions {
4446 classes : any ;
@@ -64,17 +66,56 @@ const getRoutePath = (path: string) => {
6466 return `${ IAM_PAGES . SETTINGS } /${ path } ` ;
6567} ;
6668
69+ //region would not be part of config subsystem list.
70+ const NON_SUB_SYS_CONFIG_ITEMS = [ "region" ] ;
71+ const IGNORED_CONFIG_SUB_SYS = [ "cache" ] ; //cahe config is un supported.
72+
6773const ConfigurationOptions = ( { classes } : IConfigurationOptions ) => {
6874 const { pathname = "" } = useLocation ( ) ;
6975
76+ const [ configSubSysList , setConfigSubSysList ] = useState < string [ ] > ( [ ] ) ;
77+ const fetchConfigSubSysList = useCallback ( async ( ) => {
78+ api . configs
79+ . listConfig ( ) //get all available config subsystems.
80+ . then ( ( res ) => {
81+ if ( res && res ?. data && res ?. data ?. configurations ) {
82+ const confSubSysList = ( res ?. data ?. configurations || [ ] ) . reduce (
83+ ( acc : string [ ] , { key = "" } ) => {
84+ if ( ! IGNORED_CONFIG_SUB_SYS . includes ( key ) ) {
85+ acc . push ( key ) ;
86+ }
87+ return acc ;
88+ } ,
89+ [ ]
90+ ) ;
91+
92+ setConfigSubSysList ( confSubSysList ) ;
93+ }
94+ } )
95+ . catch ( ( ) => {
96+ console . log ( "Error in retrieving config subsystem list." ) ;
97+ } ) ;
98+ } , [ ] ) ;
99+
70100 let selConfigTab = pathname . substring ( pathname . lastIndexOf ( "/" ) + 1 ) ;
71101 selConfigTab = selConfigTab === "settings" ? "region" : selConfigTab ;
72102 const dispatch = useAppDispatch ( ) ;
73103 useEffect ( ( ) => {
104+ fetchConfigSubSysList ( ) ;
74105 dispatch ( setHelpName ( "settings_Region" ) ) ;
75106 // eslint-disable-next-line react-hooks/exhaustive-deps
76107 } , [ ] ) ;
77108
109+ const availableConfigSubSys = configurationElements . filter (
110+ ( { configuration_id } : IElement ) => {
111+ return (
112+ NON_SUB_SYS_CONFIG_ITEMS . includes ( configuration_id ) ||
113+ configSubSysList . includes ( configuration_id ) ||
114+ ! configSubSysList . length
115+ ) ;
116+ }
117+ ) ;
118+
78119 return (
79120 < Fragment >
80121 < PageHeaderWrapper label = { "Settings" } actions = { < HelpMenu /> } />
@@ -104,7 +145,7 @@ const ConfigurationOptions = ({ classes }: IConfigurationOptions) => {
104145 isRouteTabs
105146 routes = {
106147 < Routes >
107- { configurationElements . map ( ( element ) => (
148+ { availableConfigSubSys . map ( ( element ) => (
108149 < Route
109150 key = { `configItem-${ element . configuration_label } ` }
110151 path = { `${ element . configuration_id } ` }
@@ -118,7 +159,7 @@ const ConfigurationOptions = ({ classes }: IConfigurationOptions) => {
118159 </ Routes >
119160 }
120161 >
121- { configurationElements . map ( ( element ) => {
162+ { availableConfigSubSys . map ( ( element ) => {
122163 const { configuration_id, configuration_label, icon } = element ;
123164 return {
124165 tabConfig : {
0 commit comments