File size: 7,321 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | import { useTranslation } from "react-i18next";
import { ModalBackdrop } from "#/components/shared/modals/modal-backdrop";
import { ModalCloseButton } from "#/components/shared/modals/modal-close-button";
import { BrandButton } from "#/components/features/settings/brand-button";
import { SettingsSwitch } from "#/components/features/settings/settings-switch";
import { SkillIconBadge } from "#/components/features/skills/skill-icon-badge";
import { I18nKey } from "#/i18n/declaration";
import { cn } from "#/utils/utils";
import { modalTitleLgClassName } from "#/utils/modal-classes";
import { extensionModuleCardPillClassName } from "#/utils/extension-module-card-classes";
import type { PluginViewModel } from "./build-plugins-view-model";
import { PluginFilesSection } from "./plugin-files-section";
interface PluginDetailModalProps {
plugin: PluginViewModel;
isBusy?: boolean;
isDisabled?: boolean;
onToggle: (enabled: boolean) => void;
onInstall: () => void;
onUninstall: () => void;
onRefresh: () => void;
onClose: () => void;
onStartConversation?: () => void;
}
export function PluginDetailModal({
plugin,
isBusy = false,
isDisabled = false,
onToggle,
onInstall,
onUninstall,
onRefresh,
onClose,
onStartConversation,
}: PluginDetailModalProps) {
const { t } = useTranslation("openhands");
const actionsDisabled = isDisabled || isBusy;
return (
<ModalBackdrop onClose={onClose} aria-label={plugin.name}>
<div
data-testid="plugin-detail-modal"
data-plugin-name={plugin.name}
className="relative flex w-[640px] max-w-[90vw] max-h-[85vh] flex-col rounded-xl border border-[var(--oh-border)] bg-base-secondary"
>
<ModalCloseButton
onClose={onClose}
testId="plugin-detail-modal-close"
/>
<header className="flex-shrink-0 px-6 pb-4 pt-6">
<h2 className={cn("pr-6", modalTitleLgClassName)}>{plugin.name}</h2>
{plugin.source ? (
<p className="mt-1 break-all text-xs text-tertiary-alt">
{plugin.source}
</p>
) : null}
</header>
<div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-6 custom-scrollbar">
{plugin.description ? (
<p className="text-sm leading-relaxed text-tertiary-light">
{plugin.description}
</p>
) : null}
<div className="flex flex-wrap gap-2">
{plugin.isLocal ? (
<span className={extensionModuleCardPillClassName}>
{t(I18nKey.SETTINGS$PLUGINS_FILTER_LOCAL)}
</span>
) : null}
{plugin.version ? (
<span className={extensionModuleCardPillClassName}>
{t(I18nKey.SETTINGS$SKILLS_VERSION, {
version: plugin.version,
})}
</span>
) : null}
{plugin.ref ? (
<span className={extensionModuleCardPillClassName}>
{t(I18nKey.SETTINGS$PLUGINS_REF_LABEL)} {plugin.ref}
</span>
) : null}
{plugin.repoPath ? (
<span className={extensionModuleCardPillClassName}>
{t(I18nKey.SETTINGS$PLUGINS_REPO_PATH_LABEL)} {plugin.repoPath}
</span>
) : null}
</div>
{plugin.installed ? (
<SettingsSwitch
testId={`plugin-modal-toggle-${plugin.name}`}
isToggled={plugin.enabled}
onToggle={onToggle}
isDisabled={actionsDisabled}
togglePosition="right"
>
{t(
plugin.enabled
? I18nKey.SETTINGS$SKILLS_ENABLED
: I18nKey.SETTINGS$SKILLS_DISABLED,
)}
</SettingsSwitch>
) : null}
{plugin.skills?.length ? (
<section className="flex min-w-0 flex-col gap-2">
<h3 className="text-sm font-medium text-white">
{t(I18nKey.SETTINGS$PLUGINS_SKILLS_IN_BUNDLE)}
</h3>
<ul className="flex min-w-0 flex-col gap-2">
{plugin.skills.map((skill) => (
<li
key={skill.name}
data-testid={`plugin-bundled-skill-${skill.name}`}
className="flex items-start gap-3 rounded-lg border border-[var(--oh-border)] bg-[rgba(255,255,255,0.04)] px-3 py-2.5"
>
<SkillIconBadge skillName={skill.name} />
<div className="min-w-0 flex-1">
<p className="truncate text-sm font-semibold text-white">
{skill.name}
</p>
{skill.description ? (
<p className="mt-0.5 break-words text-xs leading-relaxed text-tertiary-light">
{skill.description}
</p>
) : null}
</div>
</li>
))}
</ul>
</section>
) : null}
{plugin.path && plugin.files?.length ? (
<PluginFilesSection basePath={plugin.path} files={plugin.files} />
) : null}
</div>
<footer className="flex flex-shrink-0 flex-wrap justify-end gap-2 px-6 pb-6 pt-4">
{plugin.installed ? (
<>
<BrandButton
type="button"
variant="secondary"
testId={`plugin-detail-refresh-${plugin.name}`}
isDisabled={actionsDisabled}
onClick={onRefresh}
>
{t(I18nKey.SETTINGS$PLUGINS_REFRESH)}
</BrandButton>
<BrandButton
type="button"
variant="secondary"
testId={`plugin-detail-uninstall-${plugin.name}`}
isDisabled={actionsDisabled}
onClick={onUninstall}
>
{t(I18nKey.SETTINGS$PLUGINS_UNINSTALL)}
</BrandButton>
</>
) : plugin.isLocal ? null : (
<BrandButton
type="button"
variant="secondary"
testId={`plugin-detail-install-${plugin.name}`}
isDisabled={actionsDisabled}
onClick={onInstall}
>
{t(
isBusy
? I18nKey.SETTINGS$PLUGINS_INSTALLING
: I18nKey.SETTINGS$PLUGINS_INSTALL,
)}
</BrandButton>
)}
{plugin.source && onStartConversation ? (
<BrandButton
type="button"
variant="secondary"
testId={`plugin-detail-start-conversation-${plugin.name}`}
onClick={onStartConversation}
>
{t(I18nKey.COMMON$START_CONVERSATION)}
</BrandButton>
) : null}
<BrandButton
type="button"
variant="secondary"
testId="plugin-detail-modal-dismiss"
onClick={onClose}
>
{t(I18nKey.BUTTON$CLOSE)}
</BrandButton>
</footer>
</div>
</ModalBackdrop>
);
}
|