2024-08-04 00:51:30 -04:00
|
|
|
import { Popover } from '@headlessui/react'
|
|
|
|
import Tooltip from './Tooltip'
|
|
|
|
import { machineManager } from 'lib/machineManager'
|
2024-08-16 07:15:42 -04:00
|
|
|
import { isDesktop } from 'lib/isDesktop'
|
2024-08-04 00:51:30 -04:00
|
|
|
import { CustomIcon } from './CustomIcon'
|
|
|
|
|
|
|
|
export const NetworkMachineIndicator = ({
|
|
|
|
className,
|
|
|
|
}: {
|
|
|
|
className?: string
|
|
|
|
}) => {
|
2024-08-19 15:57:31 -07:00
|
|
|
const machineCount = machineManager.machineCount()
|
|
|
|
const reason = machineManager.noMachinesReason()
|
2024-10-17 15:30:46 -07:00
|
|
|
const machines = machineManager.machines
|
|
|
|
console.log('react machines', machines)
|
2024-08-19 15:57:31 -07:00
|
|
|
|
2024-08-16 07:15:42 -04:00
|
|
|
return isDesktop() ? (
|
2024-08-04 00:51:30 -04:00
|
|
|
<Popover className="relative">
|
|
|
|
<Popover.Button
|
|
|
|
className={
|
|
|
|
'flex items-center p-0 border-none bg-transparent dark:bg-transparent relative ' +
|
|
|
|
(className || '')
|
|
|
|
}
|
|
|
|
data-testid="network-machine-toggle"
|
|
|
|
>
|
|
|
|
<CustomIcon name="printer3d" className="w-5 h-5" />
|
|
|
|
{machineCount > 0 && (
|
|
|
|
<p aria-hidden className="flex items-center justify-center text-xs">
|
|
|
|
{machineCount}
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
<Tooltip position="top-right" wrapperClassName="ui-open:hidden">
|
2024-08-19 15:57:31 -07:00
|
|
|
Network machines ({machineCount}) {reason && `: ${reason}`}
|
2024-08-04 00:51:30 -04:00
|
|
|
</Tooltip>
|
|
|
|
</Popover.Button>
|
|
|
|
<Popover.Panel
|
|
|
|
className="absolute right-0 left-auto bottom-full mb-1 w-64 flex flex-col gap-1 align-stretch bg-chalkboard-10 dark:bg-chalkboard-90 rounded shadow-lg border border-solid border-chalkboard-20/50 dark:border-chalkboard-80/50 text-sm"
|
|
|
|
data-testid="network-popover"
|
|
|
|
>
|
|
|
|
<div className="flex items-center justify-between p-2 rounded-t-sm bg-chalkboard-20 dark:bg-chalkboard-80">
|
|
|
|
<h2 className="text-sm font-sans font-normal">Network machines</h2>
|
|
|
|
<p
|
|
|
|
data-testid="network"
|
|
|
|
className="font-bold text-xs uppercase px-2 py-1 rounded-sm"
|
|
|
|
>
|
|
|
|
{machineCount}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
{machineCount > 0 && (
|
|
|
|
<ul className="divide-y divide-chalkboard-20 dark:divide-chalkboard-80">
|
2024-10-17 15:30:46 -07:00
|
|
|
{machines.map((machine) => {
|
|
|
|
return (
|
|
|
|
<li key={machine.id} className={'px-2 py-4 gap-1 last:mb-0 '}>
|
|
|
|
<p className="">{machine.id.toUpperCase()}</p>
|
|
|
|
<p className="text-chalkboard-60 dark:text-chalkboard-50 text-xs">
|
|
|
|
{machine.make_model.model}
|
2024-08-28 15:15:37 -04:00
|
|
|
</p>
|
2024-08-04 00:51:30 -04:00
|
|
|
<p className="text-chalkboard-60 dark:text-chalkboard-50 text-xs">
|
2024-10-17 15:30:46 -07:00
|
|
|
{machine.state.state.toUpperCase()}
|
|
|
|
{machine.state.state === 'failed' && machine.state.message
|
|
|
|
? ': ' + machine.state.message
|
|
|
|
: ''}
|
2024-08-04 00:51:30 -04:00
|
|
|
</p>
|
2024-10-17 15:30:46 -07:00
|
|
|
{machine.extra &&
|
|
|
|
machine.extra.type === 'bambu' &&
|
|
|
|
machine.extra.nozzle_diameter && (
|
|
|
|
<p className="text-chalkboard-60 dark:text-chalkboard-50 text-xs">
|
|
|
|
Nozzle Diameter: {machine.extra.nozzle_diameter}
|
|
|
|
</p>
|
|
|
|
)}
|
2024-08-04 00:51:30 -04:00
|
|
|
</li>
|
|
|
|
)
|
2024-10-17 15:30:46 -07:00
|
|
|
})}
|
2024-08-04 00:51:30 -04:00
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
</Popover.Panel>
|
|
|
|
</Popover>
|
|
|
|
) : null
|
|
|
|
}
|