|
1 | 1 | import type { WorkspaceApp } from "api/typesGenerated";
|
| 2 | +import { Button } from "components/Button/Button"; |
| 3 | +import { |
| 4 | + DropdownMenu, |
| 5 | + DropdownMenuContent, |
| 6 | + DropdownMenuItem, |
| 7 | + DropdownMenuTrigger, |
| 8 | +} from "components/DropdownMenu/DropdownMenu"; |
| 9 | +import { EllipsisVertical, ExternalLinkIcon, HouseIcon } from "lucide-react"; |
2 | 10 | import { useAppLink } from "modules/apps/useAppLink";
|
3 | 11 | import type { Task } from "modules/tasks/tasks";
|
4 |
| -import type { FC } from "react"; |
| 12 | +import { type FC, useRef } from "react"; |
| 13 | +import { Link as RouterLink } from "react-router-dom"; |
5 | 14 | import { cn } from "utils/cn";
|
6 | 15 |
|
7 | 16 | type TaskAppIFrameProps = {
|
@@ -31,24 +40,69 @@ export const TaskAppIFrame: FC<TaskAppIFrameProps> = ({
|
31 | 40 | workspace: task.workspace,
|
32 | 41 | });
|
33 | 42 |
|
34 |
| - let href = link.href; |
35 |
| - try { |
36 |
| - const url = new URL(link.href); |
37 |
| - if (pathname) { |
38 |
| - url.pathname = pathname; |
| 43 | + const appHref = (): string => { |
| 44 | + try { |
| 45 | + const url = new URL(link.href, location.href); |
| 46 | + if (pathname) { |
| 47 | + url.pathname = pathname; |
| 48 | + } |
| 49 | + return url.toString(); |
| 50 | + } catch (err) { |
| 51 | + console.warn(`Failed to parse URL ${link.href} for app ${app.id}`, err); |
| 52 | + return link.href; |
39 | 53 | }
|
40 |
| - href = url.toString(); |
41 |
| - } catch (err) { |
42 |
| - console.warn(`Failed to parse URL ${link.href} for app ${app.id}`, err); |
43 |
| - } |
| 54 | + }; |
| 55 | + |
| 56 | + const frameRef = useRef<HTMLIFrameElement>(null); |
| 57 | + const frameSrc = appHref(); |
44 | 58 |
|
45 | 59 | return (
|
46 |
| - <iframe |
47 |
| - src={href} |
48 |
| - title={link.label} |
49 |
| - loading="eager" |
50 |
| - className={cn([active ? "block" : "hidden", "w-full h-full border-0"])} |
51 |
| - allow="clipboard-read; clipboard-write" |
52 |
| - /> |
| 60 | + <div className={cn([active ? "flex" : "hidden", "w-full h-full flex-col"])}> |
| 61 | + <div className="bg-surface-tertiary flex items-center p-2 py-1 gap-1"> |
| 62 | + <Button |
| 63 | + size="icon" |
| 64 | + variant="subtle" |
| 65 | + onClick={(e) => { |
| 66 | + e.preventDefault(); |
| 67 | + if (frameRef.current?.contentWindow) { |
| 68 | + frameRef.current.contentWindow.location.href = appHref(); |
| 69 | + } |
| 70 | + }} |
| 71 | + > |
| 72 | + <HouseIcon /> |
| 73 | + <span className="sr-only">Home</span> |
| 74 | + </Button> |
| 75 | + |
| 76 | + {/* Possibly we will put a URL bar here, but for now we cannot due to |
| 77 | + * cross-origin restrictions in iframes. */} |
| 78 | + <div className="w-full"></div> |
| 79 | + |
| 80 | + <DropdownMenu> |
| 81 | + <DropdownMenuTrigger asChild> |
| 82 | + <Button size="icon" variant="subtle" aria-label="More options"> |
| 83 | + <EllipsisVertical aria-hidden="true" /> |
| 84 | + <span className="sr-only">More options</span> |
| 85 | + </Button> |
| 86 | + </DropdownMenuTrigger> |
| 87 | + <DropdownMenuContent align="end"> |
| 88 | + <DropdownMenuItem asChild> |
| 89 | + <RouterLink to={frameSrc} target="_blank"> |
| 90 | + <ExternalLinkIcon /> |
| 91 | + Open app in new tab |
| 92 | + </RouterLink> |
| 93 | + </DropdownMenuItem> |
| 94 | + </DropdownMenuContent> |
| 95 | + </DropdownMenu> |
| 96 | + </div> |
| 97 | + |
| 98 | + <iframe |
| 99 | + ref={frameRef} |
| 100 | + src={frameSrc} |
| 101 | + title={link.label} |
| 102 | + loading="eager" |
| 103 | + className={"w-full h-full border-0"} |
| 104 | + allow="clipboard-read; clipboard-write" |
| 105 | + /> |
| 106 | + </div> |
53 | 107 | );
|
54 | 108 | };
|
0 commit comments