File size: 4,346 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 | import React from "react";
import { createPortal } from "react-dom";
import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
import {
getEnvironmentSwitchSnapshot,
subscribeEnvironmentSwitch,
} from "./environment-switch-store";
// Re-export the store API so existing call sites and tests that import from
// this module keep working unchanged.
export {
ENVIRONMENT_SWITCH_DURATION_MS,
ENVIRONMENT_SWITCH_SETACTIVE_DELAY_MS,
triggerEnvironmentSwitch,
dismissEnvironmentSwitch,
__resetEnvironmentSwitchOverlayForTests,
} from "./environment-switch-store";
function EnvironmentSwitchIcon({ className }: { className?: string }) {
return (
<svg
viewBox="0 0 74.17 22"
xmlns="http://www.w3.org/2000/svg"
className={className}
aria-hidden
>
<g>
<rect
x="1"
y="1"
width="20"
height="8"
rx="2"
ry="2"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
/>
<rect
x="1"
y="13"
width="20"
height="8"
rx="2"
ry="2"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
/>
<line
x1="5"
y1="5"
x2="5.01"
y2="5"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
/>
<line
x1="5"
y1="17"
x2="5.01"
y2="17"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
/>
</g>
<g>
<rect
x="53.17"
y="1"
width="20"
height="8"
rx="2"
ry="2"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
/>
<rect
x="53.17"
y="13"
width="20"
height="8"
rx="2"
ry="2"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
/>
<line
x1="57.17"
y1="5"
x2="57.18"
y2="5"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
/>
<line
x1="57.17"
y1="17"
x2="57.18"
y2="17"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
/>
</g>
<g>
<path
d="M43.09,7l4,4-4,4"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M27.09,11h20"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M31.09,7l-4,4,4,4"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</g>
</svg>
);
}
export function EnvironmentSwitchOverlay() {
const { t } = useTranslation("openhands");
const { visible, target } = React.useSyncExternalStore(
subscribeEnvironmentSwitch,
getEnvironmentSwitchSnapshot,
getEnvironmentSwitchSnapshot,
);
if (!visible || typeof document === "undefined") return null;
return createPortal(
<div
data-testid="environment-switch-overlay"
data-target={target}
className="environment-switch-overlay pointer-events-none fixed inset-0 z-[2147483646] flex items-center justify-center"
aria-live="polite"
aria-atomic="true"
>
<div className="pointer-events-none flex min-w-[280px] max-w-[420px] flex-col items-center gap-2 rounded-xl border border-[var(--oh-border)] bg-[var(--oh-surface)] px-5 py-4 text-[var(--oh-foreground)] shadow-2xl">
<EnvironmentSwitchIcon className="mb-2 h-6 w-20 shrink-0 text-[var(--oh-foreground)]" />
<p className="text-center text-sm font-medium">
{t(I18nKey.BACKEND$SWITCHING_TO, { environment: target })}
</p>
</div>
</div>,
document.body,
);
}
// React.lazy() expects a default export.
export default EnvironmentSwitchOverlay;
|