File size: 4,014 Bytes
9b906ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | import React from "react";
import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
import { cn } from "#/utils/utils";
import { CirclePlusCheckToggle } from "#/components/shared/buttons/circle-plus-check-toggle";
import { BrandButton } from "#/components/features/settings/brand-button";
import {
extensionModuleCardInteractiveClassName,
extensionModuleCardPillClassName,
extensionModuleCardSurfaceClassName,
} from "#/utils/extension-module-card-classes";
import type { PluginViewModel } from "./build-plugins-view-model";
interface PluginCardProps {
plugin: PluginViewModel;
/** A mutation targeting this plugin is in flight. */
isBusy?: boolean;
/** Management actions are unavailable (e.g. non-local backend). */
isDisabled?: boolean;
onOpen: () => void;
onInstall: () => void;
onToggle: (enabled: boolean) => void;
}
export function PluginCard({
plugin,
isBusy = false,
isDisabled = false,
onOpen,
onInstall,
onToggle,
}: PluginCardProps) {
const { t } = useTranslation("openhands");
const handleKeyDown = (event: React.KeyboardEvent) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
onOpen();
}
};
const handleInstall = (event?: React.MouseEvent<HTMLButtonElement>) => {
event?.stopPropagation();
onInstall();
};
return (
<div
data-testid={`plugin-card-${plugin.name}`}
role="button"
tabIndex={0}
onClick={onOpen}
onKeyDown={handleKeyDown}
className={cn(
"flex min-w-0 flex-col gap-3 overflow-hidden p-4",
extensionModuleCardSurfaceClassName,
extensionModuleCardInteractiveClassName,
)}
>
<header className="flex items-start justify-between gap-3">
<div className="min-w-0 flex-1">
<h3
data-testid={`plugin-name-${plugin.name}`}
className="truncate text-sm font-semibold text-white"
>
{plugin.name}
</h3>
{plugin.source ? (
<p
data-testid={`plugin-source-${plugin.name}`}
className="mt-0.5 min-w-0 truncate text-xs text-tertiary-alt"
title={plugin.source}
>
{plugin.source}
</p>
) : null}
</div>
{plugin.installed ? (
<CirclePlusCheckToggle
testId={`plugin-toggle-${plugin.name}`}
isSelected={plugin.enabled}
isDisabled={isDisabled || isBusy}
onToggle={onToggle}
disableTooltipKey={I18nKey.COMMON$DISABLE}
/>
) : plugin.isLocal ? (
<span
data-testid={`plugin-local-badge-${plugin.name}`}
className={cn(extensionModuleCardPillClassName, "flex-shrink-0")}
>
{t(I18nKey.SETTINGS$PLUGINS_FILTER_LOCAL)}
</span>
) : (
<BrandButton
type="button"
variant="secondary"
testId={`plugin-install-${plugin.name}`}
isDisabled={isDisabled || isBusy}
className="flex-shrink-0 whitespace-nowrap"
onClick={handleInstall}
>
{t(
isBusy
? I18nKey.SETTINGS$PLUGINS_INSTALLING
: I18nKey.SETTINGS$PLUGINS_INSTALL,
)}
</BrandButton>
)}
</header>
{plugin.description ? (
<p
data-testid={`plugin-description-${plugin.name}`}
className="line-clamp-2 break-words text-xs leading-relaxed text-tertiary-light"
>
{plugin.description}
</p>
) : null}
{(plugin.installed || plugin.isLocal) && plugin.version ? (
<span
data-testid={`plugin-version-${plugin.name}`}
className={cn(extensionModuleCardPillClassName, "self-start")}
>
{t(I18nKey.SETTINGS$SKILLS_VERSION, { version: plugin.version })}
</span>
) : null}
</div>
);
}
|