forked from loft-sh/devpod
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added troubleshoot menu options in desktop
Signed-off-by: Thomas Kosiewski <[email protected]>
- Loading branch information
1 parent
fba226c
commit 77b2ad4
Showing
13 changed files
with
211 additions
and
31 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -77,5 +77,6 @@ | |
}, | ||
"resolutions": { | ||
"lodash": "4.17.21" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
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
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
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
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,73 @@ | ||
import { client } from "@/client" | ||
import { TActionObj } from "@/contexts/DevPodContext/action" | ||
import { TWorkspace } from "@/types" | ||
import { useToast } from "@chakra-ui/react" | ||
import { useMutation } from "@tanstack/react-query" | ||
import { ProWorkspaceInstance } from "@/contexts" | ||
|
||
export function useStoreTroubleshoot() { | ||
const toast = useToast() | ||
const { mutate, isLoading: isStoring } = useMutation({ | ||
mutationFn: async ({ | ||
workspace, | ||
workspaceActions, | ||
}: { | ||
workspace: TWorkspace | ProWorkspaceInstance | ||
workspaceActions: TActionObj[] | ||
}) => { | ||
const logFiles = await Promise.all( | ||
workspaceActions.map((action) => client.workspaces.getActionLogFile(action.id)) | ||
) | ||
|
||
const targetFolder = await client.selectFromDir("Save Troubleshooting Data") | ||
|
||
// user cancelled "save file" dialog | ||
if (targetFolder === null) { | ||
return | ||
} | ||
|
||
const unwrappedLogFiles = logFiles | ||
.filter((f) => f.ok) | ||
.map((f) => f.unwrap() ?? "") | ||
.map((f) => [[f], [targetFolder, f.split("/").pop() ?? ""]]) | ||
// poor mans zip | ||
await Promise.all( | ||
unwrappedLogFiles.map(([src, target]) => client.copyFilePaths(src ?? [], target ?? [])) | ||
) | ||
|
||
await client.writeTextFile( | ||
[targetFolder, "workspace_actions.json"], | ||
JSON.stringify(workspaceActions, null, 2) | ||
) | ||
|
||
await client.writeTextFile( | ||
[targetFolder, "workspace.json"], | ||
JSON.stringify(workspace, null, 2) | ||
) | ||
|
||
const troubleshootOutput = await client.workspaces.troubleshoot({ | ||
id: workspace.id, | ||
actionID: "", | ||
streamID: "", | ||
}) | ||
if (troubleshootOutput.ok) { | ||
await client.writeTextFile( | ||
[targetFolder, "cli_troubleshoot.json"], | ||
troubleshootOutput.unwrap().stdout | ||
) | ||
} | ||
|
||
client.open(targetFolder) | ||
}, | ||
onError(error) { | ||
toast({ | ||
title: `Failed to save logs: ${error}`, | ||
status: "error", | ||
isClosable: true, | ||
duration: 30_000, // 30 sec | ||
}) | ||
}, | ||
}) | ||
|
||
return { store: mutate, isStoring } | ||
} |
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
Oops, something went wrong.