|
| 1 | +import { ReactElement } from 'react' |
| 2 | + |
| 3 | +import LoadingIndicator from '../utils/LoadingIndicator' |
| 4 | +import { EmptyListMessage } from '../overview/clusters/misc' |
| 5 | +import { Cluster, useRepositoryQuery } from '../../generated/graphql' |
| 6 | + |
| 7 | +import { GqlError } from '../utils/Alert' |
| 8 | +import { useNavigate, useParams } from 'react-router-dom' |
| 9 | +import { useTheme } from 'styled-components' |
| 10 | +import { |
| 11 | + IconFrame, |
| 12 | + Flex, |
| 13 | + Card, |
| 14 | + Chip, |
| 15 | + GearTrainIcon, |
| 16 | + Button, |
| 17 | + ArrowTopRightIcon, |
| 18 | +} from '@pluralsh/design-system' |
| 19 | +import { Body1BoldP } from '../utils/Typography' |
| 20 | +import { ensureURLValidity } from '../../utils/url' |
| 21 | +import { ignoreEvent } from '../../utils/ignore-event' |
| 22 | + |
| 23 | +const CONSOLE_APP_NAME = 'console' |
| 24 | + |
| 25 | +type ClusterAppsProps = { cluster: Cluster } |
| 26 | + |
| 27 | +export function ClusterConsole({ |
| 28 | + cluster: { consoleUrl }, |
| 29 | +}: ClusterAppsProps): ReactElement { |
| 30 | + const theme = useTheme() |
| 31 | + const navigate = useNavigate() |
| 32 | + const { clusterId } = useParams() |
| 33 | + const { data, loading, error } = useRepositoryQuery({ |
| 34 | + variables: { name: CONSOLE_APP_NAME }, |
| 35 | + }) |
| 36 | + const console = data?.repository |
| 37 | + const url = ensureURLValidity(consoleUrl) |
| 38 | + |
| 39 | + if (error) |
| 40 | + return ( |
| 41 | + <GqlError |
| 42 | + header="Could not fetch console details" |
| 43 | + error={error} |
| 44 | + /> |
| 45 | + ) |
| 46 | + |
| 47 | + if (!data && loading) return <LoadingIndicator /> |
| 48 | + |
| 49 | + if (!console) |
| 50 | + return ( |
| 51 | + <EmptyListMessage> |
| 52 | + Looks like you haven't installed your first app yet. |
| 53 | + </EmptyListMessage> |
| 54 | + ) |
| 55 | + |
| 56 | + return ( |
| 57 | + <Card |
| 58 | + clickable={!!url} |
| 59 | + onClick={(e) => { |
| 60 | + ignoreEvent(e) |
| 61 | + if (url) window.open(url, '_blank', 'noopener noreferrer') |
| 62 | + }} |
| 63 | + alignItems="center" |
| 64 | + display="flex" |
| 65 | + gap="medium" |
| 66 | + padding="small" |
| 67 | + > |
| 68 | + <IconFrame |
| 69 | + icon={ |
| 70 | + <img |
| 71 | + src={console.darkIcon || console.icon || ''} |
| 72 | + width={32} |
| 73 | + height={32} |
| 74 | + /> |
| 75 | + } |
| 76 | + size="large" |
| 77 | + type="floating" |
| 78 | + /> |
| 79 | + <Body1BoldP>{console.name}</Body1BoldP> |
| 80 | + <Chip |
| 81 | + severity={console.installation?.synced ? 'success' : 'warning'} |
| 82 | + size={'small'} |
| 83 | + > |
| 84 | + {console.installation?.synced ? 'Synced' : 'Pending Sync'} |
| 85 | + </Chip> |
| 86 | + {console.installation?.locked && <Chip>Locked</Chip>} |
| 87 | + <Flex grow={1} /> |
| 88 | + <Button |
| 89 | + floating |
| 90 | + small |
| 91 | + startIcon={<GearTrainIcon />} |
| 92 | + onClick={(e) => { |
| 93 | + ignoreEvent(e) |
| 94 | + navigate(`/apps/${clusterId}/${console.name}`) |
| 95 | + }} |
| 96 | + > |
| 97 | + Settings |
| 98 | + </Button> |
| 99 | + {url && ( |
| 100 | + <Button |
| 101 | + endIcon={<ArrowTopRightIcon size={14} />} |
| 102 | + small |
| 103 | + onClick={(e) => { |
| 104 | + ignoreEvent(e) |
| 105 | + window.open(url, '_blank', 'noopener noreferrer') |
| 106 | + }} |
| 107 | + > |
| 108 | + Launch |
| 109 | + </Button> |
| 110 | + )} |
| 111 | + </Card> |
| 112 | + ) |
| 113 | +} |
0 commit comments