-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
enclave-manager/web/packages/app/src/emui/enclaves/components/modals/TerminalAccessModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
Button, | ||
useDisclosure, | ||
Text, | ||
Box, | ||
IconButton, | ||
CloseButton, | ||
} from '@chakra-ui/react'; | ||
import { CopyIcon } from '@chakra-ui/icons'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
const TerminalAccessModal: React.FC = () => { | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const [uniqueId, setUniqueId] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
setUniqueId(uuidv4()); | ||
} | ||
}, [isOpen]); | ||
|
||
const codeSnippets = [ | ||
'brew install kurtosis', | ||
`kurtosis terminal ${uniqueId}` | ||
]; | ||
|
||
const handleCopy = (snippet: string): void => { | ||
navigator.clipboard.writeText(snippet) | ||
.then(() => console.log('Code copied to clipboard!')) | ||
.catch(err => console.error('Failed to copy: ', err)); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button size={"xs"} variant={"ghost"} | ||
onClick={onOpen}> | ||
Terminal | ||
</Button> | ||
|
||
<Modal isOpen={isOpen} onClose={onClose} size="xl" isCentered> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Setup service access</ModalHeader> | ||
<CloseButton position="absolute" right="8px" top="8px" onClick={onClose} /> | ||
<ModalBody> | ||
<Text>Follow the steps below access the running service:</Text> | ||
{codeSnippets.map((snippet, index) => ( | ||
<Box key={index} as="pre" p="4" background="gray.500" my="2" position="relative" overflowY="auto"> | ||
{snippet} | ||
<IconButton | ||
aria-label="Copy code" | ||
icon={<CopyIcon />} | ||
size="sm" | ||
position="absolute" | ||
right="1" | ||
top="1" | ||
onClick={() => handleCopy(snippet)} | ||
/> | ||
</Box> | ||
))} | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default TerminalAccessModal; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters