Skip to content

Commit be2fa86

Browse files
working installations into table
1 parent dbf976a commit be2fa86

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/components/ControlPlane/FluxList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function FluxList() {
2222
data: gitReposData,
2323
error: repoErr,
2424
isLoading: repoIsLoading,
25-
} = useResource(FluxRequest); //404 if component not enabled
25+
} = useResource(FluxRequest); //404 if component not enabled`
2626
const {
2727
data: kustmizationData,
2828
error: kustomizationErr,

src/components/ControlPlane/Landscapers.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,46 @@ import useResource from '../../lib/api/useApiResource';
1111
import '@ui5/webcomponents-icons/dist/sys-enter-2';
1212
import '@ui5/webcomponents-icons/dist/sys-cancel-2';
1313
import { ListNamespaces } from '../../lib/api/types/k8s/listNamespaces';
14-
import { useEffect, useState } from 'react';
14+
import { useEffect, useState, useContext } from 'react';
1515
import { resourcesInterval } from '../../lib/shared/constants';
1616
import { InstalationsRequest } from '../../lib/api/types/landscaper/listInstallations';
17+
import { ApiConfigContext } from '../../components/Shared/k8s';
18+
import { fetchApiServerJson } from '../../lib/api/fetch';
1719

1820
export 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'),

src/lib/api/types/landscaper/listInstallations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ interface InstalationsListResponse {
1818
export const InstalationsRequest = (
1919
namespace: string,
2020
): Resource<InstalationsListResponse> => ({
21-
path: `/apis/landscaper.gardener.cloud/v1alpha1/namespaces/landscaper02/installations`,
21+
path: `/apis/landscaper.gardener.cloud/v1alpha1/namespaces/${namespace}/installations`,
2222
});

0 commit comments

Comments
 (0)