From b379fbb2a60d2bbb5dacb70a2b29199967982b8c Mon Sep 17 00:00:00 2001 From: pwillis77 Date: Thu, 8 Aug 2024 11:46:30 +0000 Subject: [PATCH] feat(NET-1445): network onvoarding improvements --- .../modals/new-host-modal/NewHostModal.tsx | 1 + src/pages/DashboardPage.tsx | 138 +++++++++++++++++- 2 files changed, 137 insertions(+), 2 deletions(-) diff --git a/src/components/modals/new-host-modal/NewHostModal.tsx b/src/components/modals/new-host-modal/NewHostModal.tsx index 71f34f5b..16ddf1bb 100644 --- a/src/components/modals/new-host-modal/NewHostModal.tsx +++ b/src/components/modals/new-host-modal/NewHostModal.tsx @@ -93,6 +93,7 @@ export default function NewHostModal({ const filteredEnrollmentKeys = useMemo( () => + enrollmentKeys && enrollmentKeys .filter((key) => isEnrollmentKeyValid(key)) .filter((key) => diff --git a/src/pages/DashboardPage.tsx b/src/pages/DashboardPage.tsx index 57b2b764..87814ae1 100644 --- a/src/pages/DashboardPage.tsx +++ b/src/pages/DashboardPage.tsx @@ -9,6 +9,8 @@ import { Layout, Row, Space, + Table, + TableColumnsType, Tooltip, Typography, notification, @@ -20,21 +22,23 @@ import { LaptopOutlined, PlusOutlined, QuestionCircleOutlined, + ReloadOutlined, SearchOutlined, } from '@ant-design/icons'; import UpgradeModal from '../components/modals/upgrade-modal/UpgradeModal'; import { PageProps } from '../models/Page'; import { AppRoutes } from '../routes'; -import { useNavigate } from 'react-router-dom'; +import { Link, useNavigate } from 'react-router-dom'; import AddNetworkModal from '@/components/modals/add-network-modal/AddNetworkModal'; import { useEffect, useMemo, useState } from 'react'; import { useStore } from '@/store/store'; -import { getAmuiUrl, getLicenseDashboardUrl, resolveAppRoute } from '@/utils/RouteUtils'; +import { getAmuiUrl, getLicenseDashboardUrl, getNetworkRoute, resolveAppRoute } from '@/utils/RouteUtils'; import NewHostModal from '@/components/modals/new-host-modal/NewHostModal'; import { isSaasBuild } from '@/services/BaseService'; import { useBranding } from '@/utils/Utils'; import QuickSetupModal from '@/components/modals/quick-setup-modal/QuickSetupModal'; import { UsecaseQuestionKey } from '@/constants/NetworkUseCases'; +import { Network } from '@/models/Network'; export type TourType = | 'relays' @@ -62,6 +66,7 @@ export default function DashboardPage(props: PageProps) { const [isNewHostModalOpen, setIsNewHostModalOpen] = useState(false); const [showUpgradeAlert, setShowUpgradeAlert] = useState(false); const [isQuickSetupModalOpen, setIsQuickSetupModalOpen] = useState(false); + const [searchText, setSearchText] = useState(''); const [notify, notifyCtx] = notification.useNotification(); const jumpToTourPage = (tourType: TourType, netId?: string) => { @@ -103,6 +108,79 @@ export default function DashboardPage(props: PageProps) { break; } }; + const filteredNetworks = useMemo( + () => + store.networks.filter((network) => { + return network.netid.toLowerCase().includes(searchText.toLowerCase()); + }), + [store.networks, searchText], + ); + + const tableColumns: TableColumnsType = [ + { + title: 'Name', + dataIndex: 'netid', + key: 'netid', + sorter: { + compare: (a, b) => a.netid.localeCompare(b.netid), + }, + defaultSortOrder: 'ascend', + render: (netId) => ( + {netId} + ), + }, + { + title: 'Address Range (IPv4)', + dataIndex: 'addressrange', + key: 'addressrange', + render: (addressRange) => ( +
ev.stopPropagation()}> + {addressRange} +
+ ), + }, + { + title: 'Address Range (IPv6)', + dataIndex: 'addressrange6', + key: 'addressrange6', + render: (addressRange6) => ( +
ev.stopPropagation()}> + {addressRange6} +
+ ), + }, + { + title: 'Hosts Count', + render(_, network) { + const nodeCount = store.nodes?.filter((node) => node.network === network.netid).length ?? 0; + return ( +
ev.stopPropagation()}> + {nodeCount} +
+ ); + }, + }, + { + title: 'Network Last Modified', + dataIndex: 'networklastmodified', + key: 'networklastmodified', + render: (date) => ( +
ev.stopPropagation()}> + {new Date(date * 1000).toLocaleString()} +
+ ), + }, + { + title: 'Hosts Last Modified', + dataIndex: 'nodeslastmodified', + key: 'nodeslastmodified', + render: (date) => ( +
ev.stopPropagation()}> + {new Date(date * 1000).toLocaleString()} +
+ ), + }, + ]; useEffect(() => { if (!isServerEE && !isSaasBuild && !store.serverStatus.status?.is_on_trial_license) { @@ -348,6 +426,62 @@ export default function DashboardPage(props: PageProps) { )} + {store.networks.length > 0 && ( + <> + + + + Networks + + + + + + + setSearchText(ev.target.value)} + prefix={} + /> + + + + + + + + + +
+ { + return { + onClick: () => { + navigate(getNetworkRoute(network)); + }, + }; + }} + /> + + + + + )}