|
1 | 1 | importtype{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{ |
| 10 | +EllipsisVertical, |
| 11 | +ExternalLinkIcon, |
| 12 | +HouseIcon, |
| 13 | +RotateCwIcon, |
| 14 | +}from"lucide-react"; |
| 15 | +import{openAppInNewWindow}from"modules/apps/apps"; |
2 | 16 | import{useAppLink}from"modules/apps/useAppLink";
|
3 | 17 | importtype{Task}from"modules/tasks/tasks";
|
4 |
| -importtype{FC}from"react"; |
| 18 | +import{typeFC,useRef}from"react"; |
5 | 19 | import{cn}from"utils/cn";
|
6 | 20 |
|
7 | 21 | typeTaskAppIFrameProps={
|
@@ -31,24 +45,85 @@ export const TaskAppIFrame: FC<TaskAppIFrameProps> = ({
|
31 | 45 | workspace:task.workspace,
|
32 | 46 | });
|
33 | 47 |
|
34 |
| -lethref=link.href; |
35 |
| -try{ |
36 |
| -consturl=newURL(link.href); |
37 |
| -if(pathname){ |
38 |
| -url.pathname=pathname; |
| 48 | +constappHref=():string=>{ |
| 49 | +try{ |
| 50 | +consturl=newURL(link.href,location.href); |
| 51 | +if(pathname){ |
| 52 | +url.pathname=pathname; |
| 53 | +} |
| 54 | +returnurl.toString(); |
| 55 | +}catch(err){ |
| 56 | +console.warn(`Failed to parse URL${link.href} for app${app.id}`,err); |
| 57 | +returnlink.href; |
39 | 58 | }
|
40 |
| -href=url.toString(); |
41 |
| -}catch(err){ |
42 |
| -console.warn(`Failed to parse URL${link.href} for app${app.id}`,err); |
43 |
| -} |
| 59 | +}; |
| 60 | + |
| 61 | +constframeRef=useRef<HTMLIFrameElement>(null); |
| 62 | +constframeSrc=appHref(); |
44 | 63 |
|
45 | 64 | 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 |
| -/> |
| 65 | +<divclassName={cn([active ?"flex" :"hidden","w-full h-full flex-col"])}> |
| 66 | +<divclassName="bg-surface-tertiary flex items-center p-2 py-1 gap-1"> |
| 67 | +<Button |
| 68 | +size="icon" |
| 69 | +variant="subtle" |
| 70 | +onClick={(e)=>{ |
| 71 | +e.preventDefault(); |
| 72 | +if(frameRef.current?.contentWindow){ |
| 73 | +frameRef.current.contentWindow.location.reload(); |
| 74 | +} |
| 75 | +}} |
| 76 | +> |
| 77 | +<RotateCwIcon/> |
| 78 | +<spanclassName="sr-only">Refresh</span> |
| 79 | +</Button> |
| 80 | + |
| 81 | +<Button |
| 82 | +size="icon" |
| 83 | +variant="subtle" |
| 84 | +onClick={(e)=>{ |
| 85 | +e.preventDefault(); |
| 86 | +if(frameRef.current?.contentWindow){ |
| 87 | +frameRef.current.contentWindow.location.href=appHref(); |
| 88 | +} |
| 89 | +}} |
| 90 | +> |
| 91 | +<HouseIcon/> |
| 92 | +<spanclassName="sr-only">Home</span> |
| 93 | +</Button> |
| 94 | + |
| 95 | +{/* Possibly we will put a URL bar here, but for now we cannot due to |
| 96 | + * cross-origin restrictions in iframes. */} |
| 97 | +<divclassName="w-full"></div> |
| 98 | + |
| 99 | +<DropdownMenu> |
| 100 | +<DropdownMenuTriggerasChild> |
| 101 | +<Buttonsize="icon"variant="subtle"aria-label="More options"> |
| 102 | +<EllipsisVerticalaria-hidden="true"/> |
| 103 | +<spanclassName="sr-only">More options</span> |
| 104 | +</Button> |
| 105 | +</DropdownMenuTrigger> |
| 106 | +<DropdownMenuContentalign="end"> |
| 107 | +<DropdownMenuItem |
| 108 | +onClick={()=>{ |
| 109 | +openAppInNewWindow(frameSrc); |
| 110 | +}} |
| 111 | +> |
| 112 | +<ExternalLinkIcon/> |
| 113 | +Open app in new tab |
| 114 | +</DropdownMenuItem> |
| 115 | +</DropdownMenuContent> |
| 116 | +</DropdownMenu> |
| 117 | +</div> |
| 118 | + |
| 119 | +<iframe |
| 120 | +ref={frameRef} |
| 121 | +src={frameSrc} |
| 122 | +title={link.label} |
| 123 | +loading="eager" |
| 124 | +className={"w-full h-full border-0"} |
| 125 | +allow="clipboard-read; clipboard-write" |
| 126 | +/> |
| 127 | +</div> |
53 | 128 | );
|
54 | 129 | };
|