-
Notifications
You must be signed in to change notification settings - Fork 18
feat(automations): add deployment choice modal for responder automations #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FraterCCCLXIII
wants to merge
2
commits into
OpenHands:main
Choose a base branch
from
FraterCCCLXIII:feature/deployment-choice-modal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { AUTOMATION_CATALOG } from "@openhands/extensions/automations"; | ||
| import { | ||
| isResponderAutomation, | ||
| RESPONDER_INTEGRATION_IDS, | ||
| } from "#/utils/automation-responder"; | ||
|
|
||
| function byId(id: string) { | ||
| const automation = AUTOMATION_CATALOG.find((item) => item.id === id); | ||
| if (!automation) throw new Error(`missing catalog automation: ${id}`); | ||
| return automation; | ||
| } | ||
|
|
||
| describe("isResponderAutomation", () => { | ||
| it("treats GitHub automations as responders", () => { | ||
| expect(isResponderAutomation(byId("github-pr-reviewer"))).toBe(true); | ||
| expect(isResponderAutomation(byId("github-repo-monitor"))).toBe(true); | ||
| }); | ||
|
|
||
| it("treats Slack automations as responders", () => { | ||
| expect(isResponderAutomation(byId("slack-channel-monitor"))).toBe(true); | ||
| expect(isResponderAutomation(byId("slack-standup-digest"))).toBe(true); | ||
| }); | ||
|
|
||
| it("treats automations without GitHub/Slack as non-responders", () => { | ||
| expect( | ||
| isResponderAutomation({ requiredIntegrationIds: ["tavily", "notion"] }), | ||
| ).toBe(false); | ||
| expect(isResponderAutomation({ requiredIntegrationIds: ["linear"] })).toBe( | ||
| false, | ||
| ); | ||
| expect(isResponderAutomation({ requiredIntegrationIds: [] })).toBe(false); | ||
| }); | ||
|
|
||
| it("flags an automation that requires Slack alongside other integrations", () => { | ||
| expect( | ||
| isResponderAutomation({ | ||
| requiredIntegrationIds: ["slack", "linear", "notion"], | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("exposes the github/slack responder integration ids", () => { | ||
| expect(RESPONDER_INTEGRATION_IDS).toEqual(["github", "slack"]); | ||
| }); | ||
| }); |
177 changes: 177 additions & 0 deletions
177
src/components/features/automations/deployment-choice-modal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| import { type ReactNode } from "react"; | ||
| import { Trans, useTranslation } from "react-i18next"; | ||
| import { Cloud, Laptop } from "lucide-react"; | ||
| import OpenHandsLogo from "#/assets/branding/openhands-logo.svg?react"; | ||
| 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 { | ||
| MODAL_MAX_WIDTH_VIEWPORT, | ||
| modalWidthClassName, | ||
| } from "#/components/shared/modals/modal-body"; | ||
| import { formControlButtonClassName } from "#/utils/form-control-classes"; | ||
| import { | ||
| OPENHANDS_CLOUD_INTEGRATIONS_URL, | ||
| OPENHANDS_SELF_HOSTED_DOCS_URL, | ||
| } from "#/utils/constants"; | ||
| import { useAutomationPreferencesStore } from "#/stores/automation-preferences-store"; | ||
| import { I18nKey } from "#/i18n/declaration"; | ||
| import { cn } from "#/utils/utils"; | ||
|
|
||
| interface DeploymentChoiceModalProps { | ||
| /** Proceed with the existing local automation setup flow. */ | ||
| onContinueLocal: () => void; | ||
| /** Dismiss the modal without launching (also called after the cloud link). */ | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| const CHOICE_CARD_CLASSNAME = | ||
| "flex flex-1 flex-col gap-3 rounded-xl border border-[var(--oh-border)] p-4"; | ||
|
|
||
| /** Inline docs link used inside the {@link Trans} description. */ | ||
| function SelfHostDocsLink({ children }: { children?: ReactNode }) { | ||
| return ( | ||
| <a | ||
| href={OPENHANDS_SELF_HOSTED_DOCS_URL} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| data-testid="deployment-choice-description-self-hosted" | ||
| className="text-white hover:opacity-80" | ||
| > | ||
| {children} | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Explains the two runtime options for an event-driven GitHub / Slack | ||
| * "responder" automation before the user invests time configuring it: | ||
| * | ||
| * - Poll locally: keeps everything on the user's machine, but only runs while | ||
| * the laptop is awake and Agent Canvas is running. | ||
| * - OpenHands Cloud: keeps responding even when the laptop is closed. | ||
| * | ||
| * Today this is only surfaced for the **local** backend (the recommended | ||
| * automations launcher is local-only). The component is intentionally generic | ||
| * so the future Local / User Cloud / OpenHands Cloud switch (issue #868) can | ||
| * reuse it without re-templating the copy. | ||
| */ | ||
| export function DeploymentChoiceModal({ | ||
| onContinueLocal, | ||
| onClose, | ||
| }: DeploymentChoiceModalProps) { | ||
| const { t } = useTranslation("openhands"); | ||
| const hideResponderDeploymentChoice = useAutomationPreferencesStore( | ||
| (state) => state.hideResponderDeploymentChoice, | ||
| ); | ||
| const setHideResponderDeploymentChoice = useAutomationPreferencesStore( | ||
| (state) => state.setHideResponderDeploymentChoice, | ||
| ); | ||
|
|
||
| return ( | ||
| <ModalBackdrop | ||
| onClose={onClose} | ||
| aria-label={t(I18nKey.DEPLOYMENT_CHOICE$TITLE)} | ||
| > | ||
| <div | ||
| data-testid="deployment-choice-modal" | ||
| className={cn( | ||
| "relative rounded-xl border border-[var(--oh-border)] bg-base-secondary", | ||
| modalWidthClassName("xl"), | ||
| MODAL_MAX_WIDTH_VIEWPORT, | ||
| )} | ||
| > | ||
| <ModalCloseButton | ||
| onClose={onClose} | ||
| testId="deployment-choice-modal-close" | ||
| /> | ||
|
|
||
| <header className="px-6 pb-2 pr-12 pt-6"> | ||
| <h2 | ||
| id="deployment-choice-modal-title" | ||
| className="text-lg font-medium text-white" | ||
| > | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$TITLE)} | ||
| </h2> | ||
| <p className="mt-2 text-sm leading-relaxed text-tertiary-light"> | ||
| <Trans | ||
| ns="openhands" | ||
| i18nKey={I18nKey.DEPLOYMENT_CHOICE$DESCRIPTION} | ||
| components={{ docs: <SelfHostDocsLink /> }} | ||
| /> | ||
| </p> | ||
| </header> | ||
|
|
||
| <div className="flex flex-col gap-4 px-6 pb-6 pt-2 sm:flex-row"> | ||
| {/* Left: poll locally */} | ||
| <div className={CHOICE_CARD_CLASSNAME}> | ||
| <div className="flex items-center gap-2 text-white"> | ||
| <Laptop size={18} className="shrink-0" /> | ||
| <h3 className="text-sm font-medium"> | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$LOCAL_TITLE)} | ||
| </h3> | ||
| </div> | ||
| <p className="flex-1 text-xs leading-relaxed text-tertiary-light"> | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$LOCAL_DESCRIPTION)} | ||
| </p> | ||
| <BrandButton | ||
| type="button" | ||
| variant="secondary" | ||
| testId="deployment-choice-local" | ||
| className="w-full" | ||
| onClick={onContinueLocal} | ||
| > | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$LOCAL_ACTION)} | ||
| </BrandButton> | ||
| </div> | ||
|
|
||
| {/* Right: OpenHands Cloud */} | ||
| <div className={CHOICE_CARD_CLASSNAME}> | ||
| <div className="flex items-center gap-2 text-white"> | ||
| <Cloud size={18} className="shrink-0" /> | ||
| <h3 className="text-sm font-medium"> | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$CLOUD_TITLE)} | ||
| </h3> | ||
| </div> | ||
| <p className="flex-1 text-xs leading-relaxed text-tertiary-light"> | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$CLOUD_DESCRIPTION)} | ||
| </p> | ||
| <a | ||
| href={OPENHANDS_CLOUD_INTEGRATIONS_URL} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| data-testid="deployment-choice-cloud" | ||
| onClick={onClose} | ||
| className={cn( | ||
| formControlButtonClassName, | ||
| "w-full bg-white text-[#0d0f11] hover:opacity-90", | ||
| )} | ||
| > | ||
| <OpenHandsLogo | ||
| width={22} | ||
| height={15} | ||
| className="shrink-0 invert" | ||
| aria-hidden | ||
| /> | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$CLOUD_ACTION)} | ||
| </a> | ||
| </div> | ||
| </div> | ||
|
|
||
| <footer className="flex items-center border-t border-[var(--oh-border)] px-6 py-3"> | ||
| <label className="flex cursor-pointer items-center gap-2 text-xs text-tertiary-light"> | ||
| <input | ||
| type="checkbox" | ||
| data-testid="deployment-choice-dont-show-again" | ||
| checked={hideResponderDeploymentChoice} | ||
| onChange={(event) => | ||
| setHideResponderDeploymentChoice(event.target.checked) | ||
| } | ||
| /> | ||
| {t(I18nKey.DEPLOYMENT_CHOICE$DONT_SHOW_AGAIN)} | ||
| </label> | ||
| </footer> | ||
| </div> | ||
| </ModalBackdrop> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid calling
useAutomationPreferencesStorehere directly by passing a getter & setter (dontShowAgainandonDontShowAgainChange) as props fromRecommendedAutomationsLauncher.RecommendedAutomationsLauncheralready reads from the store, so adding the setter selector there and passing both values down would keep the modal purely presentational. And tests should no longer need a global store reset inbeforeEach.deployment-choice-modal.tsxrecommended-automations-launcher.tsx