🙌 OpenHands: AI-Driven Development
feat(automations): add Download Tarball option to automation kebab menu (#725)
Tim O'Farrelldcdef5832e2c
diff --git a/src/api/automation-service/automation-service.api.ts b/src/api/automation-service/automation-service.api.tsindex fcb999eedf..124c044f7d 100644--- a/src/api/automation-service/automation-service.api.ts+++ b/src/api/automation-service/automation-service.api.ts@@ -165,6 +165,33 @@ class AutomationService {return AutomationService.updateAutomation(id, { enabled });}+ static async downloadTarball(id: string, name: string): Promise<void> {+ const active = getActiveBackend().backend;+ const path = `${AUTOMATION_BASE_PATH}/v1/${encodeURIComponent(id)}/tarball`;++ let blob: Blob;+ if (active.kind === "cloud") {+ blob = await callCloudProxy<Blob>({+ backend: active,+ method: "GET",+ path,+ responseType: "blob",+ });+ } else {+ const { data } = await localAutomationAxios.get<Blob>(path, {+ responseType: "blob",+ });+ blob = data;+ }++ const url = URL.createObjectURL(blob);+ const a = document.createElement("a");+ a.href = url;+ a.download = `${name}.tar`;+ a.click();+ URL.revokeObjectURL(url);+ }+static async checkHealth(): Promise<AutomationHealthResponse> {const active = getActiveBackend().backend;const path = `${AUTOMATION_BASE_PATH}/health`;diff --git a/src/components/features/automations/automation-card.tsx b/src/components/features/automations/automation-card.tsxindex 4834321acb..48ef191247 100644--- a/src/components/features/automations/automation-card.tsx+++ b/src/components/features/automations/automation-card.tsx@@ -1,6 +1,7 @@import { useTranslation } from "react-i18next";import { I18nKey } from "#/i18n/declaration";import type { Automation } from "#/types/automation";+import AutomationService from "#/api/automation-service/automation-service.api";import { ToggleSwitch } from "./toggle-switch";import { MetadataChip } from "./metadata-chip";import { KebabMenu } from "./kebab-menu";@@ -11,6 +12,7 @@ import FolderIcon from "#/icons/folder.svg?react";import ClockIcon from "#/icons/clock.svg?react";import SparkleIcon from "#/icons/sparkle.svg?react";import PowerIcon from "#/icons/power.svg?react";+import DownloadIcon from "#/icons/download.svg?react";import TrashIcon from "#/icons/trash.svg?react";import EditIcon from "#/icons/u-edit.svg?react";@@ -51,6 +53,13 @@ export function AutomationCard({icon: <PowerIcon className="size-4" />,onClick: () => onToggle(automation.id, automation.enabled),},+ {+ label: t(I18nKey.AUTOMATIONS$DOWNLOAD_TARBALL),+ icon: <DownloadIcon className="size-4" />,+ onClick: () => {+ AutomationService.downloadTarball(automation.id, automation.name);+ },+ },{label: t(I18nKey.AUTOMATIONS$DELETE),icon: <TrashIcon className="size-4" />,diff --git a/src/components/features/automations/detail/detail-header.tsx b/src/components/features/automations/detail/detail-header.tsxindex a0de4275fa..e4467a2e76 100644--- a/src/components/features/automations/detail/detail-header.tsx+++ b/src/components/features/automations/detail/detail-header.tsx@@ -1,9 +1,11 @@import { useTranslation } from "react-i18next";import { I18nKey } from "#/i18n/declaration";import type { Automation } from "#/types/automation";+import AutomationService from "#/api/automation-service/automation-service.api";import { ToggleSwitch } from "#/components/features/automations/toggle-switch";import { KebabMenu } from "#/components/features/automations/kebab-menu";import PowerIcon from "#/icons/power.svg?react";+import DownloadIcon from "#/icons/download.svg?react";import TrashIcon from "#/icons/trash.svg?react";import EditIcon from "#/icons/u-edit.svg?react";import { useHasPermission } from "#/hooks/use-has-permission";@@ -46,6 +48,13 @@ export function DetailHeader({icon: <PowerIcon className="size-4" />,onClick: onToggle,},+ {+ label: t(I18nKey.AUTOMATIONS$DOWNLOAD_TARBALL),+ icon: <DownloadIcon className="size-4" />,+ onClick: () => {+ AutomationService.downloadTarball(automation.id, automation.name);+ },+ },{label: t(I18nKey.AUTOMATIONS$DELETE),icon: <TrashIcon className="size-4" />,diff --git a/src/i18n/translation.json b/src/i18n/translation.jsonindex 1068268ae9..8b8c29537f 100644--- a/src/i18n/translation.json+++ b/src/i18n/translation.json@@ -11678,6 +11678,23 @@"uk": "Вимкнути","ca": "Desactiva"},+ "AUTOMATIONS$DOWNLOAD_TARBALL": {+ "en": "Tarball",+ "ja": "Tarball",+ "zh-CN": "Tarball",+ "zh-TW": "Tarball",+ "ko-KR": "Tarball",+ "no": "Tarball",+ "it": "Tarball",+ "pt": "Tarball",+ "es": "Tarball",+ "ar": "Tarball",+ "fr": "Tarball",+ "tr": "Tarball",+ "de": "Tarball",+ "uk": "Tarball",+ "ca": "Tarball"+ },"AUTOMATIONS$DELETE": {"en": "Delete","ja": "削除",diff --git a/src/icons/download.svg b/src/icons/download.svgnew file mode 100644index 0000000000..70698157de--- /dev/null+++ b/src/icons/download.svg@@ -0,0 +1,3 @@+<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">+ <path stroke-linecap="round" stroke-linejoin="round" d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />+</svg>