Skip to content

Commit

Permalink
fix(network) show physical managed network state (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
edlerd authored Aug 27, 2024
2 parents 1528ae3 + b6fd7be commit f81991d
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/pages/networks/NetworkDetailOverview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC, useEffect } from "react";
import { Link, useParams } from "react-router-dom";
import { Col, Row } from "@canonical/react-components";
import { Col, Notification, Row } from "@canonical/react-components";
import useEventListener from "@use-it/event-listener";
import { updateMaxHeight } from "util/updateMaxHeight";
import ItemName from "components/ItemName";
Expand All @@ -25,19 +25,21 @@ const NetworkDetailOverview: FC<Props> = ({ network }) => {
return <>Missing project</>;
}

const isPhysicalManagedNetwork =
network.type === "physical" && network.managed;

const { data: networkState, isLoading } = useQuery({
const {
data: networkState,
isLoading,
error: networkStateError,
isError: isNetworkStateError,
} = useQuery({
queryKey: [
queryKeys.projects,
project,
queryKeys.networks,
network.name,
queryKeys.state,
],
retry: 0, // physical managed networks can sometimes 404, show error right away and don't retry
queryFn: () => fetchNetworkState(network.name, project),
enabled: !isPhysicalManagedNetwork,
});

const updateContentHeight = () => {
Expand Down Expand Up @@ -96,12 +98,17 @@ const NetworkDetailOverview: FC<Props> = ({ network }) => {
</table>
</Col>
</Row>
{!isPhysicalManagedNetwork && (
<Row className="section">
<Col size={3}>
<h2 className="p-heading--5">Status</h2>
</Col>
<Col size={7}>
<Row className="section">
<Col size={3}>
<h2 className="p-heading--5">Status</h2>
</Col>
<Col size={7}>
{isNetworkStateError && (
<Notification severity="negative" borderless>
Could not load network state: {networkStateError.message}
</Notification>
)}
{!isNetworkStateError && (
<table>
<tbody>
<tr className="list-wrapper">
Expand All @@ -128,9 +135,9 @@ const NetworkDetailOverview: FC<Props> = ({ network }) => {
</tr>
</tbody>
</table>
</Col>
</Row>
)}
)}
</Col>
</Row>
<Row className="usage list-wrapper">
<Col size={3}>
<h2 className="p-heading--5">Usage ({usageCount})</h2>
Expand Down

0 comments on commit f81991d

Please sign in to comment.