fixes with edit forms

This commit is contained in:
biersoeckli
2024-12-12 10:10:08 +00:00
parent 55a8b38459
commit 78783b288d
8 changed files with 18 additions and 38 deletions
@@ -52,10 +52,9 @@ export default function DefaultPortEditDialog({ children, appPort, appId }: { ch
const values = form.watch();
useEffect(() => {
if (!isOpen) {
form.reset();
}
}, [isOpen]);
form.reset(appPort);
}, [appPort]);
return (
<>
@@ -58,10 +58,8 @@ export default function DialogEditDialog({ children, domain, appId }: { children
const values = form.watch();
useEffect(() => {
if (!isOpen) {
form.reset();
}
}, [isOpen]);
form.reset(domain);
}, [domain]);
return (
<>
@@ -54,12 +54,7 @@ export default function MonitoringTab({
return <>
<Card>
<CardHeader>
<CardTitle>App Monitoring</CardTitle>
<CardDescription>This is an overview about the resources the app is consuming in comparison to the resources of all nodes.
</CardDescription>
</CardHeader>
<CardContent>
<CardContent className="pb-0">
{!selectedPod ? <FullLoadingSpinner /> :
<Table>
<TableHeader>
@@ -77,10 +77,8 @@ export default function DialogEditDialog({ children, volume, app }: { children:
}, [state]);
useEffect(() => {
if (!isOpen) {
form.reset();
}
}, [isOpen]);
form.reset(volume);
}, [volume]);
return (
<>
@@ -13,21 +13,20 @@ import { AppVolume } from "@prisma/client";
import React from "react";
import { KubeObjectNameUtils } from "@/server/utils/kube-object-name.utils";
type AppVolumeWithCapacity = (AppVolume & { capacity?: string });
export default function StorageList({ app }: {
app: AppExtendedModel
}) {
const [volumesWithStorage, setVolumesWithStorage] = React.useState<(AppVolume&{capacity?:string})[]>(app.appVolumes);
const [volumesWithStorage, setVolumesWithStorage] = React.useState<AppVolumeWithCapacity[]>(app.appVolumes);
const loadAndMapStorageData = async () => {
//Funktion aufrufen, die die Daten aus dem Longhorn holt
const response = (await getPvcUsage(app.id, app.projectId)); // hier wäre der call
const response = (await getPvcUsage(app.id, app.projectId));
if (response.status === 'success' && response.data) {
(response.data);
const mappedVolumeData = [...volumesWithStorage];
const mappedVolumeData = [...app.appVolumes] as AppVolumeWithCapacity[];
for (let item of mappedVolumeData) {
const volume = response.data.find(x => x.pvcName === KubeObjectNameUtils.toPvcName(item.id));
if (volume) {
@@ -38,15 +37,10 @@ export default function StorageList({ app }: {
} else {
console.error(response);
}
}
React.useEffect(() => {
setVolumesWithStorage(app.appVolumes);
loadAndMapStorageData();
}, [app.appVolumes]);
const { openDialog } = useConfirmDialog();
+4 -9
View File
@@ -4,7 +4,7 @@ class LonghornApiAdapter {
async getLonghornVolume(pvcName: String) { //Soll PVC Name und Used Size zurückgeben
let longhornApiUrl = process.env.NODE_ENV === 'production' ? 'http://longhorn-frontend.longhorn-system.svc.cluster.local/v1/volumes' : 'http://localhost:4000/v1/volumes';
try {
// Request senden
const response = await fetch(`${longhornApiUrl}/${pvcName}`, {
cache: 'no-cache',
@@ -27,11 +27,6 @@ class LonghornApiAdapter {
const usedStorage = data.controllers?.[0]?.actualSize;
return (usedStorage / (1024 * 1024)); // Rückgabe mit Erfolgsfall
} catch (error) {
console.error('Fehler beim Abrufen der Daten:', error);
return -1; // Rückgabe mit Fehlerfall
}
}
@@ -74,8 +69,8 @@ class LonghornApiAdapter {
// Iterate over each disk and sum up the values
Object.values(data.disks).forEach(disk => {
totalStorageMaximum += disk.storageMaximum;
totalStorageAvailable += disk.storageAvailable;
totalStorageMaximum += disk.storageMaximum;
totalStorageAvailable += disk.storageAvailable;
});
return {
@@ -83,7 +78,7 @@ class LonghornApiAdapter {
totalStorageAvailable
};
}
}
}
const longhornApiAdapter = new LonghornApiAdapter();
export default longhornApiAdapter;
+1 -1
View File
@@ -28,7 +28,7 @@ class ProjectService {
}
async getAllProjects() {
return await unstable_cache(async () => await dataAccess.client.project.findMany({
return await unstable_cache(() => dataAccess.client.project.findMany({
include: {
apps: true
},
+1
View File
@@ -59,6 +59,7 @@ class PvcService {
try {
// Rufe Speicherverbrauchsdaten von getLonghornVolume ab
const usage = await longhornApiAdapter.getLonghornVolume(volumeName);
console.log(usage)
// Füge die Daten in das Array ein
pvcUsageData.push({ pvcName, usage });
} catch (error) {