| 1 | import { |
| 2 | connectionStatusText, |
| 3 | type EnvironmentConnectionPresentation, |
| 4 | } from "@t3tools/client-runtime/connection"; |
| 5 | |
| 6 | export interface SavedCloudEnvironmentConnectionPresentation { |
| 7 | readonly buttonLabel: string; |
| 8 | readonly statusText: string; |
| 9 | readonly tone: "connected" | "connecting" | "error" | "idle"; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Present the live supervisor state for an environment that is already in the |
| 14 | * connection catalog. Catalog membership only means the environment is saved; |
| 15 | * it does not mean the connection attempt succeeded. |
| 16 | */ |
| 17 | export function presentSavedCloudEnvironmentConnection( |
| 18 | connection: EnvironmentConnectionPresentation, |
| 19 | ): SavedCloudEnvironmentConnectionPresentation { |
| 20 | switch (connection.phase) { |
| 21 | case "connected": |
| 22 | return { |
| 23 | buttonLabel: "Connected", |
| 24 | statusText: connectionStatusText(connection), |
| 25 | tone: "connected", |
| 26 | }; |
| 27 | case "connecting": |
| 28 | return { |
| 29 | buttonLabel: "Connecting…", |
| 30 | statusText: connectionStatusText(connection), |
| 31 | tone: "connecting", |
| 32 | }; |
| 33 | case "reconnecting": |
| 34 | return { |
| 35 | buttonLabel: "Reconnecting…", |
| 36 | statusText: connectionStatusText(connection), |
| 37 | tone: "connecting", |
| 38 | }; |
| 39 | // Not a failure: the machine is fine, this build just cannot talk to it. |
| 40 | case "unsupported": |
| 41 | return { |
| 42 | buttonLabel: "Client not supported", |
| 43 | statusText: connectionStatusText(connection), |
| 44 | tone: "idle", |
| 45 | }; |
| 46 | case "error": |
| 47 | return { |
| 48 | buttonLabel: "Connection failed", |
| 49 | statusText: connectionStatusText(connection), |
| 50 | tone: "error", |
| 51 | }; |
| 52 | case "offline": |
| 53 | return { |
| 54 | buttonLabel: "Offline", |
| 55 | statusText: connectionStatusText(connection), |
| 56 | tone: "idle", |
| 57 | }; |
| 58 | case "available": |
| 59 | return { |
| 60 | buttonLabel: "Not connected", |
| 61 | statusText: connectionStatusText(connection), |
| 62 | tone: "idle", |
| 63 | }; |
| 64 | } |
| 65 | } |