OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
feat: Sync dialog redesign (#1703)
Mike Fortman2e580695363c
diff --git a/frontend/.gitignore b/frontend/.gitignoreindex ca1877118..effa71abb 100644--- a/frontend/.gitignore+++ b/frontend/.gitignore@@ -42,3 +42,6 @@ next-env.d.tsplaywright-reporttest-results++# local-only dev component previews+app/dev/diff --git a/frontend/components/sync-confirm-dialog.tsx b/frontend/components/sync-confirm-dialog.tsxindex 4d1b76308..b3124d65b 100644--- a/frontend/components/sync-confirm-dialog.tsx+++ b/frontend/components/sync-confirm-dialog.tsx@@ -1,9 +1,9 @@"use client";-import { AlertTriangle, RefreshCw } from "lucide-react";+import { AlertTriangle, Check, Loader2, RefreshCw, Trash2 } from "lucide-react";import type React from "react";import type { OrphanFile } from "@/app/api/mutations/useSyncConnector";-import { Badge } from "./ui/badge";+import { Alert, AlertDescription, AlertTitle } from "./ui/alert";import { Button } from "./ui/button";import {Dialog,@@ -27,6 +27,13 @@ const CONNECTOR_DISPLAY_NAMES: Record<string, string> = {const formatConnectorLabel = (type: string): string =>CONNECTOR_DISPLAY_NAMES[type] ?? type;+const pluralize = (n: number, singular: string, plural?: string): string =>+ `${n} ${n === 1 ? singular : (plural ?? `${singular}s`)}`;++/** Rough row-count above which the deletes ScrollArea (max-h-60 ≈ 240px) will+ * overflow and the user needs a scroll affordance. */+const SCROLL_HINT_THRESHOLD = 8;+interface SyncConfirmDialogProps {open: boolean;onOpenChange: (open: boolean) => void;@@ -35,16 +42,17 @@ interface SyncConfirmDialogProps {isLoading?: boolean;/** True after Confirm is clicked, while the actual sync request runs. */isSyncing?: boolean;- /** Single-connector mode: the orphan list for this connector. */+ /** Single-connector mode: deleted-at-source files for this connector.+ * "Orphans" = documents indexed locally that no longer exist at the source. */orphans?: OrphanFile[];- /** Sync-all mode: orphans grouped by connector_type. */+ /** Sync-all mode: orphans (deletions) grouped by connector_type. */orphansByType?: Record<string, OrphanFile[]>;/** Per-connector availability flag — false means orphan detection couldn't* complete safely (e.g. unauthenticated connection). */orphansAvailableByType?: Record<string, boolean>;- /** Single-connector mode: total files about to be re-synced. */+ /** Single-connector mode: total files that will be updated. */syncedCount?: number;- /** Sync-all mode: per-connector synced counts. */+ /** Sync-all mode: per-connector update counts. */syncedCountByType?: Record<string, number>;/** Single-connector mode: connector type for the title (e.g. "sharepoint"). */connectorType?: string;@@ -52,6 +60,189 @@ interface SyncConfirmDialogProps {isSyncAll?: boolean;}+interface NormalizedData {+ /** Deletions grouped by connector_type (single-mode collapses to one entry). */+ orphansByType: Record<string, OrphanFile[]>;+ /** Update counts grouped by connector_type. */+ updatesByType: Record<string, number>;+ /** Connectors whose orphan detection couldn't complete. */+ unavailableConnectors: string[];+ totalOrphans: number;+ totalUpdates: number;+}++const normalize = (+ props: Pick<+ SyncConfirmDialogProps,+ | "orphans"+ | "orphansByType"+ | "orphansAvailableByType"+ | "syncedCount"+ | "syncedCountByType"+ | "connectorType"+ | "isSyncAll"+ >,+): NormalizedData => {+ const {+ orphans,+ orphansByType,+ orphansAvailableByType,+ syncedCount,+ syncedCountByType,+ connectorType,+ isSyncAll,+ } = props;++ const normalizedOrphans: Record<string, OrphanFile[]> = isSyncAll+ ? Object.fromEntries(+ Object.entries(orphansByType ?? {}).filter(+ ([, list]) => list.length > 0,+ ),+ )+ : orphans && orphans.length > 0 && connectorType+ ? { [connectorType]: orphans }+ : {};++ const normalizedUpdates: Record<string, number> = isSyncAll+ ? Object.fromEntries(+ Object.entries(syncedCountByType ?? {}).filter(([, n]) => n > 0),+ )+ : syncedCount && syncedCount > 0 && connectorType+ ? { [connectorType]: syncedCount }+ : {};++ const unavailableConnectors = Object.entries(orphansAvailableByType ?? {})+ .filter(([, available]) => !available)+ .map(([type]) => type);++ const totalOrphans = Object.values(normalizedOrphans).reduce(+ (sum, list) => sum + list.length,+ 0,+ );+ const totalUpdates = Object.values(normalizedUpdates).reduce(+ (sum, n) => sum + n,+ 0,+ );++ return {+ orphansByType: normalizedOrphans,+ updatesByType: normalizedUpdates,+ unavailableConnectors,+ totalOrphans,+ totalUpdates,+ };+};++const DeletesAlert: React.FC<{+ orphansByType: Record<string, OrphanFile[]>;+ totalOrphans: number;+ isSyncAll: boolean;+}> = ({ orphansByType, totalOrphans, isSyncAll }) => {+ const renderList = (list: OrphanFile[]) => (+ <ul className="space-y-1 text-sm">+ {list.map((o) => (+ <li+ key={o.document_id}+ className="truncate"+ title={o.filename || o.document_id}+ >+ {o.filename || o.document_id}+ </li>+ ))}+ </ul>+ );++ const entries = Object.entries(orphansByType);++ return (+ <div className="space-y-1.5">+ <div className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">+ Removing+ </div>+ <Alert variant="destructive" className="bg-[#271919] text-[#ffced0]">+ <AlertTriangle className="size-5" />+ <AlertTitle>+ {pluralize(totalOrphans, "file")} will be deleted+ </AlertTitle>+ <AlertDescription className="col-start-2 block min-w-0 !text-[#ffced0]">+ <p>These files no longer exist at the source.</p>+ <ScrollArea className="mt-2 max-h-60 w-full">+ {isSyncAll ? (+ <div className="space-y-3 pr-2">+ {entries.map(([type, list], index) => (+ <div key={type}>+ <div className="text-xs font-semibold uppercase tracking-wide mb-1">+ {formatConnectorLabel(type)} ({list.length})+ </div>+ {renderList(list)}+ {index < entries.length - 1 ? (+ <Separator className="mt-3" />+ ) : null}+ </div>+ ))}+ </div>+ ) : (+ <div className="pr-2">{renderList(entries[0]?.[1] ?? [])}</div>+ )}+ </ScrollArea>+ {totalOrphans > SCROLL_HINT_THRESHOLD ? (+ <p className="mt-2 text-xs italic opacity-80">+ Scroll to review all {totalOrphans} files.+ </p>+ ) : null}+ </AlertDescription>+ </Alert>+ </div>+ );+};++const UnavailableAlert: React.FC<{ connectors: string[] }> = ({+ connectors,+}) => (+ <Alert>+ <AlertTriangle className="size-5" />+ <AlertTitle>Couldn't check for deletions</AlertTitle>+ <AlertDescription className="col-start-2 block min-w-0 [text-wrap:pretty]">+ <p>+ Files may be removed at the source without warning. Re-authenticate the+ affected connection and try again to see a full preview.+ </p>+ <ul className="mt-2 space-y-0.5">+ {connectors.map((type) => (+ <li key={type}>· {formatConnectorLabel(type)}</li>+ ))}+ </ul>+ </AlertDescription>+ </Alert>+);++const UpdatesAlert: React.FC<{+ updatesByType: Record<string, number>;+ totalUpdates: number;+ isSyncAll: boolean;+}> = ({ updatesByType, totalUpdates, isSyncAll }) => {+ const entries = Object.entries(updatesByType);++ return (+ <Alert>+ <RefreshCw className="size-5" />+ <AlertTitle>{pluralize(totalUpdates, "file")} will be updated</AlertTitle>+ {isSyncAll && entries.length > 1 ? (+ <AlertDescription className="col-start-2 block min-w-0">+ <ul className="mt-1 space-y-0.5">+ {entries.map(([type, count]) => (+ <li key={type} className="flex justify-between gap-4">+ <span>{formatConnectorLabel(type)}</span>+ <span className="tabular-nums">{count}</span>+ </li>+ ))}+ </ul>+ </AlertDescription>+ ) : null}+ </Alert>+ );+};+export const SyncConfirmDialog: React.FC<SyncConfirmDialogProps> = ({open,onOpenChange,@@ -71,18 +262,27 @@ export const SyncConfirmDialog: React.FC<SyncConfirmDialogProps> = ({onOpenChange(false);};- const totalOrphans = isSyncAll- ? Object.values(orphansByType ?? {}).reduce(- (sum, list) => sum + list.length,- 0,- )- : (orphans?.length ?? 0);+ const data = normalize({+ orphans,+ orphansByType,+ orphansAvailableByType,+ syncedCount,+ syncedCountByType,+ connectorType,+ isSyncAll,+ });- const totalSynced = isSyncAll- ? Object.values(syncedCountByType ?? {}).reduce((sum, n) => sum + n, 0)- : (syncedCount ?? 0);+ const {+ orphansByType: normOrphans,+ updatesByType,+ unavailableConnectors,+ totalOrphans,+ totalUpdates,+ } = data;- const hasOrphans = totalOrphans > 0;+ const hasDeletes = totalOrphans > 0;+ const hasUnavailable = unavailableConnectors.length > 0;+ const hasUpdates = totalUpdates > 0;const busy = isLoading || isSyncing;const title = isSyncAll ? "Sync all connectors" : "Confirm sync";@@ -90,112 +290,77 @@ export const SyncConfirmDialog: React.FC<SyncConfirmDialogProps> = ({let description: React.ReactNode;if (isLoading) {description = "Checking what will change…";- } else if (hasOrphans) {- description = (- <>- <span className="font-medium text-foreground">- {totalOrphans} {totalOrphans === 1 ? "file" : "files"}- </span>{" "}- will be removed from your knowledge base because they no longer exist at- the source. {totalSynced} {totalSynced === 1 ? "file" : "files"} will be- re-synced. This can't be undone.- </>- );+ } else if (hasDeletes) {+ description = `Sync will remove ${pluralize(totalOrphans, "file")}.`;+ } else if (hasUnavailable) {+ description = "Some connectors couldn't be checked for deletions.";} else {- description = (- <>- {totalSynced} {totalSynced === 1 ? "file" : "files"} will be re-synced.- No files will be deleted.- </>- );+ description = `Sync will update ${pluralize(totalUpdates, "file")}.`;}- const renderOrphanList = (list: OrphanFile[]) => (- <ul className="space-y-1 text-sm">- {list.map((o) => (- <li- key={o.document_id}- className="truncate text-muted-foreground"- title={o.filename || o.document_id}- >- {o.filename || o.document_id}- </li>- ))}- </ul>- );+ // CTA variant + copy follows the most-severe state present.+ let ctaVariant: "destructive" | "warning" | "default" = "default";+ let ctaCopy = "Confirm sync";+ if (hasDeletes) {+ ctaVariant = "destructive";+ ctaCopy = "Delete & sync";+ } else if (hasUnavailable) {+ ctaVariant = "warning";+ ctaCopy = "Sync anyway";+ }return (<Dialog open={open} onOpenChange={onOpenChange}><DialogContent className="sm:max-w-[560px]"><DialogHeader>- <div className="flex items-center justify-between gap-2">- <DialogTitle>- {title}- {!isSyncAll && connectorType ? (- <span className="text-muted-foreground font-normal">- {" "}- · {formatConnectorLabel(connectorType)}- </span>- ) : null}- </DialogTitle>- {hasOrphans ? (- <Badge- variant="secondary"- className="bg-accent-amber-foreground/15 text-accent-amber-foreground"- >- {totalOrphans} will be deleted- </Badge>+ <DialogTitle>+ {title}+ {!isSyncAll && connectorType ? (+ <span className="text-muted-foreground font-normal">+ {" "}+ · {formatConnectorLabel(connectorType)}+ </span>) : null}- </div>+ </DialogTitle><DialogDescription className="pt-2 text-muted-foreground">{description}</DialogDescription></DialogHeader>- {hasOrphans ? (- <div className="rounded-md border border-accent-amber-foreground/30 bg-accent-amber-foreground/5 p-3">- <div className="flex items-center gap-2 mb-2 text-sm font-medium text-accent-amber-foreground">- <AlertTriangle className="h-4 w-4" />- Files to be deleted- </div>- <ScrollArea className="max-h-60">- {isSyncAll ? (- <div className="space-y-3 pr-2">- {Object.entries(orphansByType ?? {})- .filter(([, list]) => list.length > 0)- .map(([type, list], index, arr) => (- <div key={type}>- <div className="text-xs font-semibold uppercase tracking-wide text-muted-foreground mb-1">- {formatConnectorLabel(type)} ({list.length})- </div>- {renderOrphanList(list)}- {index < arr.length - 1 ? (- <Separator className="mt-3" />- ) : null}- </div>- ))}- </div>- ) : (- <div className="pr-2">{renderOrphanList(orphans ?? [])}</div>- )}- </ScrollArea>+ {isLoading ? (+ <div className="flex items-center justify-center py-8">+ <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />+ </div>+ ) : (+ <div className="space-y-3">+ {/* Deletes — destructive, most prominent */}+ {hasDeletes ? (+ <DeletesAlert+ orphansByType={normOrphans}+ totalOrphans={totalOrphans}+ isSyncAll={isSyncAll}+ />+ ) : null}++ {/* Unavailable — destructive, surfaces unknown-deletion risk */}+ {hasUnavailable ? (+ <UnavailableAlert connectors={unavailableConnectors} />+ ) : null}++ {/* TODO: Renames section — requires backend support to detect+ renames as a distinct category. Insert between Unavailable+ and Updates when the preview endpoint returns rename data. */}++ {/* Updates — informational, count only */}+ {hasUpdates ? (+ <UpdatesAlert+ updatesByType={updatesByType}+ totalUpdates={totalUpdates}+ isSyncAll={isSyncAll}+ />+ ) : null}</div>- ) : null}-- {/* Surface "couldn't determine deletions" when strict gating aborted. */}- {isSyncAll && orphansAvailableByType- ? Object.entries(orphansAvailableByType)- .filter(([, available]) => !available)- .map(([type]) => (- <div- key={type}- className="text-xs text-muted-foreground italic"- >- Couldn't determine deletions for {formatConnectorLabel(type)}{" "}- (a connection may need re-authentication).- </div>- ))- : null}+ )}<DialogFooter className="flex-row gap-2 justify-end"><Button@@ -209,18 +374,18 @@ export const SyncConfirmDialog: React.FC<SyncConfirmDialogProps> = ({</Button><Buttontype="button"- variant="default"+ variant={ctaVariant}size="sm"onClick={handleConfirm}disabled={busy}- className={- hasOrphans- ? "flex items-center gap-2 !bg-accent-amber-foreground hover:!bg-foreground text-primary-foreground"- : "flex items-center gap-2"- }+ loading={isSyncing}>- <RefreshCw className="h-3.5 w-3.5" />- {hasOrphans ? "Delete & sync" : "Confirm sync"}+ {ctaVariant === "destructive" ? (+ <Trash2 className="h-3.5 w-3.5" />+ ) : (+ <Check className="h-3.5 w-3.5" />+ )}+ {ctaCopy}</Button></DialogFooter></DialogContent>diff --git a/frontend/components/ui/alert.tsx b/frontend/components/ui/alert.tsxnew file mode 100644index 000000000..b414ceb80--- /dev/null+++ b/frontend/components/ui/alert.tsx@@ -0,0 +1,76 @@+import { cva, type VariantProps } from "class-variance-authority";+import * as React from "react";++import { cn } from "@/lib/utils";++const alertVariants = cva(+ "group/alert relative grid w-full gap-0.5 rounded-lg border px-2.5 py-2 text-left text-sm has-data-[slot=alert-action]:relative has-data-[slot=alert-action]:pr-18 has-[>svg]:grid-cols-[auto_1fr] has-[>svg]:gap-x-2 *:[svg]:row-span-2 *:[svg]:translate-y-0.5 *:[svg]:text-current *:[svg:not([class*='size-'])]:size-4",+ {+ variants: {+ variant: {+ default: "bg-card text-card-foreground",+ destructive:+ "bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 *:[svg]:text-current",+ },+ },+ defaultVariants: {+ variant: "default",+ },+ },+);++function Alert({+ className,+ variant,+ ...props+}: React.ComponentProps<"div"> & VariantProps<typeof alertVariants>) {+ return (+ <div+ data-slot="alert"+ role="alert"+ className={cn(alertVariants({ variant }), className)}+ {...props}+ />+ );+}++function AlertTitle({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="alert-title"+ className={cn(+ "font-medium group-has-[>svg]/alert:col-start-2 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground",+ className,+ )}+ {...props}+ />+ );+}++function AlertDescription({+ className,+ ...props+}: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="alert-description"+ className={cn(+ "text-sm text-balance text-muted-foreground md:text-pretty [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4",+ className,+ )}+ {...props}+ />+ );+}++function AlertAction({ className, ...props }: React.ComponentProps<"div">) {+ return (+ <div+ data-slot="alert-action"+ className={cn("absolute top-2 right-2", className)}+ {...props}+ />+ );+}++export { Alert, AlertTitle, AlertDescription, AlertAction };