@@ -51,20 +51,27 @@ interface HueConfig {
5151 conf_dir : string ;
5252}
5353
54+ interface VisualSection {
55+ header : string ;
56+ content : Array < AdminConfigValue > ;
57+ }
58+
5459const Configuration : React . FC = ( ) : JSX . Element => {
5560 const { t } = i18nReact . useTranslation ( ) ;
5661 const [ hueConfig , setHueConfig ] = useState < HueConfig > ( ) ;
5762 const [ loading , setLoading ] = useState ( true ) ;
5863 const [ error , setError ] = useState < string > ( ) ;
59- const [ selectedApp , setSelectedApp ] = useState < string > ( 'desktop' ) ;
64+ const [ selectedSection , setSelectedSection ] = useState < string > ( 'desktop' ) ;
6065 const [ filter , setFilter ] = useState < string > ( '' ) ;
6166
67+ const ALL_SECTIONS_OPTION = t ( 'ALL' ) ;
68+
6269 useEffect ( ( ) => {
6370 ApiHelper . fetchHueConfigAsync ( )
6471 . then ( data => {
6572 setHueConfig ( data ) ;
6673 if ( data . apps . find ( app => app . name === 'desktop' ) ) {
67- setSelectedApp ( 'desktop' ) ;
74+ setSelectedSection ( 'desktop' ) ;
6875 }
6976 } )
7077 . catch ( error => {
@@ -98,50 +105,80 @@ const Configuration: React.FC = (): JSX.Element => {
98105 return undefined ;
99106 } ;
100107
101- const selectedConfig = useMemo ( ( ) => {
102- const filterSelectedApp = hueConfig ?. config ?. find ( config => config . key === selectedApp ) ;
108+ const visualSections = useMemo ( ( ) => {
109+ const showAllSections = selectedSection === ALL_SECTIONS_OPTION ;
110+ const selectedFullConfigs = ! hueConfig ?. config
111+ ? [ ]
112+ : showAllSections
113+ ? hueConfig . config
114+ : hueConfig . config . filter ( config => config . key === selectedSection ) ;
115+
116+ return selectedFullConfigs
117+ . map ( selectedSection => ( {
118+ header : selectedSection . key ,
119+ content : selectedSection . values
120+ . map ( config => filterConfig ( config , filter . toLowerCase ( ) ) )
121+ . filter ( Boolean ) as Config [ ]
122+ } ) )
123+ . filter ( headerContentObj => ! ! headerContentObj . content ) as Array < VisualSection > ;
124+ } , [ hueConfig , filter , selectedSection ] ) ;
125+
126+ const renderVisualSection = ( visualSection : VisualSection ) => {
127+ const showingMultipleSections = selectedSection === ALL_SECTIONS_OPTION ;
128+ const content = visualSection . content ;
129+ return content . length > 0 ? (
130+ < >
131+ { showingMultipleSections && (
132+ < h4 className = "config__section-header" > { visualSection . header } </ h4 >
133+ ) }
134+ { content . map ( ( record , index ) => (
135+ < div key = { index } className = "config__main-item" >
136+ < ConfigurationKey record = { record } />
137+ < ConfigurationValue record = { record } />
138+ </ div >
139+ ) ) }
140+ </ >
141+ ) : (
142+ ! showingMultipleSections && < i > { t ( 'Empty configuration section' ) } </ i >
143+ ) ;
144+ } ;
103145
104- return filterSelectedApp ?. values
105- . map ( config => filterConfig ( config , filter . toLowerCase ( ) ) )
106- . filter ( Boolean ) as Config [ ] ;
107- } , [ hueConfig , filter , selectedApp ] ) ;
146+ const optionsIncludingAll = [
147+ ALL_SECTIONS_OPTION ,
148+ ... ( hueConfig ?. apps . map ( app => app . name ) || [ ] )
149+ ] ;
108150
109151 return (
110152 < div className = "config-component" >
111153 < Spin spinning = { loading } >
112154 { error && (
113155 < Alert
114156 message = { `Error: ${ error } ` }
115- description = " Error in displaying the Configuration!"
157+ description = { t ( ' Error in displaying the Configuration!' ) }
116158 type = "error"
117159 />
118160 ) }
119161
120162 { ! error && (
121163 < >
122- < div className = "config__section-header" > Sections</ div >
164+ < div className = "config__section-dropdown-label" > { t ( ' Sections' ) } </ div >
123165 < AdminHeader
124- options = { hueConfig ?. apps . map ( app => app . name ) || [ ] }
125- selectedValue = { selectedApp }
126- onSelectChange = { setSelectedApp }
166+ options = { optionsIncludingAll }
167+ selectedValue = { selectedSection }
168+ onSelectChange = { setSelectedSection }
127169 filterValue = { filter }
128170 onFilterChange = { setFilter }
129- placeholder = { `Filter in ${ selectedApp } ...` }
171+ placeholder = {
172+ selectedSection === ALL_SECTIONS_OPTION
173+ ? t ( 'Filter...' )
174+ : `${ t ( 'Filter in' ) } ${ selectedSection } ...`
175+ }
130176 configAddress = { hueConfig ?. conf_dir }
131177 />
132- { selectedApp &&
133- selectedConfig &&
134- ( selectedConfig . length > 0 ? (
135- < >
136- { selectedConfig . map ( ( record , index ) => (
137- < div key = { index } className = "config__main-item" >
138- < ConfigurationKey record = { record } />
139- < ConfigurationValue record = { record } />
140- </ div >
141- ) ) }
142- </ >
143- ) : (
144- < i > { t ( 'Empty configuration section' ) } </ i >
178+ { selectedSection &&
179+ visualSections ?. length &&
180+ visualSections . map ( visualSection => (
181+ < div key = { visualSection . header } > { renderVisualSection ( visualSection ) } </ div >
145182 ) ) }
146183 </ >
147184 ) }
0 commit comments