|
| 1 | +/* |
| 2 | + * Copyright Contributors to the OpenCue Project |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +"use client"; |
| 18 | + |
| 19 | +import * as React from "react"; |
| 20 | +import { Copy, ExternalLink } from "lucide-react"; |
| 21 | + |
| 22 | +import { |
| 23 | + Dialog, |
| 24 | + DialogContent, |
| 25 | + DialogDescription, |
| 26 | + DialogFooter, |
| 27 | + DialogHeader, |
| 28 | + DialogTitle, |
| 29 | +} from "@/components/ui/dialog"; |
| 30 | +import { Button } from "@/components/ui/button"; |
| 31 | +import { useCuebotFacility } from "@/app/utils/use_cuebot_facility"; |
| 32 | +import { toastSuccess, toastWarning } from "@/app/utils/notify_utils"; |
| 33 | + |
| 34 | +/** |
| 35 | + * "About CueWeb" dialog - CueGUI parity (Help -> About in |
| 36 | + * `cuegui/cuegui/MainWindow.py`). Opened from the Help menu via the |
| 37 | + * `CUEWEB_OPEN_ABOUT_EVENT` CustomEvent and mounted once at the layout level. |
| 38 | + * |
| 39 | + * Shows the build version + Git SHA (build-time env), the active Cuebot |
| 40 | + * facility, the REST gateway URL (masked so it can be pasted into a bug report |
| 41 | + * without leaking the full internal host), the license, and credits. A |
| 42 | + * "Copy diagnostics" button copies all fields as JSON. |
| 43 | + */ |
| 44 | + |
| 45 | +export const CUEWEB_OPEN_ABOUT_EVENT = "cueweb:open-about"; |
| 46 | + |
| 47 | +const LICENSE_URL = |
| 48 | + "https://github.com/AcademySoftwareFoundation/OpenCue/blob/master/LICENSE"; |
| 49 | +const OPENCUE_URL = "https://www.opencue.io/"; |
| 50 | + |
| 51 | +/** |
| 52 | + * Mask a gateway URL for display: keep the scheme + port and the first/last |
| 53 | + * couple of host characters, replacing the middle with asterisks. Drops any |
| 54 | + * path / query / userinfo. Falls back to a coarse mask for non-URL strings. |
| 55 | + */ |
| 56 | +function maskGatewayUrl(raw: string | undefined): string { |
| 57 | + const value = (raw ?? "").trim(); |
| 58 | + if (!value) return "(not configured)"; |
| 59 | + try { |
| 60 | + const u = new URL(value); |
| 61 | + const host = u.hostname; |
| 62 | + const masked = |
| 63 | + host.length <= 4 |
| 64 | + ? "*".repeat(host.length || 4) |
| 65 | + : `${host.slice(0, 2)}${"*".repeat(Math.max(3, host.length - 4))}${host.slice(-2)}`; |
| 66 | + const port = u.port ? `:${u.port}` : ""; |
| 67 | + return `${u.protocol}//${masked}${port}`; |
| 68 | + } catch { |
| 69 | + return value.length <= 6 ? "******" : `${value.slice(0, 3)}***${value.slice(-3)}`; |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +function Field({ label, value, mono = false }: { label: string; value: React.ReactNode; mono?: boolean }) { |
| 74 | + return ( |
| 75 | + <div className="grid grid-cols-[8rem_1fr] items-start gap-2 py-1 text-sm"> |
| 76 | + <dt className="text-muted-foreground">{label}</dt> |
| 77 | + <dd className={mono ? "break-all font-mono text-xs" : "break-words"}>{value}</dd> |
| 78 | + </div> |
| 79 | + ); |
| 80 | +} |
| 81 | + |
| 82 | +export function AboutDialog() { |
| 83 | + const [open, setOpen] = React.useState(false); |
| 84 | + const { facility } = useCuebotFacility(); |
| 85 | + |
| 86 | + React.useEffect(() => { |
| 87 | + const handler = () => setOpen(true); |
| 88 | + window.addEventListener(CUEWEB_OPEN_ABOUT_EVENT, handler); |
| 89 | + return () => window.removeEventListener(CUEWEB_OPEN_ABOUT_EVENT, handler); |
| 90 | + }, []); |
| 91 | + |
| 92 | + const version = |
| 93 | + process.env.NEXT_PUBLIC_APP_VERSION && process.env.NEXT_PUBLIC_APP_VERSION.length > 0 |
| 94 | + ? process.env.NEXT_PUBLIC_APP_VERSION |
| 95 | + : "dev"; |
| 96 | + const gitSha = |
| 97 | + process.env.NEXT_PUBLIC_GIT_SHA && process.env.NEXT_PUBLIC_GIT_SHA.length > 0 |
| 98 | + ? process.env.NEXT_PUBLIC_GIT_SHA |
| 99 | + : "unknown"; |
| 100 | + const maskedGateway = maskGatewayUrl(process.env.NEXT_PUBLIC_OPENCUE_ENDPOINT); |
| 101 | + |
| 102 | + async function copyDiagnostics() { |
| 103 | + const payload = { |
| 104 | + product: "CueWeb", |
| 105 | + version, |
| 106 | + gitSha, |
| 107 | + facility, |
| 108 | + restGateway: maskedGateway, |
| 109 | + userAgent: typeof navigator !== "undefined" ? navigator.userAgent : "", |
| 110 | + generatedAt: new Date().toISOString(), |
| 111 | + }; |
| 112 | + const text = JSON.stringify(payload, null, 2); |
| 113 | + try { |
| 114 | + await navigator.clipboard.writeText(text); |
| 115 | + toastSuccess("Diagnostics copied to clipboard."); |
| 116 | + } catch { |
| 117 | + toastWarning("Could not copy to clipboard."); |
| 118 | + } |
| 119 | + } |
| 120 | + |
| 121 | + return ( |
| 122 | + <Dialog open={open} onOpenChange={setOpen}> |
| 123 | + <DialogContent className="sm:max-w-lg"> |
| 124 | + <DialogHeader> |
| 125 | + <DialogTitle>About CueWeb</DialogTitle> |
| 126 | + <DialogDescription> |
| 127 | + The web-based interface for OpenCue. |
| 128 | + </DialogDescription> |
| 129 | + </DialogHeader> |
| 130 | + |
| 131 | + <dl className="divide-y divide-border"> |
| 132 | + <Field label="Version" value={version} mono /> |
| 133 | + <Field label="Build SHA" value={gitSha} mono /> |
| 134 | + <Field label="Cuebot facility" value={<span className="uppercase">{facility}</span>} /> |
| 135 | + <Field label="REST gateway" value={maskedGateway} mono /> |
| 136 | + <Field |
| 137 | + label="License" |
| 138 | + value={ |
| 139 | + <a |
| 140 | + href={LICENSE_URL} |
| 141 | + target="_blank" |
| 142 | + rel="noopener noreferrer" |
| 143 | + className="inline-flex items-center gap-1 text-primary hover:underline" |
| 144 | + > |
| 145 | + Apache License 2.0 |
| 146 | + <ExternalLink className="h-3 w-3" aria-hidden="true" /> |
| 147 | + </a> |
| 148 | + } |
| 149 | + /> |
| 150 | + <Field |
| 151 | + label="Credits" |
| 152 | + value={ |
| 153 | + <span> |
| 154 | + OpenCue is an open source project hosted by the{" "} |
| 155 | + <a |
| 156 | + href="https://www.aswf.io/" |
| 157 | + target="_blank" |
| 158 | + rel="noopener noreferrer" |
| 159 | + className="text-primary hover:underline" |
| 160 | + > |
| 161 | + Academy Software Foundation |
| 162 | + </a> |
| 163 | + . Learn more at{" "} |
| 164 | + <a |
| 165 | + href={OPENCUE_URL} |
| 166 | + target="_blank" |
| 167 | + rel="noopener noreferrer" |
| 168 | + className="text-primary hover:underline" |
| 169 | + > |
| 170 | + opencue.io |
| 171 | + </a> |
| 172 | + . |
| 173 | + </span> |
| 174 | + } |
| 175 | + /> |
| 176 | + </dl> |
| 177 | + |
| 178 | + <DialogFooter className="gap-2 sm:justify-between"> |
| 179 | + <Button type="button" variant="outline" size="sm" onClick={copyDiagnostics}> |
| 180 | + <Copy className="mr-2 h-4 w-4" aria-hidden="true" /> |
| 181 | + Copy diagnostics |
| 182 | + </Button> |
| 183 | + <Button type="button" size="sm" onClick={() => setOpen(false)}> |
| 184 | + Close |
| 185 | + </Button> |
| 186 | + </DialogFooter> |
| 187 | + </DialogContent> |
| 188 | + </Dialog> |
| 189 | + ); |
| 190 | +} |
0 commit comments