|
1 |
| -import { Card, CardBody, Button, Text } from "@stacklok/ui-kit"; |
| 1 | +import { |
| 2 | + Card, |
| 3 | + CardBody, |
| 4 | + Button, |
| 5 | + Text, |
| 6 | + TooltipTrigger, |
| 7 | + Tooltip, |
| 8 | + TooltipInfoButton, |
| 9 | +} from "@stacklok/ui-kit"; |
2 | 10 | import { twMerge } from "tailwind-merge";
|
3 | 11 | import { useRestoreWorkspaceButton } from "../hooks/use-restore-workspace-button";
|
4 | 12 | import { useArchiveWorkspaceButton } from "../hooks/use-archive-workspace-button";
|
5 | 13 | import { useConfirmHardDeleteWorkspace } from "../hooks/use-confirm-hard-delete-workspace";
|
6 | 14 | import { useNavigate } from "react-router-dom";
|
7 | 15 | import { hrefs } from "@/lib/hrefs";
|
| 16 | +import { useActiveWorkspaceName } from "../hooks/use-active-workspace-name"; |
| 17 | + |
| 18 | +function getContextualText({ |
| 19 | + activeWorkspaceName, |
| 20 | + workspaceName, |
| 21 | +}: { |
| 22 | + workspaceName: string; |
| 23 | + activeWorkspaceName: string; |
| 24 | +}) { |
| 25 | + if (workspaceName === activeWorkspaceName) { |
| 26 | + return "Cannot archive the active workspace"; |
| 27 | + } |
| 28 | + if (workspaceName === "default") { |
| 29 | + return "Cannot archive the default workspace"; |
| 30 | + } |
| 31 | + return null; |
| 32 | +} |
| 33 | + |
| 34 | +// NOTE: You can't show a tooltip on a disabled button |
| 35 | +// React Aria's recommended approach is https://spectrum.adobe.com/page/contextual-help/ |
| 36 | +function ContextualHelp({ workspaceName }: { workspaceName: string }) { |
| 37 | + const { data: activeWorkspaceName } = useActiveWorkspaceName(); |
| 38 | + if (!activeWorkspaceName) return null; |
| 39 | + |
| 40 | + const text = getContextualText({ activeWorkspaceName, workspaceName }); |
| 41 | + if (!text) return null; |
| 42 | + |
| 43 | + return ( |
| 44 | + <TooltipTrigger delay={0}> |
| 45 | + <TooltipInfoButton aria-label="Contextual help" /> |
| 46 | + <Tooltip>{text}</Tooltip> |
| 47 | + </TooltipTrigger> |
| 48 | + ); |
| 49 | +} |
8 | 50 |
|
9 | 51 | const ButtonsUnarchived = ({ workspaceName }: { workspaceName: string }) => {
|
10 | 52 | const archiveButtonProps = useArchiveWorkspaceButton({ workspaceName });
|
11 | 53 |
|
12 |
| - return <Button {...archiveButtonProps} />; |
| 54 | + return ( |
| 55 | + <div className="flex gap-2 items-center"> |
| 56 | + <Button {...archiveButtonProps} /> |
| 57 | + <ContextualHelp workspaceName={workspaceName} /> |
| 58 | + </div> |
| 59 | + ); |
13 | 60 | };
|
14 | 61 |
|
15 | 62 | const ButtonsArchived = ({ workspaceName }: { workspaceName: string }) => {
|
@@ -51,7 +98,7 @@ export function ArchiveWorkspace({
|
51 | 98 | <CardBody className="flex justify-between items-center">
|
52 | 99 | <div>
|
53 | 100 | <Text className="text-primary">Archive Workspace</Text>
|
54 |
| - <Text className="flex items-center text-secondary mb-0"> |
| 101 | + <Text className="flex items-center text-secondary mb-0 text-balance"> |
55 | 102 | Archiving this workspace removes it from the main workspaces list,
|
56 | 103 | though it can be restored if needed.
|
57 | 104 | </Text>
|
|
0 commit comments