From 0c8cfafcd027d871f6b88e95e8c6fd668a1b9ec7 Mon Sep 17 00:00:00 2001 From: kunish Date: Tue, 20 Jun 2023 10:36:15 +0800 Subject: [PATCH] feat(group): show subscription tag on node hover --- src/components/SortableResourceBadge.tsx | 42 +++-- src/pages/Orchestrate.tsx | 229 ++++++++++++----------- 2 files changed, 140 insertions(+), 131 deletions(-) diff --git a/src/components/SortableResourceBadge.tsx b/src/components/SortableResourceBadge.tsx index c2359fc4..ab8c7593 100644 --- a/src/components/SortableResourceBadge.tsx +++ b/src/components/SortableResourceBadge.tsx @@ -1,6 +1,6 @@ import { useSortable } from '@dnd-kit/sortable' import { CSS } from '@dnd-kit/utilities' -import { ActionIcon, Badge, Text } from '@mantine/core' +import { ActionIcon, Badge, Text, Tooltip } from '@mantine/core' import { IconX } from '@tabler/icons-react' export const SortableResourceBadge = ({ @@ -8,11 +8,13 @@ export const SortableResourceBadge = ({ name, onRemove, dragDisabled, + children, }: { id: string name: string onRemove: () => void dragDisabled?: boolean + children?: React.ReactNode }) => { const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({ id, @@ -20,23 +22,25 @@ export const SortableResourceBadge = ({ }) return ( - - - - } - style={{ - transform: CSS.Transform.toString(transform), - transition, - zIndex: isDragging ? 10 : 0, - }} - > - - {name} - - + + + + + } + style={{ + transform: CSS.Transform.toString(transform), + transition, + zIndex: isDragging ? 10 : 0, + }} + > + + {name} + + + ) } diff --git a/src/pages/Orchestrate.tsx b/src/pages/Orchestrate.tsx index b6347e28..bcb4966f 100644 --- a/src/pages/Orchestrate.tsx +++ b/src/pages/Orchestrate.tsx @@ -416,122 +416,127 @@ export const OrchestratePage = () => { bordered > - {groupsQuery?.groups.map(({ id: groupId, name, policy, nodes, subscriptions }) => ( - removeGroupMutation.mutate(groupId) : undefined} - actions={ - - { - if (renameFormModalRef.current) { - renameFormModalRef.current.setProps({ - id: groupId, - type: RuleType.group, - oldName: name, + {groupsQuery?.groups.map( + ({ id: groupId, name, policy, nodes: groupNodes, subscriptions: groupSubscriptions }) => ( + removeGroupMutation.mutate(groupId) : undefined} + actions={ + + { + if (renameFormModalRef.current) { + renameFormModalRef.current.setProps({ + id: groupId, + type: RuleType.group, + oldName: name, + }) + } + openRenameFormModal() + }} + > + + + + { + updateGroupFormModalRef.current?.setEditingID(groupId) + + updateGroupFormModalRef.current?.initOrigins({ + name, + policy, }) - } - openRenameFormModal() - }} - > - - - - { - updateGroupFormModalRef.current?.setEditingID(groupId) - - updateGroupFormModalRef.current?.initOrigins({ - name, - policy, - }) - openUpdateGroupFormModal() - }} - > - - - - } - > - - {policy} - + openUpdateGroupFormModal() + }} + > + + + + } + > + + {policy} + - + - - {nodes.length > 0 && ( - - - {t('node')} ({nodes.length}) - - - - - - - {nodes.map(({ id: nodeId, tag, name }) => ( - - groupDelNodesMutation.mutate({ - id: groupId, - nodeIDs: [nodeId], - }) - } - /> - ))} - - - - - - )} - - {subscriptions.length > 0 && ( - - - {t('subscription')} ({subscriptions.length}) - - - - - - - {subscriptions.map(({ id: subscriptionId, tag, link }) => ( - - groupDelSubscriptionsMutation.mutate({ - id: groupId, - subscriptionIDs: [subscriptionId], - }) - } - /> - ))} - - - - - - )} - - - ))} + + {groupNodes.length > 0 && ( + + + {t('node')} ({groupNodes.length}) + + + + + + + {groupNodes.map(({ id: nodeId, tag, name, subscriptionID }) => ( + + groupDelNodesMutation.mutate({ + id: groupId, + nodeIDs: [nodeId], + }) + } + > + {subscriptionID && + subscriptionsQuery?.subscriptions.find((s) => s.id === subscriptionID)?.tag} + + ))} + + + + + + )} + + {groupSubscriptions.length > 0 && ( + + + {t('subscription')} ({groupSubscriptions.length}) + + + + + + + {groupSubscriptions.map(({ id: subscriptionId, tag, link }) => ( + + groupDelSubscriptionsMutation.mutate({ + id: groupId, + subscriptionIDs: [subscriptionId], + }) + } + /> + ))} + + + + + + )} + + + ) + )}