From 960200fb5968dc6c154ba08d668eb799c0fbcf93 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 | 79 ++++++- src/modules/peers/PeerOSCell.tsx | 42 +++- src/modules/peers/PeersTable.tsx | 213 ++++++++++-------- 4 files changed, 235 insertions(+), 101 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..ea0bd178 100644 --- a/src/modules/groups/GroupSelector.tsx +++ b/src/modules/groups/GroupSelector.tsx @@ -21,17 +21,23 @@ 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; + unassignedCount?: number; + defaultGroupName?: string; } export function GroupSelector({ onChange, values, + exactValue: exactValues, disabled = false, popoverWidth = 400, groups, + unassignedCount, + defaultGroupName = "All", //defined as a property, no clue if this value may change in the future }: MultiSelectProps) { const searchRef = React.useRef(null); const [inputRef, { width }] = useElementSize(); @@ -40,9 +46,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 +82,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} + unassignedCount={unassignedCount} + defaultGroupName={DEFAULT_GROUP_NAME} /> )} + + {