Skip to content

An open-source, self-hosted system for apps built with web technologies.

2.7 KB
Raw Blame
import { Badge, Button, Table, Text, useAppearance, useColor, useScale } from "@phreshos/react-ui"
import type Process from "@client/core/link-manager/auth-manager/process-manager/process"
import usePromise from "@libs/react-promise"
import type Program from "@client/core/link-manager/auth-manager/program-manager/program"
import { ApplicationContext } from "@client/view/contexts"
import programIcon from "@client/view/structure/desktop/programs/program-icon"

/**
 * One live Process as a table row: its name, its Program, a mark for each
 * running Endpoint, and End, as in Settings. The live list owns removal.
 */
export default function ProcessRow({ process, program, server, client }: Readonly<{
    process: Process
    program: Program | undefined
    server: boolean
    client: boolean
}>) {

    const application = ApplicationContext.useValue()

    const space = useScale(useAppearance().spacing)

    const danger = useColor("danger").base

    const ending = usePromise(() => process.exit())

    const label = process.name ?? process.identity

    const failure = ending.exception ? ending.exception.current instanceof Error ? ending.exception.current.message : "Could not end this Process." : null

    return <Table.Row id={process.identity} textValue={`${program?.name ?? process.program} ${label}`}>

        <Table.Cell>
            <span className="flex min-w-0 items-center" style={{ gap: space.small, maxWidth: "100%" }}>
                {program ? <img src={programIcon(application.doors.program, program.assetId)} alt="" draggable={false} style={{ width: space.medium, height: space.medium }} className="shrink-0 object-contain" /> : null}
                <Text truncate title={process.identity}>{label}</Text>
                {/* A failure to end stays beside the Process it belongs to. */}
                {failure && <span role="alert" style={{ display: "flex", minWidth: 0, color: danger }}><Text truncate title={failure}>{failure}</Text></span>}
            </span>
        </Table.Cell>

        <Table.Cell><Text tone="secondary">{program?.name ?? process.program}</Text></Table.Cell>

        <Table.Cell>
            <span className="flex" style={{ gap: space.xsmall }}>
                {server && <Badge size="xsmall">Server</Badge>}
                {client && <Badge size="xsmall">Client</Badge>}
            </span>
        </Table.Cell>

        <Table.Cell>
            <Button
                size="xsmall"
                depth="none"
                color="danger"
                pending={ending.isPending}
                aria-label={`End process ${label}`}
                onPress={() => void ending.safeExecute()}
            >End</Button>
        </Table.Cell>

    </Table.Row>
}