feat(web): update machine status view
This commit is contained in:
		
							parent
							
								
									ef3c2e4348
								
							
						
					
					
						commit
						06f427ef70
					
				@ -5,6 +5,7 @@ import {
 | 
				
			|||||||
  CreateDeploymentButton,
 | 
					  CreateDeploymentButton,
 | 
				
			||||||
  MachineSelect,
 | 
					  MachineSelect,
 | 
				
			||||||
  RunWorkflowButton,
 | 
					  RunWorkflowButton,
 | 
				
			||||||
 | 
					  VersionDetails,
 | 
				
			||||||
  VersionSelect,
 | 
					  VersionSelect,
 | 
				
			||||||
} from "@/components/VersionSelect";
 | 
					} from "@/components/VersionSelect";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
@ -46,6 +47,8 @@ export default async function Page({
 | 
				
			|||||||
              <CreateDeploymentButton workflow={workflow} machines={machines} />
 | 
					              <CreateDeploymentButton workflow={workflow} machines={machines} />
 | 
				
			||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <VersionDetails workflow={workflow} />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <MachinesWSMain machines={machines} />
 | 
					            <MachinesWSMain machines={machines} />
 | 
				
			||||||
          </CardContent>
 | 
					          </CardContent>
 | 
				
			||||||
        </Card>
 | 
					        </Card>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
"use client";
 | 
					"use client";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { Badge } from "@/components/ui/badge";
 | 
				
			||||||
import type { getMachines } from "@/server/curdMachine";
 | 
					import type { getMachines } from "@/server/curdMachine";
 | 
				
			||||||
 | 
					import { Check, CircleOff, SatelliteDish } from "lucide-react";
 | 
				
			||||||
import React, { useEffect } from "react";
 | 
					import React, { useEffect } from "react";
 | 
				
			||||||
import useWebSocket, { ReadyState } from "react-use-websocket";
 | 
					import useWebSocket, { ReadyState } from "react-use-websocket";
 | 
				
			||||||
import { create } from "zustand";
 | 
					import { create } from "zustand";
 | 
				
			||||||
@ -36,12 +38,14 @@ export function MachinesWSMain(props: {
 | 
				
			|||||||
  machines: Awaited<ReturnType<typeof getMachines>>;
 | 
					  machines: Awaited<ReturnType<typeof getMachines>>;
 | 
				
			||||||
}) {
 | 
					}) {
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className="flex flex-col gap-2 mt-6">
 | 
					    <div className="flex flex-col gap-2 mt-4">
 | 
				
			||||||
      Machine Status
 | 
					      Machine Status
 | 
				
			||||||
 | 
					      <div className="flex flex-wrap gap-2">
 | 
				
			||||||
        {props.machines.map((x) => (
 | 
					        {props.machines.map((x) => (
 | 
				
			||||||
          <MachineWS key={x.id} machine={x} />
 | 
					          <MachineWS key={x.id} machine={x} />
 | 
				
			||||||
        ))}
 | 
					        ))}
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -55,17 +59,19 @@ function MachineWS({
 | 
				
			|||||||
  const { lastMessage, readyState } = useWebSocket(
 | 
					  const { lastMessage, readyState } = useWebSocket(
 | 
				
			||||||
    `${wsEndpoint}/comfyui-deploy/ws`,
 | 
					    `${wsEndpoint}/comfyui-deploy/ws`,
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      shouldReconnect: ()=> true,
 | 
					      shouldReconnect: () => true,
 | 
				
			||||||
      reconnectAttempts: 20,
 | 
					      reconnectAttempts: 20,
 | 
				
			||||||
      reconnectInterval: 1000,
 | 
					      reconnectInterval: 1000,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const connectionStatus = {
 | 
					  const connectionStatus = {
 | 
				
			||||||
    [ReadyState.CONNECTING]: "Connecting",
 | 
					    [ReadyState.CONNECTING]: (
 | 
				
			||||||
    [ReadyState.OPEN]: "Open",
 | 
					      <SatelliteDish size={14} className="text-orange-500" />
 | 
				
			||||||
    [ReadyState.CLOSING]: "Closing",
 | 
					    ),
 | 
				
			||||||
    [ReadyState.CLOSED]: "Closed",
 | 
					    [ReadyState.OPEN]: <Check size={14} className="text-green-500" />,
 | 
				
			||||||
 | 
					    [ReadyState.CLOSING]: <CircleOff size={14} className="text-orange-500" />,
 | 
				
			||||||
 | 
					    [ReadyState.CLOSED]: <CircleOff size={14} className="text-red-500" />,
 | 
				
			||||||
    [ReadyState.UNINSTANTIATED]: "Uninstantiated",
 | 
					    [ReadyState.UNINSTANTIATED]: "Uninstantiated",
 | 
				
			||||||
  }[readyState];
 | 
					  }[readyState];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -81,8 +87,8 @@ function MachineWS({
 | 
				
			|||||||
  }, [lastMessage]);
 | 
					  }, [lastMessage]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div className="text-sm">
 | 
					    <Badge className="text-sm flex gap-2 font-normal" variant="outline">
 | 
				
			||||||
      {machine.name} - {connectionStatus}
 | 
					      {machine.name} {connectionStatus}
 | 
				
			||||||
    </div>
 | 
					    </Badge>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import { callServerPromise } from "./callServerPromise";
 | 
					import { callServerPromise } from "./callServerPromise";
 | 
				
			||||||
import { LoadingIcon } from "@/components/LoadingIcon";
 | 
					import { LoadingIcon } from "@/components/LoadingIcon";
 | 
				
			||||||
 | 
					import { Badge } from "@/components/ui/badge";
 | 
				
			||||||
import { Button } from "@/components/ui/button";
 | 
					import { Button } from "@/components/ui/button";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
  DropdownMenu,
 | 
					  DropdownMenu,
 | 
				
			||||||
@ -199,3 +200,48 @@ export function CreateDeploymentButton({
 | 
				
			|||||||
    </DropdownMenu>
 | 
					    </DropdownMenu>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const customInputNodes: Record<string, string> = {
 | 
				
			||||||
 | 
					  ComfyUIDeployExternalText: "string",
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function VersionDetails({
 | 
				
			||||||
 | 
					  workflow,
 | 
				
			||||||
 | 
					}: {
 | 
				
			||||||
 | 
					  workflow: Awaited<ReturnType<typeof findFirstTableWithVersion>>;
 | 
				
			||||||
 | 
					}) {
 | 
				
			||||||
 | 
					  const [version] = useQueryState("version", {
 | 
				
			||||||
 | 
					    defaultValue: workflow?.versions[0].version ?? 1,
 | 
				
			||||||
 | 
					    ...parseAsInteger,
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					  const workflow_version = workflow?.versions.find(
 | 
				
			||||||
 | 
					    (x) => x.version === version
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <div className="mt-4">
 | 
				
			||||||
 | 
					      Workflow Details
 | 
				
			||||||
 | 
					      <div className="border rounded-lg p-2">
 | 
				
			||||||
 | 
					        {workflow_version?.workflow_api && (
 | 
				
			||||||
 | 
					          <div>
 | 
				
			||||||
 | 
					            {Object.entries(workflow_version.workflow_api).map(
 | 
				
			||||||
 | 
					              ([key, value]) => {
 | 
				
			||||||
 | 
					                if (!value.class_type) return <> </>;
 | 
				
			||||||
 | 
					                const nodeType = customInputNodes[value.class_type];
 | 
				
			||||||
 | 
					                if (nodeType) {
 | 
				
			||||||
 | 
					                  const input_id = value.inputs.input_id;
 | 
				
			||||||
 | 
					                  const defaultValue = value.inputs.default_value;
 | 
				
			||||||
 | 
					                  return (
 | 
				
			||||||
 | 
					                    <>
 | 
				
			||||||
 | 
					                      <Badge>{input_id}</Badge> {nodeType} {defaultValue}
 | 
				
			||||||
 | 
					                    </>
 | 
				
			||||||
 | 
					                  );
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return <></>;
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            )}
 | 
				
			||||||
 | 
					          </div>
 | 
				
			||||||
 | 
					        )}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user