mirror of
https://github.com/netbirdio/dashboard.git
synced 2026-01-26 01:21:04 +00:00
Add better search for network-routes by group name (#336)
This commit is contained in:
@@ -12,6 +12,7 @@ export interface Route {
|
||||
peer_groups?: string[];
|
||||
routesGroups?: string[];
|
||||
groupedRoutes?: GroupedRoute[];
|
||||
group_names?: string[];
|
||||
}
|
||||
|
||||
export interface GroupedRoute {
|
||||
@@ -22,5 +23,6 @@ export interface GroupedRoute {
|
||||
high_availability_count: number;
|
||||
is_using_route_groups: boolean;
|
||||
routes?: Route[];
|
||||
group_names?: string[];
|
||||
description?: string;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,12 @@ export const GroupedRouteTableColumns: ColumnDef<GroupedRoute>[] = [
|
||||
accessorKey: "enabled",
|
||||
sortingFn: "basic",
|
||||
},
|
||||
{
|
||||
id: "group_names",
|
||||
accessorFn: (row) => {
|
||||
return row.group_names?.map((name) => name).join(", ");
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "network",
|
||||
header: ({ column }) => {
|
||||
@@ -121,10 +127,11 @@ export default function NetworkRoutesTable({
|
||||
setSorting={setSorting}
|
||||
columns={GroupedRouteTableColumns}
|
||||
data={groupedRoutes}
|
||||
searchPlaceholder={"Search by network, range or name..."}
|
||||
searchPlaceholder={"Search by network, range, name or groups..."}
|
||||
columnVisibility={{
|
||||
enabled: false,
|
||||
description: false,
|
||||
group_names: false,
|
||||
}}
|
||||
renderExpandedRow={(row) => {
|
||||
const data = cloneDeep(row);
|
||||
|
||||
@@ -41,6 +41,19 @@ export default function useGroupedRoutes({ routes }: Props) {
|
||||
const countEnabledPeers = peerRoutes.filter((r) => r.enabled).length;
|
||||
const allPeers = countPeersOfGroup + countEnabledPeers;
|
||||
|
||||
// Get the group names for better search results
|
||||
const peerGroupNames =
|
||||
groupPeerRoute?.peer_groups?.map((id) => {
|
||||
return groups?.find((g) => g.id == id)?.name || "";
|
||||
}) || [];
|
||||
|
||||
const routeGroups = routes.map((r) => r.groups).flat();
|
||||
const distributionGroupNames = routeGroups.map((group) => {
|
||||
return groups?.find((g) => g.id == group)?.name || "";
|
||||
});
|
||||
|
||||
const allGroupNames = [...peerGroupNames, ...distributionGroupNames];
|
||||
|
||||
results.push({
|
||||
id,
|
||||
enabled: routes.find((r) => r.enabled) != undefined,
|
||||
@@ -50,6 +63,7 @@ export default function useGroupedRoutes({ routes }: Props) {
|
||||
is_using_route_groups: !!groupPeerRoute,
|
||||
description: groupPeerRoute ? groupPeerRoute?.description : undefined,
|
||||
routes: routes,
|
||||
group_names: allGroupNames,
|
||||
});
|
||||
});
|
||||
return results;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { DataTable } from "@components/table/DataTable";
|
||||
import DataTableHeader from "@components/table/DataTableHeader";
|
||||
import { ColumnDef, SortingState } from "@tanstack/react-table";
|
||||
import React, { useState } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import { useGroups } from "@/contexts/GroupsProvider";
|
||||
import { GroupedRoute, Route } from "@/interfaces/Route";
|
||||
import RouteActionCell from "@/modules/routes/RouteActionCell";
|
||||
import RouteActiveCell from "@/modules/routes/RouteActiveCell";
|
||||
@@ -39,7 +40,6 @@ export const RouteTableColumns: ColumnDef<Route>[] = [
|
||||
),
|
||||
cell: ({ row }) => <RouteActiveCell route={row.original} />,
|
||||
},
|
||||
|
||||
{
|
||||
id: "groups",
|
||||
accessorFn: (r) => r.groups?.length,
|
||||
@@ -50,6 +50,12 @@ export const RouteTableColumns: ColumnDef<Route>[] = [
|
||||
},
|
||||
cell: ({ row }) => <RouteDistributionGroupsCell route={row.original} />,
|
||||
},
|
||||
{
|
||||
id: "group_names",
|
||||
accessorFn: (row) => {
|
||||
return row.group_names?.map((name) => name).join(", ");
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "",
|
||||
@@ -58,6 +64,8 @@ export const RouteTableColumns: ColumnDef<Route>[] = [
|
||||
];
|
||||
|
||||
export default function RouteTable({ row }: Props) {
|
||||
const { groups } = useGroups();
|
||||
|
||||
// Default sorting state of the table
|
||||
const [sorting, setSorting] = useState<SortingState>([
|
||||
{
|
||||
@@ -74,6 +82,26 @@ export default function RouteTable({ row }: Props) {
|
||||
const [currentRow, setCurrentRow] = useState<Route>();
|
||||
const [currentCellClicked, setCurrentCellClicked] = useState("");
|
||||
|
||||
const data = useMemo(() => {
|
||||
if (!row.routes) return [];
|
||||
// Get the group names for better search results
|
||||
return row.routes.map((route) => {
|
||||
const distributionGroupNames =
|
||||
route.groups?.map((id) => {
|
||||
return groups?.find((g) => g.id === id)?.name || "";
|
||||
}) || [];
|
||||
const peerGroupNames =
|
||||
route.peer_groups?.map((id) => {
|
||||
return groups?.find((g) => g.id === id)?.name || "";
|
||||
}) || [];
|
||||
const allGroupNames = [...distributionGroupNames, ...peerGroupNames];
|
||||
return {
|
||||
...route,
|
||||
group_names: allGroupNames,
|
||||
} as Route;
|
||||
});
|
||||
}, [row.routes, groups]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{editModal && currentRow && (
|
||||
@@ -92,6 +120,9 @@ export default function RouteTable({ row }: Props) {
|
||||
text={"Network Routes"}
|
||||
manualPagination={true}
|
||||
sorting={sorting}
|
||||
columnVisibility={{
|
||||
group_names: false,
|
||||
}}
|
||||
onRowClick={(row, cell) => {
|
||||
setCurrentRow(row.original);
|
||||
setEditModal(true);
|
||||
@@ -99,7 +130,7 @@ export default function RouteTable({ row }: Props) {
|
||||
}}
|
||||
setSorting={setSorting}
|
||||
columns={RouteTableColumns}
|
||||
data={row.routes}
|
||||
data={data}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user