-
Notifications
You must be signed in to change notification settings - Fork 22
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
1 parent
38bf4b9
commit c57b264
Showing
8 changed files
with
169 additions
and
131 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
frontend/app/src/entities/branches/api/rebase-branch-from-api.ts
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,44 @@ | ||
import graphqlClient from "@/shared/api/graphql/graphqlClientApollo"; | ||
import { gql } from "@apollo/client"; | ||
|
||
export const BRANCH_REBASE = gql` | ||
mutation BRANCH_REBASE($name: String, $waitForCompletion: Boolean!) { | ||
BranchRebase ( | ||
wait_until_completion: $waitForCompletion | ||
data: { | ||
name: $name | ||
} | ||
) { | ||
ok | ||
object { | ||
id | ||
name | ||
description | ||
origin_branch | ||
branched_from | ||
created_at | ||
sync_with_git | ||
is_default | ||
has_schema_changes | ||
} | ||
task { | ||
id | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export type RebaseBranchFromApiParams = { | ||
branchName: string; | ||
waitForCompletion: boolean; | ||
}; | ||
|
||
export const rebaseBranchFromApi = ({ | ||
branchName, | ||
waitForCompletion, | ||
}: RebaseBranchFromApiParams) => { | ||
return graphqlClient.mutate({ | ||
mutation: BRANCH_REBASE, | ||
variables: { name: branchName, waitForCompletion }, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
frontend/app/src/entities/branches/domain/rebase-branch.ts
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,31 @@ | ||
import { rebaseBranchFromApi } from "@/entities/branches/api/rebase-branch-from-api"; | ||
import { Branch } from "@/shared/api/graphql/generated/graphql"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
|
||
export type RebaseBranchParams = { | ||
branchName: string; | ||
waitForCompletion?: boolean; | ||
}; | ||
|
||
export type RebaseBranch = (params: RebaseBranchParams) => Promise<{ | ||
branch: Branch; | ||
relatedTaskId: string | null; | ||
}>; | ||
|
||
export const rebaseBranch: RebaseBranch = async ({ | ||
branchName, | ||
waitForCompletion = true, | ||
}: RebaseBranchParams) => { | ||
const { data } = await rebaseBranchFromApi({ branchName, waitForCompletion }); | ||
|
||
return { | ||
branch: data.BranchRebase.object, | ||
relatedTaskId: data.BranchRebase.task?.id ?? null, | ||
}; | ||
}; | ||
|
||
export const useRebaseBranch = () => { | ||
return useMutation({ | ||
mutationFn: rebaseBranch, | ||
}); | ||
}; |
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
3 changes: 3 additions & 0 deletions
3
frontend/app/src/entities/diff/domain/update-diff.mutation.ts
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { updateDiff } from "@/entities/diff/domain/update-diff"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
|
||
export const UPDATE_DIFF_KEY = "update-diff"; | ||
|
||
export function useUpdateDiffMutation() { | ||
return useMutation({ | ||
mutationKey: [UPDATE_DIFF_KEY], | ||
mutationFn: (branchName: string) => updateDiff(branchName), | ||
}); | ||
} |
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,39 @@ | ||
import { useRebaseBranch } from "@/entities/branches/domain/rebase-branch"; | ||
import { useUpdateDiffMutation } from "@/entities/diff/domain/update-diff.mutation"; | ||
import { Button, ButtonProps } from "@/shared/components/buttons/button-primitive"; | ||
import { ALERT_TYPES, Alert } from "@/shared/components/ui/alert"; | ||
import { toast } from "react-toastify"; | ||
|
||
export interface DiffRebaseButtonProps extends ButtonProps { | ||
branchName: string; | ||
} | ||
|
||
export function DiffRebaseButton({ branchName, ...props }: DiffRebaseButtonProps) { | ||
const updateDiffMutation = useUpdateDiffMutation(); | ||
const rebaseBranchMutation = useRebaseBranch(); | ||
|
||
const handleRebase = async () => { | ||
try { | ||
await rebaseBranchMutation.mutateAsync({ branchName }); | ||
toast(<Alert type={ALERT_TYPES.SUCCESS} message="Branch rebased!" />); | ||
await updateDiffMutation.mutateAsync(branchName); | ||
} catch (error: unknown) { | ||
if (error instanceof Error) { | ||
toast(<Alert type={ALERT_TYPES.ERROR} message={error.message} />); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
size="sm" | ||
variant="primary-outline" | ||
onClick={handleRebase} | ||
isLoading={rebaseBranchMutation.isPending} | ||
disabled={rebaseBranchMutation.isPending} | ||
{...props} | ||
> | ||
Rebase | ||
</Button> | ||
); | ||
} |
Oops, something went wrong.