environment panel (#724)

This commit is contained in:
Michael Quigley 2024-12-19 14:16:50 -05:00
parent b044c7ac5b
commit 5d863dd9f0
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
4 changed files with 44 additions and 10 deletions

View File

@ -94,7 +94,7 @@ const ApiConsole = ({ user, logout }: ApiConsoleProps) => {
break;
case "environment":
setSidePanel(<EnvironmentPanel environment={selectedNode} />);
setSidePanel(<EnvironmentPanel environment={selectedNode} user={user} />);
break;
case "share":

View File

@ -1,21 +1,54 @@
import {Node} from "@xyflow/react";
import {Grid2, Typography} from "@mui/material";
import EnvironmentIcon from "@mui/icons-material/Computer";
import {SparkLineChart} from "@mui/x-charts";
import {User} from "./model/user.ts";
import {useEffect, useState} from "react";
import {Configuration, Environment, MetadataApi} from "./api";
import PropertyTable from "./PropertyTable.tsx";
import SecretToggle from "./SecretToggle.tsx";
interface EnvironmentPanelProps {
environment: Node;
user: User;
}
const EnvironmentPanel = ({ environment }: EnvironmentPanelProps) => {
const EnvironmentPanel = ({ environment, user }: EnvironmentPanelProps) => {
const [detail, setDetail] = useState<Environment>(null);
const customProperties = {
zId: row => <SecretToggle secret={row.value} />,
createdAt: row => new Date(row.value).toLocaleString(),
updatedAt: row => new Date(row.value).toLocaleString()
}
useEffect(() => {
let cfg = new Configuration({
headers: {
"X-TOKEN": user.token
}
});
let metadata = new MetadataApi(cfg);
metadata.getEnvironmentDetail({envZId: environment.data!.envZId! as string})
.then(d => {
let env = d.environment!;
delete env.activity;
delete env.limited;
setDetail(env);
})
.catch(e => {
console.log("EnvironmentPanel", e);
})
}, [environment]);
return (
<Typography component="div">
<Grid2 container spacing={2}>
<Grid2 >
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<Grid2 display="flex"><EnvironmentIcon sx={{ fontSize: 30, mr: 0.5 }}/></Grid2>
<Grid2 display="flex" component="h3">{String(environment.data.label)}</Grid2>
</Grid2>
<Grid2 container sx={{ flexGrow: 1, p: 1 }} alignItems="center">
<Grid2 display="flex"><EnvironmentIcon sx={{ fontSize: 30, mr: 0.5 }}/></Grid2>
<Grid2 display="flex" component="h3">{String(environment.data.label)}</Grid2>
</Grid2>
<Grid2 container sx={{ flexGrow: 1 }}>
<Grid2 display="flex">
<PropertyTable object={detail} custom={customProperties} />
</Grid2>
</Grid2>
</Typography>

View File

@ -35,7 +35,7 @@ const PropertyTable = ({ object, custom }: PropertyTableProps) => {
<TableBody>
{data.map((row) => (
<TableRow key={row.id}>
<TableCell>{camelToWords(row.property)}</TableCell>
<TableCell sx={{ width: 100 }}>{camelToWords(row.property)}</TableCell>
<TableCell sx={{ width: 1000 }}>{value(row)}</TableCell>
</TableRow>
))}

View File

@ -8,6 +8,7 @@ export const objectToRows = (obj) => {
value: obj[key]
});
}
rows.sort((a, b) => a.property.localeCompare(b.property));
return rows;
};