diff --git a/app/Transformers/Api/Application/NodeTransformer.php b/app/Transformers/Api/Application/NodeTransformer.php index 093fcc9621..703a385051 100644 --- a/app/Transformers/Api/Application/NodeTransformer.php +++ b/app/Transformers/Api/Application/NodeTransformer.php @@ -14,7 +14,7 @@ class NodeTransformer extends Transformer /** * List of resources that can be included. */ - protected array $availableIncludes = ['allocations', 'location', 'servers']; + protected array $availableIncludes = ['allocations', 'location', 'servers', 'database_host']; /** * Return the resource name for the JSONAPI output. @@ -45,6 +45,18 @@ public function transform(Node $model): array return $response; } + /** + * Return the database host associated with this node. + */ + public function includeDatabaseHost(Node $node): Item|NullResource + { + if (!$this->authorize(AdminAcl::RESOURCE_DATABASE_HOSTS)) { + return $this->null(); + } + + return $this->item($node->databaseHost, new DatabaseHostTransformer()); + } + /** * Return the allocations associated with this node. */ diff --git a/resources/scripts/components/admin/nodes/NodeStatus.tsx b/resources/scripts/components/admin/nodes/NodeStatus.tsx new file mode 100644 index 0000000000..9b0bf93f62 --- /dev/null +++ b/resources/scripts/components/admin/nodes/NodeStatus.tsx @@ -0,0 +1,29 @@ +import getNodeInformation, { NodeInformation } from '@/api/admin/nodes/getNodeInformation'; +import Tooltip from '@/components/elements/tooltip/Tooltip'; +import { faHeartPulse } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { useEffect, useState } from 'react'; +import tw from 'twin.macro'; + +export default function NodeStatus({ node }: { node: number }) { + const [info, setInfo] = useState(null); + useEffect(() => { + const getNodeStatus = async () => { + getNodeInformation(node) + .then(info => setInfo(info)) + .catch(error => { + console.error(error); + }); + }; + getNodeStatus(); + }, []); + + return ( + + + + ); +} diff --git a/resources/scripts/components/admin/nodes/NodesContainer.tsx b/resources/scripts/components/admin/nodes/NodesContainer.tsx index 2ad97ad7fd..ea375f1c46 100644 --- a/resources/scripts/components/admin/nodes/NodesContainer.tsx +++ b/resources/scripts/components/admin/nodes/NodesContainer.tsx @@ -23,6 +23,8 @@ import AdminTable, { import Button from '@/components/elements/Button'; import CopyOnClick from '@/components/elements/CopyOnClick'; import { bytesToString, mbToBytes } from '@/lib/formatters'; +import NodeStatus from '@/components/admin/nodes/NodeStatus'; +import { Size } from '@/components/elements/button/types'; const RowCheckbox = ({ id }: { id: number }) => { const isChecked = AdminContext.useStoreState(state => state.nodes.selectedNodes.indexOf(id) >= 0); @@ -224,23 +226,7 @@ const NodesContainer = () => { {/* TODO: Change color based off of online/offline status */} - - - + ))}