|
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{EllipsisVertical,ExternalLinkIcon,HouseIcon}from"lucide-react"; |
2 | 10 | import{useAppLink}from"modules/apps/useAppLink";
|
3 | 11 | importtype{Task}from"modules/tasks/tasks";
|
4 |
| -importtype{FC}from"react"; |
| 12 | +import{typeFC,useRef}from"react"; |
| 13 | +import{LinkasRouterLink}from"react-router-dom"; |
5 | 14 | import{cn}from"utils/cn";
|
6 | 15 |
|
7 | 16 | typeTaskAppIFrameProps={
|
@@ -31,24 +40,69 @@ export const TaskAppIFrame: FC<TaskAppIFrameProps> = ({
|
31 | 40 | workspace:task.workspace,
|
32 | 41 | });
|
33 | 42 |
|
34 |
| -lethref=link.href; |
35 |
| -try{ |
36 |
| -consturl=newURL(link.href); |
37 |
| -if(pathname){ |
38 |
| -url.pathname=pathname; |
| 43 | +constappHref=():string=>{ |
| 44 | +try{ |
| 45 | +consturl=newURL(link.href,location.href); |
| 46 | +if(pathname){ |
| 47 | +url.pathname=pathname; |
| 48 | +} |
| 49 | +returnurl.toString(); |
| 50 | +}catch(err){ |
| 51 | +console.warn(`Failed to parse URL${link.href} for app${app.id}`,err); |
| 52 | +returnlink.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 | +constframeRef=useRef<HTMLIFrameElement>(null); |
| 57 | +constframeSrc=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 | +<divclassName={cn([active ?"flex" :"hidden","w-full h-full flex-col"])}> |
| 61 | +<divclassName="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 | +<spanclassName="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 | +<divclassName="w-full"></div> |
| 79 | + |
| 80 | +<DropdownMenu> |
| 81 | +<DropdownMenuTriggerasChild> |
| 82 | +<Buttonsize="icon"variant="subtle"aria-label="More options"> |
| 83 | +<EllipsisVerticalaria-hidden="true"/> |
| 84 | +<spanclassName="sr-only">More options</span> |
| 85 | +</Button> |
| 86 | +</DropdownMenuTrigger> |
| 87 | +<DropdownMenuContentalign="end"> |
| 88 | +<DropdownMenuItemasChild> |
| 89 | +<RouterLinkto={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 | };
|