From 44166a3c82f4b9e9edcc8b72f6890bc989d96b93 Mon Sep 17 00:00:00 2001 From: Edouard Vanbelle Date: Wed, 27 Nov 2024 01:04:49 +0100 Subject: [PATCH] [WIP] serial number lookup + filter to only "All" group Signed-off-by: Edouard Vanbelle --- src/modules/groups/AssignPeerToGroupModal.tsx | 2 +- src/modules/groups/GroupSelector.tsx | 69 +++++- src/modules/peers/PeerOSCell.tsx | 42 +++- src/modules/peers/PeersTable.tsx | 200 ++++++++++-------- 4 files changed, 211 insertions(+), 102 deletions(-) diff --git a/src/modules/groups/AssignPeerToGroupModal.tsx b/src/modules/groups/AssignPeerToGroupModal.tsx index 9e15305b..493dbb51 100644 --- a/src/modules/groups/AssignPeerToGroupModal.tsx +++ b/src/modules/groups/AssignPeerToGroupModal.tsx @@ -367,6 +367,6 @@ const PeersTableColumns: ColumnDef[] = [ header: ({ column }) => { return OS; }, - cell: ({ row }) => , + cell: ({ row }) => , }, ]; diff --git a/src/modules/groups/GroupSelector.tsx b/src/modules/groups/GroupSelector.tsx index c3b77d80..8981e402 100644 --- a/src/modules/groups/GroupSelector.tsx +++ b/src/modules/groups/GroupSelector.tsx @@ -21,7 +21,8 @@ import { Group } from "@/interfaces/Group"; interface MultiSelectProps { values: string[]; - onChange: (items: string[]) => void; + exactValue?: string; + onChange: (items: string[], exactItem?: string) => void; disabled?: boolean; popoverWidth?: "auto" | number; groups: Group[] | undefined; @@ -29,6 +30,7 @@ interface MultiSelectProps { export function GroupSelector({ onChange, values, + exactValue: exactValues, disabled = false, popoverWidth = 400, groups, @@ -40,9 +42,20 @@ export function GroupSelector({ const toggle = (code: string) => { const isSelected = values.find((c) => c == code) != undefined; if (isSelected) { - onChange && onChange(values.filter((c) => c != code)); + onChange && onChange(values.filter((c) => c != code), undefined); } else { - onChange && onChange([...values, code]); + onChange && onChange([...values, code], undefined); + setSearch(""); + } + }; + + const toggleExactGroup = (code: string) => { + const isSelected = exactValues == code; + if (isSelected) { + onChange && onChange([], undefined); + setSearch(""); + } else { + onChange && onChange([], code); setSearch(""); } }; @@ -65,11 +78,13 @@ export function GroupSelector({ )} - - - {!isUser && ( + { + !isUser + && tableGroups.length > 1 // if length == 1, it means only "All" group exists, case not relevant + && ( { - table.setPageIndex(0); - if (groups.length == 0) { - table.getColumn("group_names")?.setFilterValue(undefined); - return; - } else { - table.getColumn("group_names")?.setFilterValue(groups); - } - resetSelectedRows(); + exactValue={ + (table + .getColumn("exact_group_name_strings") + ?.getFilterValue() as string) || undefined + } + onChange={(groups, exactItem) => { + const group_filter = groups.length == 0 ? undefined : groups; + overrideTableFilter( table, [ + { + id: "group_names", + value: group_filter + }, + { + id: "exact_group_name_strings", + value: exactItem + } + ]); }} - groups={tableGroups} + // as all peers are assigned to All group, do not propose it + groups={tableGroups.filter((group) => group.name != "All")} /> )} + + {