Skip to content

Commit

Permalink
feat(network) fix review notes for network overhaul
Browse files Browse the repository at this point in the history
 - use new view for managed networks, remove old network overview
 - topology should be calculated for managed networks
 - search placeholder: "Search for key"
 - search over the description and field name
 - hide topology on yaml config
 - on creation: asterisk for name and uplink/parent
 - on creation: disable submit until a parent is selected
 - left align topology

Signed-off-by: David Edler <[email protected]>
  • Loading branch information
edlerd committed Jan 6, 2025
1 parent e8a3413 commit c5b65d6
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 310 deletions.
2 changes: 1 addition & 1 deletion src/components/ConfigurationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export const getConfigurationRow = ({
</div>
),
override: renderOverride(),
name: label as string,
name: `${label as string}-${name ?? ""}-${metadata.value}-${metadata.configField?.shortdesc}`,
});
};

Expand Down
3 changes: 2 additions & 1 deletion src/pages/networks/CreateNetwork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ const CreateNetwork: FC = () => {
disabled={
!formik.isValid ||
!formik.values.name ||
(formik.values.networkType === "ovn" && !formik.values.network)
(formik.values.networkType === "ovn" && !formik.values.network) ||
(formik.values.networkType === "physical" && !formik.values.parent)
}
onClick={() => void formik.submitForm()}
>
Expand Down
11 changes: 1 addition & 10 deletions src/pages/networks/EditNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC, useEffect, useState } from "react";
import { Button, Notification, useNotify } from "@canonical/react-components";
import { Button, useNotify } from "@canonical/react-components";
import { useFormik } from "formik";
import * as Yup from "yup";
import { useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -45,15 +45,6 @@ const EditNetwork: FC<Props> = ({ network, project }) => {
const controllerState = useState<AbortController | null>(null);
const [version, setVersion] = useState(0);

if (!network?.managed) {
return (
<Notification severity="negative">
Configuration is only available for managed networks. This network is
not managed.
</Notification>
);
}

const NetworkSchema = Yup.object().shape({
name: Yup.string()
.test(
Expand Down
14 changes: 2 additions & 12 deletions src/pages/networks/NetworkDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import EditNetwork from "pages/networks/EditNetwork";
import NetworkDetailHeader from "pages/networks/NetworkDetailHeader";
import Loader from "components/Loader";
import { Row } from "@canonical/react-components";
import NetworkDetailOverview from "pages/networks/NetworkDetailOverview";
import CustomLayout from "components/CustomLayout";
import TabLinks from "components/TabLinks";
import NetworkForwards from "pages/networks/NetworkForwards";
Expand Down Expand Up @@ -40,12 +39,8 @@ const NetworkDetail: FC = () => {
const isManagedNetwork = network?.managed;

const getTabs = () => {
if (!isManagedNetwork) {
return ["Overview"];
}

const type = network?.type ?? "";
if (type === "physical") {
if (type === "physical" || !isManagedNetwork) {
return ["Configuration"];
}

Expand All @@ -66,12 +61,7 @@ const NetworkDetail: FC = () => {
tabUrl={`/ui/project/${project}/network/${name}`}
/>
<NotificationRow />
{!activeTab && !isManagedNetwork && (
<div role="tabpanel" aria-labelledby="overview">
{network && <NetworkDetailOverview network={network} />}
</div>
)}
{!activeTab && isManagedNetwork && (
{!activeTab && (
<div role="tabpanel" aria-labelledby="configuration">
{network && <EditNetwork network={network} project={project} />}
</div>
Expand Down
200 changes: 0 additions & 200 deletions src/pages/networks/NetworkDetailOverview.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion src/pages/networks/NetworkList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import HelpLink from "components/HelpLink";
import { useDocs } from "context/useDocs";
import NetworkForwardCount from "pages/networks/NetworkForwardCount";
import { useSmallScreen } from "context/useSmallScreen";
import { capitalizeFirstLetter } from "util/helpers";

const NetworkList: FC = () => {
const docBaseLink = useDocs();
Expand Down Expand Up @@ -70,7 +71,7 @@ const NetworkList: FC = () => {
"aria-label": "Name",
},
{
content: network.type,
content: capitalizeFirstLetter(network.type),
role: "rowheader",
"aria-label": "Type",
},
Expand Down
5 changes: 4 additions & 1 deletion src/pages/networks/NetworkTopology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import classNames from "classnames";
import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "util/queryKeys";
import { fetchNetworks } from "api/networks";
import classnames from "classnames";

interface Props {
formik: FormikProps<NetworkFormValues>;
Expand Down Expand Up @@ -78,7 +79,9 @@ const NetworkTopology: FC<Props> = ({ formik, project }) => {
return (
<div
key={networkUrl}
className="downstream-item downstream-network"
className={classnames("downstream-item", {
"has-descendents": instances.length > 0,
})}
>
<ResourceLink
type="network"
Expand Down
81 changes: 81 additions & 0 deletions src/pages/networks/forms/NetworkAddresses.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { FC } from "react";
import { FormikProps } from "formik/dist/types";
import { NetworkFormValues } from "pages/networks/forms/NetworkForm";
import { useQuery } from "@tanstack/react-query";
import { queryKeys } from "util/queryKeys";
import { fetchNetworkState } from "api/networks";
import { MainTable } from "@canonical/react-components";

interface Props {
formik: FormikProps<NetworkFormValues>;
project: string;
}

const NetworkAddresses: FC<Props> = ({ formik, project }) => {
const { data: networkState } = useQuery({
queryKey: [
queryKeys.projects,
project,
queryKeys.networks,
formik.values.bareNetwork?.name,
queryKeys.state,
],
retry: 0, // physical managed networks can sometimes 404, show error right away and don't retry
queryFn: () =>
fetchNetworkState(formik.values.bareNetwork?.name ?? "", project),
enabled: !formik.values.isCreating,
});

return (
<>
<h2 className="p-heading--4">Addresses</h2>
{(networkState?.addresses ?? []).length > 0 ? (
<MainTable
sortable
headers={[
{ content: "IP", sortKey: "ip" },
{ content: "Netmask", sortKey: "netmask" },
{ content: "Scope", sortKey: "scope" },
{ content: "Family", sortKey: "family" },
]}
rows={networkState?.addresses.map((item) => {
return {
columns: [
{
content: item.address,
role: "cell",
"aria-label": "Address",
},
{
content: item.netmask,
role: "cell",
"aria-label": "Netmask",
},
{
content: item.scope,
role: "cell",
"aria-label": "Scope",
},
{
content: item.family,
role: "cell",
"aria-label": "family",
},
],
sortData: {
ip: item.address,
netmask: item.netmask,
scope: item.scope,
family: item.family,
},
};
})}
/>
) : (
"None"
)}
</>
);
};

export default NetworkAddresses;
Loading

0 comments on commit c5b65d6

Please sign in to comment.