Skip to content

Commit c8e3b50

Browse files
Display serial number on peer information and on peers table (#444)
* display serial number on peer information and on peers table * add serial on peers list (included in OS information to minimize informations) * permit a lookup via serial number * add serial on peer information * Update os icon to match existing one and hide serial if it does not exist --------- Co-authored-by: Eduard Gert <[email protected]>
1 parent 25be69e commit c8e3b50

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

src/app/(dashboard)/peer/page.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import useFetchApi from "@utils/api";
3030
import dayjs from "dayjs";
3131
import { isEmpty, trim } from "lodash";
3232
import {
33+
Barcode,
3334
Cpu,
3435
FlagIcon,
3536
Globe,
@@ -429,6 +430,19 @@ function PeerInformationCard({ peer }: { peer: Peer }) {
429430
}
430431
value={peer.os}
431432
/>
433+
434+
{peer.serial_number && peer.serial_number !== "" && (
435+
<Card.ListItem
436+
label={
437+
<>
438+
<Barcode size={16} />
439+
Serial Number
440+
</>
441+
}
442+
value={peer.serial_number}
443+
/>
444+
)}
445+
432446
<Card.ListItem
433447
label={
434448
<>

src/interfaces/Peer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ export interface Peer {
2323
city_name: string;
2424
country_code: string;
2525
connection_ip: string;
26+
serial_number: string;
2627
}

src/modules/groups/AssignPeerToGroupModal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,6 @@ const PeersTableColumns: ColumnDef<Peer>[] = [
370370
header: ({ column }) => {
371371
return <DataTableHeader column={column}>OS</DataTableHeader>;
372372
},
373-
cell: ({ row }) => <PeerOSCell os={row.original.os} />,
373+
cell: ({ row }) => <PeerOSCell os={row.original.os} serial={row.original.serial_number} />,
374374
},
375375
];

src/modules/peers/PeerOSCell.tsx

+41-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
TooltipProvider,
55
TooltipTrigger,
66
} from "@components/Tooltip";
7+
import { Barcode, CpuIcon } from "lucide-react";
78
import Image from "next/image";
89
import React, { useMemo } from "react";
910
import { FaWindows } from "react-icons/fa6";
@@ -14,7 +15,11 @@ import FreeBSDLogo from "@/assets/os-icons/FreeBSD.png";
1415
import { getOperatingSystem } from "@/hooks/useOperatingSystem";
1516
import { OperatingSystem } from "@/interfaces/OperatingSystem";
1617

17-
export function PeerOSCell({ os }: { os: string }) {
18+
type Props = {
19+
os: string;
20+
serial?: string;
21+
};
22+
export function PeerOSCell({ os, serial }: Readonly<Props>) {
1823
return (
1924
<TooltipProvider>
2025
<Tooltip delayDuration={1}>
@@ -33,14 +38,47 @@ export function PeerOSCell({ os }: { os: string }) {
3338
</div>
3439
</div>
3540
</TooltipTrigger>
36-
<TooltipContent>
37-
<div className={"text-neutral-300 flex flex-col gap-1"}>{os}</div>
41+
<TooltipContent className={"!p-0"}>
42+
<div>
43+
<ListItem icon={<CpuIcon size={14} />} label={"OS"} value={os} />
44+
{serial && serial !== "" && (
45+
<ListItem
46+
icon={<Barcode size={14} />}
47+
label={"Serial Number"}
48+
value={serial}
49+
/>
50+
)}
51+
</div>
3852
</TooltipContent>
3953
</Tooltip>
4054
</TooltipProvider>
4155
);
4256
}
4357

58+
const ListItem = ({
59+
icon,
60+
label,
61+
value,
62+
}: {
63+
icon: React.ReactNode;
64+
label: string;
65+
value: string | React.ReactNode;
66+
}) => {
67+
return (
68+
<div
69+
className={
70+
"flex justify-between gap-5 border-b border-nb-gray-920 py-2 px-4 last:border-b-0 text-xs"
71+
}
72+
>
73+
<div className={"flex items-center gap-2 text-nb-gray-100 font-medium"}>
74+
{icon}
75+
{label}
76+
</div>
77+
<div className={"text-nb-gray-400"}>{value}</div>
78+
</div>
79+
);
80+
};
81+
4482
export function OSLogo({ os }: { os: string }) {
4583
const icon = useMemo(() => {
4684
return getOperatingSystem(os);

src/modules/peers/PeersTable.tsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,20 @@ const PeersTableColumns: ColumnDef<Peer>[] = [
134134
cell: ({ row }) => <PeerLastSeenCell peer={row.original} />,
135135
},
136136
{
137+
id: "os",
137138
accessorKey: "os",
138139
header: ({ column }) => {
139140
return <DataTableHeader column={column}>OS</DataTableHeader>;
140141
},
141-
cell: ({ row }) => <PeerOSCell os={row.original.os} />,
142+
cell: ({ row }) => <PeerOSCell os={row.original.os} serial={row.original.serial_number} />,
143+
},
144+
{
145+
id: "serial",
146+
header: ({ column }) => {
147+
return <DataTableHeader column={column}>Serial number</DataTableHeader>;
148+
},
149+
accessorFn: (peer) => peer.serial_number,
150+
sortingFn: "text",
142151
},
143152
{
144153
accessorKey: "version",
@@ -241,14 +250,15 @@ export default function PeersTable({ peers, isLoading, headingTarget }: Props) {
241250
setSorting={setSorting}
242251
columns={PeersTableColumns}
243252
data={peers}
244-
searchPlaceholder={"Search by name, IP, owner or group..."}
253+
searchPlaceholder={"Search by name, IP, Serial, owner or group..."}
245254
columnVisibility={{
246255
select: !isUser,
247256
connected: false,
248257
approval_required: false,
249258
group_name_strings: false,
250259
group_names: false,
251260
ip: false,
261+
serial: false,
252262
user_name: false,
253263
user_email: false,
254264
actions: !isUser,

0 commit comments

Comments
 (0)