From 449344f8a8dbb525455d850c67e8b712674759b2 Mon Sep 17 00:00:00 2001 From: Eduard Gert Date: Mon, 13 Jan 2025 14:56:05 +0100 Subject: [PATCH] Add resource group modal and adjust tables --- src/modules/networks/NetworkProvider.tsx | 36 ++++++ .../networks/resources/ResourceActionCell.tsx | 2 +- .../networks/resources/ResourceGroupCell.tsx | 4 +- .../networks/resources/ResourceGroupModal.tsx | 121 ++++++++++++++++++ .../networks/resources/ResourcesTable.tsx | 100 +++++++-------- .../routing-peers/NetworkRoutingPeerName.tsx | 12 +- .../NetworkRoutingPeersTable.tsx | 31 ++++- .../routing-peers/RoutingPeersActionCell.tsx | 2 +- 8 files changed, 240 insertions(+), 68 deletions(-) create mode 100644 src/modules/networks/resources/ResourceGroupModal.tsx diff --git a/src/modules/networks/NetworkProvider.tsx b/src/modules/networks/NetworkProvider.tsx index 3c529808..171f5a33 100644 --- a/src/modules/networks/NetworkProvider.tsx +++ b/src/modules/networks/NetworkProvider.tsx @@ -10,6 +10,7 @@ import { Network, NetworkResource, NetworkRouter } from "@/interfaces/Network"; import { AccessControlModalContent } from "@/modules/access-control/AccessControlModal"; import NetworkModal from "@/modules/networks/NetworkModal"; import NetworkResourceModal from "@/modules/networks/resources/NetworkResourceModal"; +import { ResourceGroupModal } from "@/modules/networks/resources/ResourceGroupModal"; import NetworkRoutingPeerModal from "@/modules/networks/routing-peers/NetworkRoutingPeerModal"; type Props = { @@ -23,6 +24,10 @@ const NetworksContext = React.createContext( openEditNetworkModal: (network: Network) => void; openCreateNetworkModal: () => void; openResourceModal: (network: Network, resource?: NetworkResource) => void; + openResourceGroupModal: ( + network: Network, + resource?: NetworkResource, + ) => void; openPolicyModal: (network?: Network, resource?: NetworkResource) => void; deleteNetwork: (network: Network) => void; deleteResource: (network: Network, resource: NetworkResource) => void; @@ -49,6 +54,7 @@ export const NetworkProvider = ({ children, network }: Props) => { const [routingPeerModal, setRoutingPeerModal] = useState(false); const [networkModal, setNetworkModal] = useState(false); const [resourceModal, setResourceModal] = useState(false); + const [resourceGroupModal, setResourceGroupModal] = useState(false); const [policyModal, setPolicyModal] = useState(false); const openAddRoutingPeerModal = ( @@ -76,6 +82,15 @@ export const NetworkProvider = ({ children, network }: Props) => { setResourceModal(true); }; + const openResourceGroupModal = ( + network: Network, + resource?: NetworkResource, + ) => { + setCurrentNetwork(network); + resource && setCurrentResource(resource); + setResourceGroupModal(true); + }; + const openPolicyModal = (network?: Network, resource?: NetworkResource) => { setPolicyDefaultSettings({ destinationGroups: resource?.groups, @@ -217,6 +232,7 @@ export const NetworkProvider = ({ children, network }: Props) => { openEditNetworkModal, openCreateNetworkModal, openResourceModal, + openResourceGroupModal, openPolicyModal, deleteNetwork, deleteResource, @@ -294,6 +310,26 @@ export const NetworkProvider = ({ children, network }: Props) => { setRoutingPeerModal(state); }} /> + + { + setCurrentResource(undefined); + setResourceGroupModal(state); + }} + onUpdated={() => { + setResourceGroupModal(false); + setCurrentResource(undefined); + mutate("/groups"); + if (network) { + mutate(`/networks/${network.id}/resources`); + mutate(`/networks/${network.id}`); + } + }} + /> + { const { deleteResource, network, openResourceModal } = useNetworksContext(); return ( -
+
{ - const { network, openResourceModal } = useNetworksContext(); + const { network, openResourceGroupModal } = useNetworksContext(); return ( + + + +
+ + + ); +}; diff --git a/src/modules/networks/resources/ResourcesTable.tsx b/src/modules/networks/resources/ResourcesTable.tsx index 547a6187..478845ad 100644 --- a/src/modules/networks/resources/ResourcesTable.tsx +++ b/src/modules/networks/resources/ResourcesTable.tsx @@ -91,62 +91,56 @@ export default function ResourcesTable({ resources, isLoading, headingTarget, -}: Props) { +}: Readonly) { const [sorting, setSorting] = useState([]); const { openResourceModal, network } = useNetworksContext(); return ( - <> - } - /> - } - columnVisibility={{}} - paginationPaddingClassName={"px-0 pt-8"} - rightSide={() => ( - <> - - - )} - > - {(table) => ( - <> - - - )} - - + } + /> + } + columnVisibility={{}} + paginationPaddingClassName={"px-0 pt-8"} + rightSide={() => ( + + )} + > + {(table) => ( + + )} + ); } diff --git a/src/modules/networks/routing-peers/NetworkRoutingPeerName.tsx b/src/modules/networks/routing-peers/NetworkRoutingPeerName.tsx index 03511e2c..092f5064 100644 --- a/src/modules/networks/routing-peers/NetworkRoutingPeerName.tsx +++ b/src/modules/networks/routing-peers/NetworkRoutingPeerName.tsx @@ -44,13 +44,11 @@ export const NetworkRoutingPeerName = ({ router }: Props) => { if (routingPeerGroup) { return ( - <> -
- - - {routingPeerGroup.peers_count} Peer(s) -
- +
+ + + {routingPeerGroup.peers_count} Peer(s) +
); } }; diff --git a/src/modules/networks/routing-peers/NetworkRoutingPeersTable.tsx b/src/modules/networks/routing-peers/NetworkRoutingPeersTable.tsx index 5c138b76..9e801ad9 100644 --- a/src/modules/networks/routing-peers/NetworkRoutingPeersTable.tsx +++ b/src/modules/networks/routing-peers/NetworkRoutingPeersTable.tsx @@ -1,12 +1,16 @@ +import Button from "@components/Button"; import Card from "@components/Card"; import { DataTable } from "@components/table/DataTable"; import DataTableHeader from "@components/table/DataTableHeader"; +import { DataTableRowsPerPage } from "@components/table/DataTableRowsPerPage"; import NoResults from "@components/ui/NoResults"; +import { IconCirclePlus } from "@tabler/icons-react"; import { ColumnDef, SortingState } from "@tanstack/react-table"; import * as React from "react"; import { useState } from "react"; import PeerIcon from "@/assets/icons/PeerIcon"; import { NetworkRouter } from "@/interfaces/Network"; +import { useNetworksContext } from "@/modules/networks/NetworkProvider"; import { NetworkRoutingPeerName } from "@/modules/networks/routing-peers/NetworkRoutingPeerName"; import { RoutingPeersActionCell } from "@/modules/networks/routing-peers/RoutingPeersActionCell"; import { RoutingPeersEnabledCell } from "@/modules/networks/routing-peers/RoutingPeersEnabledCell"; @@ -70,6 +74,8 @@ export default function NetworkRoutingPeersTable({ isLoading, headingTarget, }: Readonly) { + const { openAddRoutingPeerModal, network } = useNetworksContext(); + const [sorting, setSorting] = useState([ { id: "metric", @@ -80,7 +86,7 @@ export default function NetworkRoutingPeersTable({ return ( + rightSide={() => ( + + )} + > + {(table) => ( + + )} + ); } diff --git a/src/modules/networks/routing-peers/RoutingPeersActionCell.tsx b/src/modules/networks/routing-peers/RoutingPeersActionCell.tsx index cb53fea7..3c64415c 100644 --- a/src/modules/networks/routing-peers/RoutingPeersActionCell.tsx +++ b/src/modules/networks/routing-peers/RoutingPeersActionCell.tsx @@ -18,7 +18,7 @@ export const RoutingPeersActionCell = ({ router }: Props) => { useNetworksContext(); return ( -
+