-
Notifications
You must be signed in to change notification settings - Fork 53
feat(code-review): add revert all local changes button #3352
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { useWorkspaceTRPC } from "@posthog/workspace-client/trpc"; | ||
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
| import { useCallback } from "react"; | ||
| import { showMessageBox } from "../../../utils/dialog"; | ||
| import { updateGitCacheFromSnapshot } from "../../git-interaction/utils/updateGitCache"; | ||
|
|
||
| export function useDiscardAllChanges(repoPath: string | undefined) { | ||
| const queryClient = useQueryClient(); | ||
| const trpc = useWorkspaceTRPC(); | ||
| const discardAllChanges = useMutation( | ||
| trpc.git.discardAllChanges.mutationOptions(), | ||
| ); | ||
|
|
||
| return useCallback(async () => { | ||
| if (!repoPath) return; | ||
|
|
||
| const dialogResult = await showMessageBox({ | ||
| type: "warning", | ||
| title: "Revert all local changes", | ||
| message: | ||
| "This will discard all uncommitted changes, including new files. A backup will be kept in a git stash.", | ||
| buttons: ["Cancel", "Revert All"], | ||
| defaultId: 1, | ||
| cancelId: 0, | ||
| }); | ||
|
|
||
| if (dialogResult.response !== 1) return; | ||
|
|
||
| const result = await discardAllChanges.mutateAsync({ | ||
| directoryPath: repoPath, | ||
| }); | ||
|
|
||
| if (result.state) { | ||
| updateGitCacheFromSnapshot(queryClient, repoPath, result.state); | ||
| } | ||
| }, [repoPath, queryClient, discardAllChanges]); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,7 @@ import { | |
| diffStatsInput, | ||
| diffStatsSchema, | ||
| directoryPathInput, | ||
| discardAllChangesInput, | ||
| discardFileChangesInput, | ||
| discardFileChangesOutput, | ||
| filePathInput, | ||
|
|
@@ -482,6 +483,13 @@ export function createAppRouter({ | |
| ), | ||
| ), | ||
|
|
||
| discardAllChanges: t.procedure | ||
| .input(discardAllChangesInput) | ||
| .output(discardFileChangesOutput) | ||
| .mutation(({ input }) => | ||
| gitService().discardAllChanges(input.directoryPath), | ||
|
Comment on lines
+489
to
+490
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new mutation takes Rule Used: When implementing new features, ensure that owners... (source) Learned From |
||
| ), | ||
|
|
||
| push: t.procedure | ||
| .input(pushInput) | ||
| .output(pushOutput) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
discardAllChanges.mutateAsyncrejects after the user confirms, this async click handler lets the error escape without showing any failure message. The local diff can stay unchanged while the user gets no clear indication that the revert did not happen.Rule Used: Always wrap asynchronous calls that may fail, such... (source)
Learned From
PostHog/posthog#32098