Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface SyncRepositoryDialogProps {
params: RegistryRepositoriesSyncRegistryRepositoryData
) => Promise<tracecat__registry__repositories__schemas__RegistrySyncResponse>
syncRepoIsPending: boolean
force?: boolean
}

export function SyncRepositoryDialog({
Expand All @@ -37,7 +38,15 @@ export function SyncRepositoryDialog({
setSelectedRepo,
syncRepo,
syncRepoIsPending,
force = false,
}: SyncRepositoryDialogProps) {
let actionLabel = "Sync"
if (syncRepoIsPending) {
actionLabel = "Syncing..."
} else if (force) {
actionLabel = "Force sync"
}

const handleSync = async () => {
if (!selectedRepo) {
console.error("No repository selected")
Expand All @@ -59,7 +68,10 @@ export function SyncRepositoryDialog({
</span>
),
})
await syncRepo({ repositoryId: selectedRepo.id })
await syncRepo({
repositoryId: selectedRepo.id,
requestBody: { force },
})
toast({
title: "Successfully synced repository",
description: (
Expand All @@ -82,12 +94,20 @@ export function SyncRepositoryDialog({
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent className="max-w-2xl">
<AlertDialogHeader>
<AlertDialogTitle>Sync repository</AlertDialogTitle>
<AlertDialogTitle>
{force ? "Force sync repository" : "Sync repository"}
</AlertDialogTitle>
<AlertDialogDescription>
<span className="flex flex-col space-y-3">
<span>
You are about to pull the latest version of the repository.
</span>
{force ? (
<span className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
Force sync deletes the existing synced version before
reloading actions from the remote repository.
</span>
) : null}
<span className="max-w-full rounded-md border px-3 py-2 font-mono text-sm font-semibold tracking-tight text-foreground break-all whitespace-normal">
{selectedRepo?.origin}
</span>
Expand Down Expand Up @@ -121,7 +141,7 @@ export function SyncRepositoryDialog({
<RefreshCcw
className={`size-4 ${syncRepoIsPending ? "animate-spin" : ""}`}
/>
<span>{syncRepoIsPending ? "Syncing..." : "Sync"}</span>
<span>{actionLabel}</span>
</div>
</AlertDialogAction>
</AlertDialogFooter>
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/components/registry/workspace-actions-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { toast } from "@/components/ui/use-toast"
import { useRegistryRepositories } from "@/lib/hooks"
import { copyToClipboard } from "@/lib/utils"

type ActiveDialog = "sync" | "commit" | "versions" | null
type ActiveDialog = "sync" | "force-sync" | "commit" | "versions" | null

function RegistryActionsControlsMenu() {
const canUpdateRegistry = useScopeCheck("org:registry:update") === true
Expand Down Expand Up @@ -134,6 +134,15 @@ function RegistryActionsControlsMenu() {
</DropdownMenuItem>
) : null}

{showRegistryActions ? (
<DropdownMenuItem
onSelect={() => handleOpenDialog("force-sync")}
Comment thread
daryllimyt marked this conversation as resolved.
>
<RefreshCcw className="mr-2 size-4" />
<span>Force sync from remote</span>
</DropdownMenuItem>
) : null}

{showRegistryActions ? (
<DropdownMenuItem onSelect={() => handleOpenDialog("commit")}>
<GitBranchIcon className="mr-2 size-4" />
Expand All @@ -160,7 +169,7 @@ function RegistryActionsControlsMenu() {
</DropdownMenu>

<SyncRepositoryDialog
open={activeDialog === "sync"}
open={activeDialog === "sync" || activeDialog === "force-sync"}
onOpenChange={(open) => {
if (!open) {
setActiveDialog(null)
Expand All @@ -170,6 +179,7 @@ function RegistryActionsControlsMenu() {
setSelectedRepo={setSelectedRepo}
syncRepo={syncRepo}
syncRepoIsPending={syncRepoIsPending}
force={activeDialog === "force-sync"}
/>

<CommitSelectorDialog
Expand Down
Loading