import { Check, CheckCircle } from 'lucide-react'; import { notifySuccess } from '@/portainer/services/notifications'; import { useDeleteEnvironmentsMutation } from '@/react/portainer/environments/queries/useDeleteEnvironmentsMutation'; import { Environment } from '@/react/portainer/environments/types'; import { withReactQuery } from '@/react-tools/withReactQuery'; import { useIsPureAdmin } from '@/react/hooks/useUser'; import { Button } from '@@/buttons'; import { openModal } from '@@/modals'; import { TooltipWithChildren } from '@@/Tip/TooltipWithChildren'; import { DeleteButton } from '@@/buttons/DeleteButton'; import { useAssociateDeviceMutation, useLicenseOverused } from '../queries'; import { WaitingRoomEnvironment } from '../types'; import { AssignmentDialog } from './AssignmentDialog/AssignmentDialog'; const overusedTooltip = ( <> Associating devices is disabled as your node count exceeds your license limit ); export function TableActions({ selectedRows, }: { selectedRows: WaitingRoomEnvironment[]; }) { const isPureAdmin = useIsPureAdmin(); const associateMutation = useAssociateDeviceMutation(); const removeMutation = useDeleteEnvironmentsMutation(); const licenseOverused = useLicenseOverused(selectedRows.length); return ( <> handleRemoveDevice(selectedRows)} disabled={selectedRows.length === 0} data-cy="remove-device-button" confirmMessage="You're about to remove edge device(s) from waiting room, which will not be shown until next agent startup." > Remove Device Associate device(s) and assigning edge groups, group and tags with overriding options ) } > Associate device(s) based on their pre-assigned edge groups, group and tags ) } > ); async function handleAssociateAndAssign( environments: WaitingRoomEnvironment[] ) { const assigned = await openModal(withReactQuery(AssignmentDialog), { environments, }); if (!assigned) { return; } handleAssociateDevice(environments); } function handleAssociateDevice(devices: Environment[]) { associateMutation.mutate( devices.map((d) => d.Id), { onSuccess() { notifySuccess('Success', 'Edge devices associated successfully'); }, } ); } async function handleRemoveDevice(devices: Environment[]) { removeMutation.mutate( devices.map((d) => d.Id), { onSuccess() { notifySuccess('Success', 'Edge devices were hidden successfully'); }, } ); } }