@@ -11,47 +11,46 @@ import useResource from '../../lib/api/useApiResource';
1111import '@ui5/webcomponents-icons/dist/sys-enter-2' ;
1212import '@ui5/webcomponents-icons/dist/sys-cancel-2' ;
1313import { ListNamespaces } from '../../lib/api/types/k8s/listNamespaces' ;
14- import { useEffect , useState } from 'react' ;
14+ import { useEffect , useState , useContext } from 'react' ;
1515import { resourcesInterval } from '../../lib/shared/constants' ;
1616import { InstalationsRequest } from '../../lib/api/types/landscaper/listInstallations' ;
17+ import { ApiConfigContext } from '../../components/Shared/k8s' ;
18+ import { fetchApiServerJson } from '../../lib/api/fetch' ;
1719
1820export function Landscapers ( ) {
1921 const { t } = useTranslation ( ) ;
22+ const apiConfig = useContext ( ApiConfigContext ) ;
2023
21- // Namespaces z API
22- const { data : namespaces , error : namespacesError } = useResource (
23- ListNamespaces ,
24- {
25- refreshInterval : resourcesInterval ,
26- } ,
27- ) ;
24+ const { data : namespaces } = useResource ( ListNamespaces , {
25+ refreshInterval : resourcesInterval ,
26+ } ) ;
2827
2928 const [ selectedNamespaces , setSelectedNamespaces ] = useState < string [ ] > ( [ ] ) ;
3029 const [ installations , setInstallations ] = useState < any [ ] > ( [ ] ) ;
3130 const [ loading , setLoading ] = useState ( false ) ;
3231
33- // Handler wyboru namespace’ów
3432 const handleSelectionChange = ( e : CustomEvent ) => {
3533 const selectedItems = Array . from ( e . detail . items || [ ] ) ;
3634 const selectedValues = selectedItems . map ( ( item : any ) => item . text ) ;
3735 setSelectedNamespaces ( selectedValues ) ;
3836 } ;
3937
40- // Fetch installations, gdy zmienią się namespace’y
4138 useEffect ( ( ) => {
4239 const fetchInstallations = async ( ) => {
4340 if ( selectedNamespaces . length === 0 ) {
4441 setInstallations ( [ ] ) ;
4542 return ;
4643 }
44+
4745 setLoading ( true ) ;
46+
4847 try {
4948 const paths = selectedNamespaces
5049 . map ( ( ns ) => InstalationsRequest ( ns ) . path )
5150 . filter ( ( p ) : p is string => p !== null && p !== undefined ) ;
5251
5352 const allResponses = await Promise . all (
54- paths . map ( ( path ) => fetch ( path ) . then ( ( res ) => res . json ( ) ) ) ,
53+ paths . map ( ( path ) => fetchApiServerJson ( path , apiConfig ) ) ,
5554 ) ;
5655
5756 const allItems = allResponses . flatMap ( ( res ) => res . items || [ ] ) ;
@@ -65,9 +64,8 @@ export function Landscapers() {
6564 } ;
6665
6766 fetchInstallations ( ) ;
68- } , [ selectedNamespaces ] ) ;
67+ } , [ selectedNamespaces , apiConfig ] ) ;
6968
70- // Definicja kolumn tabeli
7169 const columns : AnalyticalTableColumnDefinition [ ] = [
7270 {
7371 Header : t ( 'Namespace' ) ,
0 commit comments