Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(desktop): add debug tool to simplify investigating workspace import related issues #1587

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions desktop/src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ class Client {
}
}

// emitEvent publishes to a given channel and invokes the corresponding handler.
// This is only intended to be used for debugging right now.
public emitEvent<T extends TChannelName>(e: TChannels[T]) {
event.emit("event", e)
}

public fetchPlatform(): TPlatform {
return os.platform()
}
Expand Down
112 changes: 87 additions & 25 deletions desktop/src/components/Layout/StatusBar.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { CheckIcon, StarIcon } from "@chakra-ui/icons"
import {
BoxProps,
Button,
Checkbox,
HStack,
Icon,
IconButton,
Input,
Menu,
MenuButton,
MenuItem,
MenuList,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalHeader,
ModalOverlay,
Text,
Tooltip,
useColorModeValue,
useDisclosure,
} from "@chakra-ui/react"
import { useMemo } from "react"
import { useMemo, useRef } from "react"
import { FaBug } from "react-icons/fa"
import { HiDocumentMagnifyingGlass, HiMagnifyingGlassPlus } from "react-icons/hi2"
import { client } from "../../client"
Expand Down Expand Up @@ -133,7 +142,9 @@ function OSSReportIssue() {
}

function DebugMenu() {
const inputRef = useRef<HTMLInputElement>(null)
const debug = useDebug()
const { isOpen, onClose, onOpen: openModal } = useDisclosure()

if (!debug.isEnabled) {
return null
Expand All @@ -145,31 +156,82 @@ function DebugMenu() {
e.stopPropagation()
}

const handleImportLinkClicked = () => {
const rawLink = inputRef.current?.value
if (!rawLink) {
return
}
const url = new URL(rawLink.replace(/#/g, "?"))
const workspaceUID = url.searchParams.get("workspace-uid")
const workspaceID = url.searchParams.get("workspace-id")
const host = url.searchParams.get("devpod-pro-host")
const project = url.searchParams.get("project")
if (!workspaceUID || !workspaceID || !host || !project) {
console.error(
"Some parameters are missing for import",
url,
Array.from(url.searchParams.entries())
)

return
}
client.emitEvent({
type: "ImportWorkspace",
workspace_uid: workspaceUID,
workspace_id: workspaceID,
devpod_pro_host: host,
project,
options: {},
})
onClose()
}

return (
<Menu>
<MenuButton>Debug</MenuButton>
<MenuList>
<MenuItem onClick={handleMenuItemClicked("commands")}>
<Checkbox isChecked={debug.options.commands} />
<Text paddingLeft="4">Print command logs</Text>
</MenuItem>
<MenuItem onClick={handleMenuItemClicked("actions")}>
<Checkbox isChecked={debug.options.actions} />
<Text paddingLeft="4">Print action logs</Text>
</MenuItem>
<MenuItem onClick={handleMenuItemClicked("workspaces")}>
<Checkbox isChecked={debug.options.workspaces} />
<Text paddingLeft="4">Print workspace logs</Text>
</MenuItem>
<MenuItem
onClick={(e) => {
client.openDir("AppData")
e.stopPropagation()
}}>
<Text paddingLeft="4">Open app_dir</Text>
</MenuItem>
</MenuList>
</Menu>
<>
<Menu>
<MenuButton>Debug</MenuButton>
<MenuList>
<MenuItem onClick={handleMenuItemClicked("commands")}>
<Checkbox isChecked={debug.options.commands} />
<Text paddingLeft="4">Print command logs</Text>
</MenuItem>
<MenuItem onClick={handleMenuItemClicked("actions")}>
<Checkbox isChecked={debug.options.actions} />
<Text paddingLeft="4">Print action logs</Text>
</MenuItem>
<MenuItem onClick={handleMenuItemClicked("workspaces")}>
<Checkbox isChecked={debug.options.workspaces} />
<Text paddingLeft="4">Print workspace logs</Text>
</MenuItem>
<MenuItem
onClick={(e) => {
client.openDir("AppData")
e.stopPropagation()
}}>
<Text paddingLeft="4">Open app_dir</Text>
</MenuItem>
<MenuItem
onClick={(e) => {
openModal()
e.stopPropagation()
}}>
<Text paddingLeft="4">Open import tool</Text>
</MenuItem>
</MenuList>
</Menu>
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalCloseButton />
<ModalHeader>Import workspace</ModalHeader>
<ModalBody pb="8">
<Text mb="4">Paste a platform import link here</Text>
<Input mb="4" ref={inputRef} type="text" />
<Button onClick={handleImportLinkClicked}>Import</Button>
</ModalBody>
</ModalContent>
</Modal>
</>
)
}

Expand Down
9 changes: 9 additions & 0 deletions desktop/src/images/codium_insiders.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading