Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat(frontend): add diff components for secret version comparison
Victor Santos45a8083d1b57
diff --git a/frontend/src/components/secrets/diff/DiffContainer.tsx b/frontend/src/components/secrets/diff/DiffContainer.tsxnew file mode 100644index 0000000000..a8e1ca2d8f--- /dev/null+++ b/frontend/src/components/secrets/diff/DiffContainer.tsx@@ -0,0 +1,59 @@+import { useEffect } from "react";+import { twMerge } from "tailwind-merge";++import { scrollToFirstChange } from "@app/components/utilities/diff";++export interface DiffContainerProps {+ variant: "added" | "removed";+ children: React.ReactNode;+ containerRef?: React.RefObject<HTMLDivElement>;+ className?: string;+ isSingleLine?: boolean;+}++/**+ * Styled container with scroll-to-first-change behavior and consistent backgrounds+ */+export const DiffContainer = ({+ variant,+ children,+ containerRef,+ className,+ isSingleLine = false+}: DiffContainerProps) => {+ const backgroundColor = variant === "removed" ? "#120808" : "#081208";++ useEffect(() => {+ if (!isSingleLine && containerRef?.current) {+ const timeout = setTimeout(() => {+ scrollToFirstChange(containerRef.current);+ }, 100);+ return () => clearTimeout(timeout);+ }+ return undefined;+ }, [containerRef, isSingleLine]);++ if (isSingleLine) {+ return (+ <div+ className={twMerge("relative rounded-lg border border-mineshaft-600 p-2", className)}+ style={{ backgroundColor }}+ >+ {children}+ </div>+ );+ }++ return (+ <div+ ref={containerRef}+ className={twMerge(+ "relative max-h-96 thin-scrollbar overflow-x-auto overflow-y-auto rounded-lg border border-mineshaft-600 p-2",+ className+ )}+ style={{ backgroundColor }}+ >+ <div className="min-w-max">{children}</div>+ </div>+ );+};diff --git a/frontend/src/components/secrets/diff/FieldDiffRenderers.tsx b/frontend/src/components/secrets/diff/FieldDiffRenderers.tsxnew file mode 100644index 0000000000..583119bc5a--- /dev/null+++ b/frontend/src/components/secrets/diff/FieldDiffRenderers.tsx@@ -0,0 +1,210 @@+import { faKey } from "@fortawesome/free-solid-svg-icons";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { twMerge } from "tailwind-merge";++import { computeWordDiff } from "@app/components/utilities/diff";+import { Tag, Tooltip } from "@app/components/v2";++// Inline text diff renderer (for Key, Comment, Multi-line Encoding)+export const InlineTextDiff = ({+ oldText,+ newText,+ isOldVersion,+ hasChanges,+ preserveWhitespace = false,+ fontSize = "base"+}: {+ oldText: string;+ newText: string;+ isOldVersion: boolean;+ hasChanges: boolean;+ preserveWhitespace?: boolean;+ fontSize?: "sm" | "base";+}) => {+ const baseClass = preserveWhitespace ? "whitespace-pre-wrap" : "";+ const fontSizeClass = fontSize === "sm" ? "text-sm" : "text-base";++ if (!hasChanges) {+ return (+ <span className={twMerge(baseClass, fontSizeClass)}>{isOldVersion ? oldText : newText}</span>+ );+ }++ const changes = computeWordDiff(oldText, newText);++ // If no common words (null), highlight the entire text+ if (!changes) {+ const text = isOldVersion ? oldText : newText;+ const bgClass = isOldVersion ? "bg-red-600/40" : "bg-green-600/40";+ return (+ <span className={twMerge("rounded-sm px-0.5", baseClass, fontSizeClass, bgClass)}>+ {text}+ </span>+ );+ }++ return (+ <span className={twMerge(baseClass, fontSizeClass)}>+ {changes.map((change) => {+ let keyPrefix = "unchanged";+ if (change.added) keyPrefix = "add";+ else if (change.removed) keyPrefix = "rem";+ const key = `${keyPrefix}-${change.value}`;++ if (change.added && !isOldVersion) {+ return (+ <span key={key} className="rounded-sm bg-green-600/40 px-0.5">+ {change.value}+ </span>+ );+ }+ if (change.removed && isOldVersion) {+ return (+ <span key={key} className="rounded-sm bg-red-600/40 px-0.5">+ {change.value}+ </span>+ );+ }+ if (!change.added && !change.removed) {+ return <span key={key}>{change.value}</span>;+ }+ return null;+ })}+ </span>+ );+};++// Render tags with diff highlighting (string[] version - no color dots)+export const TagsDiffRenderer = ({+ tags,+ otherTags,+ isOldVersion+}: {+ tags?: Array<{ slug: string; color: string }>;+ otherTags?: Array<{ slug: string; color: string }>;+ isOldVersion: boolean;+}) => {+ if (!tags?.length) {+ return <span className="text-sm text-mineshaft-300">-</span>;+ }++ const otherTagSlugs = new Set(otherTags?.map((t) => t.slug) ?? []);++ return (+ <div className="flex flex-wrap gap-2">+ {tags.map(({ slug, color }) => {+ const isInOther = otherTagSlugs.has(slug);+ const isRemoved = isOldVersion && !isInOther;+ const isAdded = !isOldVersion && !isInOther;++ return (+ <Tag+ className={twMerge(+ "flex w-min items-center space-x-1.5 border bg-mineshaft-800",+ isRemoved && "border-red-500/60 bg-red-600/20",+ isAdded && "border-green-500/60 bg-green-600/20",+ !isRemoved && !isAdded && "border-mineshaft-500"+ )}+ key={slug}+ >+ {color && <div className="h-3 w-3 rounded-full" style={{ backgroundColor: color }} />}+ <div className="text-sm">{slug}</div>+ </Tag>+ );+ })}+ </div>+ );+};++// Render metadata with diff highlighting (granular key/value coloring)+export const MetadataDiffRenderer = ({+ metadata,+ otherMetadata,+ isOldVersion+}: {+ metadata?: Array<{ key: string; value: string }>;+ otherMetadata?: Array<{ key: string; value: string }>;+ isOldVersion: boolean;+}) => {+ if (!metadata?.length) {+ return <p className="text-sm text-mineshaft-300">-</p>;+ }++ const otherMetaByKey = new Map(otherMetadata?.map((m) => [m.key, m.value]) ?? []);+ const otherMetaByValue = new Map(otherMetadata?.map((m) => [m.value, m.key]) ?? []);++ return (+ <div className="mt-1 flex flex-wrap gap-2 text-sm text-mineshaft-300">+ {metadata.map((el) => {+ const keyExistsInOther = otherMetaByKey.has(el.key);+ const otherValueForKey = otherMetaByKey.get(el.key);++ const valueExistsWithDifferentKey =+ !keyExistsInOther &&+ otherMetaByValue.has(el.value) &&+ otherMetaByValue.get(el.value) !== el.key;++ const isEntirelyNew = !isOldVersion && !keyExistsInOther && !valueExistsWithDifferentKey;+ const isEntirelyRemoved = isOldVersion && !keyExistsInOther && !valueExistsWithDifferentKey;+ const isValueChanged = keyExistsInOther && otherValueForKey !== el.value;+ const isKeyRenamed = valueExistsWithDifferentKey;++ const keyHighlighted = isEntirelyNew || isEntirelyRemoved || isKeyRenamed;+ const valueHighlighted = isEntirelyNew || isEntirelyRemoved || isValueChanged;++ const hasAnyChange = keyHighlighted || valueHighlighted;+ const borderColorClass = isOldVersion ? "border-red-500/60" : "border-green-500/60";+ const borderClass = twMerge(+ "border",+ hasAnyChange && borderColorClass,+ !hasAnyChange && "border-mineshaft-500"+ );++ // Key: grey background with colored ring if changed+ const keyBgClass = twMerge(+ "bg-mineshaft-500",+ keyHighlighted &&+ (isOldVersion+ ? "ring-1 ring-red-500/60 ring-inset"+ : "ring-1 ring-green-500/60 ring-inset")+ );++ // Value: color background if changed+ const valueBgClass = twMerge(+ valueHighlighted && (isOldVersion ? "bg-red-600/30" : "bg-green-600/30"),+ !valueHighlighted && "bg-mineshaft-900"+ );++ return (+ <div key={el.key} className="flex items-center">+ <Tag+ size="xs"+ className={twMerge("mr-0 flex items-center rounded-r-none", borderClass, keyBgClass)}+ >+ <FontAwesomeIcon icon={faKey} size="xs" className="mr-1" />+ <Tooltip className="max-w-lg break-words whitespace-normal" content={el.key}>+ <div className="max-w-[125px] overflow-hidden text-ellipsis whitespace-nowrap">+ {el.key}+ </div>+ </Tooltip>+ </Tag>+ <Tag+ size="xs"+ className={twMerge(+ "flex items-center rounded-l-none pl-1",+ borderClass,+ valueBgClass+ )}+ >+ <Tooltip className="max-w-lg break-words whitespace-normal" content={el.value}>+ <div className="max-w-[125px] overflow-hidden text-ellipsis whitespace-nowrap">+ {el.value}+ </div>+ </Tooltip>+ </Tag>+ </div>+ );+ })}+ </div>+ );+};diff --git a/frontend/src/components/secrets/diff/MultiLineDiff.tsx b/frontend/src/components/secrets/diff/MultiLineDiff.tsxnew file mode 100644index 0000000000..e8d8b3ffbc--- /dev/null+++ b/frontend/src/components/secrets/diff/MultiLineDiff.tsx@@ -0,0 +1,195 @@+import {+ computeLineDiff,+ computeWordDiff,+ splitChangeIntoLines+} from "@app/components/utilities/diff";++export interface MultiLineDiffProps {+ oldText: string;+ newText: string;+ isOldVersion: boolean;+}++/**+ * Render multiline diff for approval screen (side-by-side view)+ */+export const MultiLineDiff = ({ oldText, newText, isOldVersion }: MultiLineDiffProps) => {+ const lineChanges = computeLineDiff(oldText, newText);++ // Check if this is just an append/prepend operation where old content is preserved+ // If the new text starts with or ends with the old text, the old content wasn't removed+ const isAppendOnly = oldText !== "" && newText.startsWith(oldText);+ const isPrependOnly = oldText !== "" && newText.endsWith(oldText);+ const isOldPreserved = isAppendOnly || isPrependOnly;++ // Find the first changed line index+ let firstChangedIndex = -1;+ let lineIndex = 0;+ for (let i = 0; i < lineChanges.length; i += 1) {+ const change = lineChanges[i];+ const lines = splitChangeIntoLines(change.value);++ const isChanged = isOldVersion ? change.removed : change.added;+ if (isChanged && firstChangedIndex === -1) {+ firstChangedIndex = lineIndex;+ break;+ }+ lineIndex += lines.length;+ }++ let currentLineIndex = 0;+ let firstChangedFound = false;++ return (+ <div className="min-w-full font-mono text-sm break-words whitespace-pre-wrap">+ {lineChanges.map((change, changeIdx) => {+ const nextChange = lineChanges[changeIdx + 1];+ const lines = splitChangeIntoLines(change.value);++ return lines.map((line, lineIdx) => {+ const lineKey = `multiline-${changeIdx}-${lineIdx}`;+ const isFirstChanged = !firstChangedFound && currentLineIndex === firstChangedIndex;+ if (isFirstChanged) firstChangedFound = true;+ currentLineIndex += 1;++ if (isOldVersion) {+ // Render old version+ if (change.added) {+ return null; // Skip added lines in old version+ }++ // If old content is preserved (append/prepend only), don't highlight old lines+ // even if diffLines marks them as "removed"+ const isActuallyChanged = change.removed && !isOldPreserved;+ const lineClass = isActuallyChanged+ ? "flex min-w-full bg-red-500/70 rounded-xs text-red-300"+ : "flex min-w-full";++ // If this is a removed line followed by an added line, it's a modification+ // But only show word-level diff if old content wasn't fully preserved+ if (change.removed && nextChange?.added && !isOldPreserved) {+ const nextLines = splitChangeIntoLines(nextChange.value);+ const newLine = nextLines[lineIdx] ?? "";+ const wordDiffs = computeWordDiff(line, newLine);++ // If no common words, just show the line with line-level background+ if (wordDiffs === null) {+ return (+ <div+ key={lineKey}+ className={lineClass}+ data-first-change={isFirstChanged ? "true" : undefined}+ >+ <div className="w-4 shrink-0">-</div>+ <div className="min-w-0 flex-1 break-words">{line}</div>+ </div>+ );+ }++ return (+ <div+ key={lineKey}+ className={lineClass}+ data-first-change={isFirstChanged ? "true" : undefined}+ >+ <div className="w-4 shrink-0">-</div>+ <div className="min-w-0 flex-1 break-words">+ {wordDiffs.map((wordChange, wordIdx) => {+ if (wordChange.added) return null;+ const wordKey = `${lineKey}-word-${wordIdx}`;+ const wordClass = wordChange.removed ? "bg-red-600/70 rounded px-0.5" : "";+ return (+ <span key={wordKey} className={wordClass}>+ {wordChange.value}+ </span>+ );+ })}+ </div>+ </div>+ );+ }++ return (+ <div+ key={lineKey}+ className={lineClass}+ data-first-change={isFirstChanged ? "true" : undefined}+ >+ <div className="w-4 shrink-0">{isActuallyChanged ? "-" : " "}</div>+ <div className="min-w-0 flex-1 break-words">{line}</div>+ </div>+ );+ }++ // Render new version+ if (change.removed) {+ return null; // Skip deleted lines in new version+ }++ // Check if previous change was removed (modification case)+ const prevChange = changeIdx > 0 ? lineChanges[changeIdx - 1] : undefined;+ const isModification = prevChange?.removed && change.added;++ const isChanged = change.added;+ const lineClass = isChanged+ ? "flex min-w-full bg-[#2ecc71]/40 rounded-xs text-green-300"+ : "flex min-w-full";++ // If this is a modification, show word-level diff+ if (isModification && prevChange) {+ const prevLines = splitChangeIntoLines(prevChange.value);+ const oldLine = prevLines[lineIdx] ?? "";+ const wordDiffs = computeWordDiff(oldLine, line);++ // If no common words, just show the line with line-level background+ if (wordDiffs === null) {+ return (+ <div+ key={lineKey}+ className={lineClass}+ data-first-change={isFirstChanged ? "true" : undefined}+ >+ <div className="w-4 shrink-0">+</div>+ <div className="min-w-0 flex-1 break-words">{line}</div>+ </div>+ );+ }++ return (+ <div+ key={lineKey}+ className={lineClass}+ data-first-change={isFirstChanged ? "true" : undefined}+ >+ <div className="w-4 shrink-0">+</div>+ <div className="min-w-0 flex-1 break-words">+ {wordDiffs.map((wordChange, wordIdx) => {+ if (wordChange.removed) return null;+ const wordKey = `${lineKey}-word-${wordIdx}`;+ const wordClass = wordChange.added ? "bg-[#2ecc71]/60 rounded px-0.5" : "";+ return (+ <span key={wordKey} className={wordClass}>+ {wordChange.value}+ </span>+ );+ })}+ </div>+ </div>+ );+ }++ return (+ <div+ key={lineKey}+ className={lineClass}+ data-first-change={isFirstChanged ? "true" : undefined}+ >+ <div className="w-4 shrink-0">{isChanged ? "+" : " "}</div>+ <div className="min-w-0 flex-1 break-words">{line}</div>+ </div>+ );+ });+ })}+ </div>+ );+};diff --git a/frontend/src/components/secrets/diff/SecretDiffView.tsx b/frontend/src/components/secrets/diff/SecretDiffView.tsxnew file mode 100644index 0000000000..2b89ca85c9--- /dev/null+++ b/frontend/src/components/secrets/diff/SecretDiffView.tsx@@ -0,0 +1,315 @@+/* eslint-disable jsx-a11y/no-static-element-interactions */+/* eslint-disable jsx-a11y/click-events-have-key-events */+import { useRef, useState } from "react";+import { faCircleCheck, faCircleXmark, faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons";+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { twMerge } from "tailwind-merge";++import { areValuesEqual, isSingleLine } from "@app/components/utilities/diff";+import { SecretInput, Tooltip } from "@app/components/v2";+import { HIDDEN_SECRET_VALUE } from "@app/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretItem";++import { DiffContainer } from "./DiffContainer";+import { InlineTextDiff, MetadataDiffRenderer, TagsDiffRenderer } from "./FieldDiffRenderers";+import { MultiLineDiff } from "./MultiLineDiff";+import { SingleLineDiff } from "./SingleLineDiff";++export interface SecretVersionData {+ secretKey?: string;+ secretValue?: string;+ secretValueHidden?: boolean;+ secretComment?: string;+ tags?: Array<{ slug: string; color: string }>;+ secretMetadata?: Array<{ key: string; value: string }>;+ skipMultilineEncoding?: boolean;+}++export interface SecretDiffViewProps {+ operationType: "create" | "update" | "delete";+ oldVersion?: SecretVersionData;+ newVersion?: SecretVersionData;+ oldVersionLabel?: string;+ newVersionLabel?: string;+}++const SecretValueRenderer = ({+ isOldVersion,+ isValueHidden,+ value,+ hasValueChanges,+ isBothSingleLine,+ oldValue,+ newValue,+ containerRef+}: {+ isOldVersion: boolean;+ isValueHidden?: boolean;+ value?: string;+ hasValueChanges: boolean;+ isBothSingleLine: boolean;+ oldValue: string;+ newValue: string;+ containerRef: React.RefObject<HTMLDivElement>;+}) => {+ const [isVisible, setIsVisible] = useState(false);++ if (isValueHidden) {+ return (+ <div className="relative">+ <div className="absolute top-1/2 left-1 z-50 -translate-y-1/2">+ <Tooltip+ position="right"+ content={`You do not have access to view the ${isOldVersion ? "old" : "new"} secret value.`}+ >+ <FontAwesomeIcon className="pl-2 text-mineshaft-300" size="sm" icon={faEyeSlash} />+ </Tooltip>+ </div>+ <SecretInput+ isReadOnly+ isVisible={isVisible}+ valueAlwaysHidden={isValueHidden}+ value={HIDDEN_SECRET_VALUE}+ containerClassName="border border-mineshaft-600 bg-bunker-700 py-1.5 text-bunker-300 hover:border-primary-400/50 pr-2 pl-8"+ />+ </div>+ );+ }++ if (hasValueChanges) {+ const variant = isOldVersion ? "removed" : "added";+ if (isBothSingleLine) {+ return (+ <DiffContainer variant={variant} isSingleLine>+ <SingleLineDiff oldText={oldValue} newText={newValue} isOldVersion={isOldVersion} />+ </DiffContainer>+ );+ }++ return (+ <DiffContainer variant={variant} containerRef={containerRef}>+ <MultiLineDiff oldText={oldValue} newText={newValue} isOldVersion={isOldVersion} />+ </DiffContainer>+ );+ }++ return (+ <div className="relative">+ <SecretInput+ isReadOnly+ isVisible={isVisible}+ valueAlwaysHidden={isValueHidden}+ value={value}+ containerClassName={twMerge(+ "border border-mineshaft-600 bg-bunker-700 py-1.5 text-bunker-300 hover:border-primary-400/50",+ isValueHidden ? "pr-2 pl-8" : "px-2"+ )}+ />+ <div className="absolute top-1 right-1" onClick={() => setIsVisible(!isVisible)}>+ <FontAwesomeIcon+ icon={isVisible ? faEyeSlash : faEye}+ className="cursor-pointer rounded-md border border-mineshaft-500 bg-mineshaft-800 p-1.5 text-mineshaft-300 hover:bg-mineshaft-700"+ />+ </div>+ </div>+ );+};++export const SecretDiffView = ({+ operationType,+ oldVersion,+ newVersion,+ oldVersionLabel = "Previous Secret",+ newVersionLabel = "New Secret"+}: SecretDiffViewProps) => {+ const oldDiffContainerRef = useRef<HTMLDivElement>(null);+ const newDiffContainerRef = useRef<HTMLDivElement>(null);++ const oldSecretValue = oldVersion?.secretValue ?? "";+ const newSecretValue = newVersion?.secretValue ?? oldVersion?.secretValue ?? "";+ const hasValueChanges = !areValuesEqual(oldSecretValue, newSecretValue);+ const isBothSingleLine = isSingleLine(oldSecretValue) && isSingleLine(newSecretValue);++ const oldKey = oldVersion?.secretKey ?? "";+ const newKey = newVersion?.secretKey ?? "";+ const hasKeyChanges = oldKey !== newKey && oldKey !== "" && newKey !== "";++ const oldComment = oldVersion?.secretComment ?? "";+ const newComment = newVersion?.secretComment ?? "";+ const hasCommentChanges = oldComment !== newComment;++ const oldMultiline = String(oldVersion?.skipMultilineEncoding ?? false);+ const newMultiline = String(newVersion?.skipMultilineEncoding ?? false);+ const hasMultilineChanges = oldMultiline !== newMultiline;++ const oldTags = oldVersion?.tags ?? [];+ const newTags = newVersion?.tags ?? [];++ const showOldVersion = operationType === "update" || operationType === "delete";+ const showNewVersion = operationType === "update" || operationType === "create";++ return (+ <div className="flex flex-col space-y-4 space-x-0 xl:flex-row xl:space-y-0 xl:space-x-4">+ {showOldVersion ? (+ <div className="flex w-full cursor-default flex-col rounded-lg border border-red-600/60 bg-red-600/10 p-4 xl:w-1/2">+ <div className="mb-4 flex flex-row justify-between">+ <span className="text-md font-medium">{oldVersionLabel}</span>+ <div className="rounded-full bg-red px-2 pt-[0.2rem] pb-[0.14rem] text-xs font-medium">+ <FontAwesomeIcon icon={faCircleXmark} className="pr-1 text-white" />+ Previous+ </div>+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Key</div>+ <InlineTextDiff+ oldText={oldKey}+ newText={newKey}+ isOldVersion+ hasChanges={hasKeyChanges}+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Value</div>+ <SecretValueRenderer+ value={oldVersion?.secretValue}+ isValueHidden={oldVersion?.secretValueHidden}+ isOldVersion+ oldValue={oldSecretValue}+ newValue={newSecretValue}+ hasValueChanges={hasValueChanges}+ isBothSingleLine={isBothSingleLine}+ containerRef={oldDiffContainerRef}+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Comment</div>+ {oldComment ? (+ <div className="max-h-32 thin-scrollbar overflow-y-auto rounded border border-mineshaft-600 bg-bunker-800 p-2">+ <InlineTextDiff+ oldText={oldComment}+ newText={newComment}+ isOldVersion+ hasChanges={hasCommentChanges}+ preserveWhitespace+ />+ </div>+ ) : (+ <span className="text-sm text-mineshaft-300">-</span>+ )}+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Tags</div>+ <TagsDiffRenderer+ tags={oldTags.map((tag) => ({ slug: tag.slug, color: tag.color }))}+ otherTags={newTags.map((tag) => ({ slug: tag.slug, color: tag.color }))}+ isOldVersion+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Metadata</div>+ <MetadataDiffRenderer+ metadata={oldVersion?.secretMetadata}+ otherMetadata={newVersion?.secretMetadata}+ isOldVersion+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Multi-line Encoding</div>+ <InlineTextDiff+ oldText={oldMultiline}+ newText={newMultiline}+ isOldVersion+ hasChanges={hasMultilineChanges}+ fontSize="sm"+ />+ </div>+ </div>+ ) : (+ <div className="flex w-full cursor-default flex-col items-center justify-center rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4 xl:w-1/2">+ <span className="text-sm text-mineshaft-400">+ Secret did not exist in the previous version.+ </span>+ </div>+ )}++ {showNewVersion ? (+ <div className="flex w-full cursor-default flex-col rounded-lg border border-green-600/60 bg-green-600/10 p-4 xl:w-1/2">+ <div className="mb-4 flex flex-row justify-between">+ <span className="text-md font-medium">{newVersionLabel}</span>+ <div className="rounded-full bg-green-600 px-2 pt-[0.2rem] pb-[0.14rem] text-xs font-medium">+ <FontAwesomeIcon icon={faCircleCheck} className="pr-1 text-white" />+ New+ </div>+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Key</div>+ <InlineTextDiff+ oldText={oldKey}+ newText={newKey}+ isOldVersion={false}+ hasChanges={hasKeyChanges}+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Value</div>+ <SecretValueRenderer+ value={newVersion?.secretValue}+ oldValue={oldSecretValue}+ newValue={newSecretValue}+ isValueHidden={newVersion?.secretValueHidden}+ isOldVersion={false}+ hasValueChanges={hasValueChanges}+ isBothSingleLine={isBothSingleLine}+ containerRef={newDiffContainerRef}+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Comment</div>+ {newComment ? (+ <div className="max-h-32 thin-scrollbar overflow-y-auto rounded border border-mineshaft-600 bg-bunker-800 p-2">+ <InlineTextDiff+ oldText={oldComment}+ newText={newComment}+ isOldVersion={false}+ hasChanges={hasCommentChanges}+ preserveWhitespace+ />+ </div>+ ) : (+ <span className="text-sm text-mineshaft-300">-</span>+ )}+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Tags</div>+ <TagsDiffRenderer+ tags={newTags.map((tag) => ({ slug: tag.slug, color: tag.color }))}+ otherTags={oldTags.map((tag) => ({ slug: tag.slug, color: tag.color }))}+ isOldVersion={false}+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Metadata</div>+ <MetadataDiffRenderer+ metadata={newVersion?.secretMetadata ?? oldVersion?.secretMetadata}+ otherMetadata={oldVersion?.secretMetadata}+ isOldVersion={false}+ />+ </div>+ <div className="mb-2">+ <div className="text-sm font-medium text-mineshaft-300">Multi-line Encoding</div>+ <InlineTextDiff+ oldText={oldMultiline}+ newText={newMultiline}+ isOldVersion={false}+ hasChanges={hasMultilineChanges}+ fontSize="sm"+ />+ </div>+ </div>+ ) : (+ <div className="flex w-full cursor-default flex-col items-center justify-center rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4 xl:w-1/2">+ <span className="text-sm text-mineshaft-400">Secret will be deleted.</span>+ </div>+ )}+ </div>+ );+};diff --git a/frontend/src/components/secrets/diff/SingleLineDiff.tsx b/frontend/src/components/secrets/diff/SingleLineDiff.tsxnew file mode 100644index 0000000000..e373cbdf5d--- /dev/null+++ b/frontend/src/components/secrets/diff/SingleLineDiff.tsx@@ -0,0 +1,166 @@+import { diffChars } from "diff";++import { computeWordDiff } from "@app/components/utilities/diff";++export interface SingleLineDiffProps {+ oldText: string;+ newText: string;+ isOldVersion: boolean;+}++/**+ * Render single-line diff (just word highlighting, no container/+/-)+ */+export const SingleLineDiff = ({ oldText, newText, isOldVersion }: SingleLineDiffProps) => {+ // Check if old text is contained within new text (pure insertion - append, prepend, or middle)+ const oldExistsInNew = oldText !== "" && newText !== "" && newText.includes(oldText);++ if (oldExistsInNew) {+ const startIndex = newText.indexOf(oldText);+ const endIndex = startIndex + oldText.length;++ const prependPart = newText.slice(0, startIndex);+ const appendPart = newText.slice(endIndex);++ if (isOldVersion) {+ return (+ <div className="font-mono text-sm break-words">+ <span>{oldText}</span>+ </div>+ );+ }++ return (+ <div className="font-mono text-sm break-words">+ {prependPart && <span className="rounded bg-green-600/70 px-0.5">{prependPart}</span>}+ <span>{oldText}</span>+ {appendPart && <span className="rounded bg-green-600/70 px-0.5">{appendPart}</span>}+ </div>+ );+ }++ // Check if new text is contained within old text (pure deletion)+ const newExistsInOld = oldText !== "" && newText !== "" && oldText.includes(newText);++ if (newExistsInOld) {+ const startIndex = oldText.indexOf(newText);+ const endIndex = startIndex + newText.length;++ const removedPrefix = oldText.slice(0, startIndex);+ const removedSuffix = oldText.slice(endIndex);++ if (isOldVersion) {+ return (+ <div className="font-mono text-sm break-words">+ {removedPrefix && <span className="rounded bg-red-600/70 px-0.5">{removedPrefix}</span>}+ <span>{newText}</span>+ {removedSuffix && <span className="rounded bg-red-600/70 px-0.5">{removedSuffix}</span>}+ </div>+ );+ }++ return (+ <div className="font-mono text-sm break-words">+ <span>{newText}</span>+ </div>+ );+ }++ // For mixed changes (both insertions and deletions), use character diff+ // but only apply special handling for pure insertions+ const charDiffs = diffChars(oldText, newText);+ const hasRemovals = charDiffs.some((d) => d.removed);+ const hasAdditions = charDiffs.some((d) => d.added);++ // Pure insertion case (no removals): don't highlight old version+ if (!hasRemovals && hasAdditions) {+ if (isOldVersion) {+ return (+ <div className="font-mono text-sm break-words">+ <span>{oldText}</span>+ </div>+ );+ }+ // Show new version with character-level highlighting+ return (+ <div className="font-mono text-sm break-words">+ {charDiffs.map((change, idx) => {+ if (change.removed) return null;+ const key = `char-${idx}`;+ const className = change.added ? "bg-green-600/70 rounded px-0.5" : "";+ return (+ <span key={key} className={className}>+ {change.value}+ </span>+ );+ })}+ </div>+ );+ }++ // Pure deletion case (no additions): don't highlight new version+ if (hasRemovals && !hasAdditions) {+ if (!isOldVersion) {+ return (+ <div className="font-mono text-sm break-words">+ <span>{newText}</span>+ </div>+ );+ }+ // Show old version with character-level highlighting+ return (+ <div className="font-mono text-sm break-words">+ {charDiffs.map((change, idx) => {+ if (change.added) return null;+ const key = `char-${idx}`;+ const className = change.removed ? "bg-red-600/70 rounded px-0.5" : "";+ return (+ <span key={key} className={className}>+ {change.value}+ </span>+ );+ })}+ </div>+ );+ }++ // Mixed changes: fall back to word-level diff (more readable for humans)+ const wordDiffs = computeWordDiff(oldText, newText);++ // If no common words, show as single highlighted block+ if (!wordDiffs) {+ const value = isOldVersion ? oldText : newText;+ const highlightClass = isOldVersion+ ? "bg-red-600/70 rounded px-0.5"+ : "bg-green-600/70 rounded px-0.5";+ return (+ <div className="font-mono text-sm break-words">+ <span className={highlightClass}>{value}</span>+ </div>+ );+ }++ // Show word-by-word diff+ return (+ <div className="font-mono text-sm break-words">+ {wordDiffs.map((change, wordIdx) => {+ if (isOldVersion && change.added) return null;+ if (!isOldVersion && change.removed) return null;++ const wordKey = `word-${wordIdx}`;+ let wordClass = "";+ if (change.removed) {+ wordClass = "bg-red-600/70 rounded px-0.5";+ } else if (change.added) {+ wordClass = "bg-green-600/70 rounded px-0.5";+ }++ return (+ <span key={wordKey} className={wordClass}>+ {change.value}+ </span>+ );+ })}+ </div>+ );+};diff --git a/frontend/src/components/secrets/diff/index.ts b/frontend/src/components/secrets/diff/index.tsnew file mode 100644index 0000000000..196f222808--- /dev/null+++ b/frontend/src/components/secrets/diff/index.ts@@ -0,0 +1,9 @@+export type { DiffContainerProps } from "./DiffContainer";+export { DiffContainer } from "./DiffContainer";+export { InlineTextDiff, MetadataDiffRenderer, TagsDiffRenderer } from "./FieldDiffRenderers";+export type { MultiLineDiffProps } from "./MultiLineDiff";+export { MultiLineDiff } from "./MultiLineDiff";+export type { SecretDiffViewProps, SecretVersionData } from "./SecretDiffView";+export { SecretDiffView } from "./SecretDiffView";+export type { SingleLineDiffProps } from "./SingleLineDiff";+export { SingleLineDiff } from "./SingleLineDiff";diff --git a/frontend/src/components/utilities/diff.ts b/frontend/src/components/utilities/diff.tsnew file mode 100644index 0000000000..411350f572--- /dev/null+++ b/frontend/src/components/utilities/diff.ts@@ -0,0 +1,79 @@+import type { Change } from "diff";+import { diffLines, diffWords } from "diff";++/**+ * Scrolls a container to center the first changed element if it's not visible+ */+export const scrollToFirstChange = (container: HTMLDivElement | null) => {+ if (!container) return;++ const firstChange = container.querySelector('[data-first-change="true"]') as HTMLElement;+ if (!firstChange) return;++ const elementTop = firstChange.offsetTop;+ const containerHeight = container.clientHeight;+ const elementHeight = firstChange.offsetHeight;++ const isVisible =+ elementTop >= container.scrollTop &&+ elementTop + elementHeight <= container.scrollTop + containerHeight;++ if (!isVisible) {+ const targetScrollTop = elementTop - containerHeight / 2 + elementHeight / 2;+ container.scrollTo({ top: Math.max(0, targetScrollTop), behavior: "smooth" });+ }+};++export const areValuesEqual = (+ oldValue: string | null | undefined,+ newValue: string | null | undefined+): boolean => {+ return (oldValue ?? "") === (newValue ?? "");+};++export const isSingleLine = (str: string | null | undefined): boolean => {+ if (!str || typeof str !== "string") return true;+ return !str.includes("\n");+};++/**+ * Use jsdiff for line-by-line diffing - returns Change[] directly+ */+export const computeLineDiff = (oldText: string, newText: string): Change[] => {+ return diffLines(oldText, newText, {+ ignoreWhitespace: false,+ newlineIsToken: false+ });+};++/**+ * Use jsdiff for word-level diffing - returns Change[] directly or null+ * Returns null when there are no common words, indicating entire line should be highlighted+ */+export const computeWordDiff = (oldText: string, newText: string): Change[] | null => {+ const changes = diffWords(oldText, newText);++ // Check if there are any common words (excluding whitespace and punctuation)+ const hasCommonWords = changes.some(+ (change) => !change.added && !change.removed && /\w/.test(change.value)+ );++ // If no common words, return null to indicate entire line should be highlighted+ if (!hasCommonWords && oldText.trim() !== "" && newText.trim() !== "") {+ return null;+ }++ return changes;+};++/**+ * Helper to split change value into lines, removing trailing empty string from split+ */+export const splitChangeIntoLines = (value: string): string[] => {+ const lines = value.split("\n");+ // Remove trailing empty string (artifact of split when value ends with newline)+ if (lines.length > 0 && lines[lines.length - 1] === "") {+ lines.pop();+ }+ return lines;+};diff --git a/frontend/src/pages/secret-manager/CommitDetailsPage/components/SecretVersionDiffView/SecretVersionDiffView.tsx b/frontend/src/pages/secret-manager/CommitDetailsPage/components/SecretVersionDiffView/SecretVersionDiffView.tsxindex b6fc4ffa4d..d931890ee7 100644--- a/frontend/src/pages/secret-manager/CommitDetailsPage/components/SecretVersionDiffView/SecretVersionDiffView.tsx+++ b/frontend/src/pages/secret-manager/CommitDetailsPage/components/SecretVersionDiffView/SecretVersionDiffView.tsx@@ -4,6 +4,7 @@ import { faChevronDown, faChevronUp, faTrash } from "@fortawesome/free-solid-svgimport { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { twMerge } from "tailwind-merge";+import { SecretDiffView, SecretVersionData } from "@app/components/secrets/diff";import { IconButton, Tooltip } from "@app/components/v2";export interface Version {@@ -506,6 +507,10 @@ export const SecretVersionDiffView = ({let newVersionContent = null;let diffPaths = new Set<string>();+ let operationType: "create" | "update" | "delete" = "update";+ if (item.isAdded) operationType = "create";+ else if (item.isDeleted) operationType = "delete";+if (item.isUpdated && sortedVersions.length >= 2) {if (item.isRollback) {[oldVersion, newVersion] = sortedVersions;@@ -572,6 +577,35 @@ export const SecretVersionDiffView = ({return null;}+ // Convert versions to SecretVersionData format for SecretDiffView+ const convertToSecretVersionData = (version: Version | null): SecretVersionData | undefined => {+ if (!version) return undefined;++ // Handle tags - normalize to string array (slugs only)+ let tags: string[] | undefined;+ if (Array.isArray(version.tags)) {+ tags = version.tags.map((tag: { slug?: string } | string) => {+ if (typeof tag === "string") {+ return tag;+ }+ return tag.slug ?? "";+ });+ }++ return {+ secretKey: version.secretKey as string | undefined,+ secretValue: version.secretValue as string | undefined,+ secretValueHidden: version.secretValueHidden as boolean | undefined,+ secretComment: version.comment as string | undefined,+ tags,+ secretMetadata: version.secretMetadata as Array<{ key: string; value: string }> | undefined,+ skipMultilineEncoding: version.skipMultilineEncoding as boolean | undefined+ };+ };++ const oldSecretData = convertToSecretVersionData(oldVersion);+ const newSecretData = convertToSecretVersionData(newVersion);+const renderHeader = () => {if (customHeader) {return customHeader;@@ -648,21 +682,29 @@ export const SecretVersionDiffView = ({{showHeader && renderHeader()}{!collapsed && (<div className="border-t border-mineshaft-700 bg-mineshaft-900 p-3 text-mineshaft-100">- <div className="flex gap-3">- <div- ref={oldContainerRef}- className="max-h-96 thin-scrollbar flex-1 overflow-auto whitespace-pre"- >- {oldVersionContent}+ {item.type === "secret" ? (+ <SecretDiffView+ operationType={operationType}+ oldVersion={oldSecretData}+ newVersion={newSecretData}+ />+ ) : (+ <div className="flex gap-3">+ <div+ ref={oldContainerRef}+ className="max-h-96 thin-scrollbar flex-1 overflow-auto whitespace-pre"+ >+ {oldVersionContent}+ </div>+ <div className="max-h-96 w-[0.05rem] self-stretch bg-mineshaft-600" />+ <div+ ref={newContainerRef}+ className="max-h-96 thin-scrollbar flex-1 overflow-auto whitespace-pre"+ >+ {newVersionContent}+ </div></div>- <div className="max-h-96 w-[0.05rem] self-stretch bg-mineshaft-600" />- <div- ref={newContainerRef}- className="max-h-96 thin-scrollbar flex-1 overflow-auto whitespace-pre"- >- {newVersionContent}- </div>- </div>+ )}</div>)}</div>diff --git a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChangeItem.tsx b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChangeItem.tsxindex f2958f843f..33d42715b3 100644--- a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChangeItem.tsx+++ b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChangeItem.tsx@@ -1,319 +1,11 @@-/* eslint-disable jsx-a11y/no-static-element-interactions */-/* eslint-disable jsx-a11y/click-events-have-key-events *//* eslint-disable no-nested-ternary */-import { useEffect, useRef, useState } from "react";-import {- faCircleCheck,- faCircleXmark,- faExclamationTriangle,- faEye,- faEyeSlash,- faInfoCircle,- faKey-} from "@fortawesome/free-solid-svg-icons";+import { faExclamationTriangle, faInfoCircle } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import type { Change } from "diff";-import { diffLines, diffWords } from "diff";-import { twMerge } from "tailwind-merge";-import { SecretInput, Tag, Tooltip } from "@app/components/v2";+import { SecretDiffView, SecretVersionData } from "@app/components/secrets/diff";+import { Tooltip } from "@app/components/v2";import { CommitType, SecretV3Raw, TSecretApprovalSecChange, WsTag } from "@app/hooks/api/types";-// Scrolls a container to center the first changed element if it's not visible-const scrollToFirstChange = (container: HTMLDivElement | null) => {- if (!container) return;-- const firstChange = container.querySelector('[data-first-change="true"]') as HTMLElement;- if (!firstChange) return;-- const elementTop = firstChange.offsetTop;- const containerHeight = container.clientHeight;- const elementHeight = firstChange.offsetHeight;-- const isVisible =- elementTop >= container.scrollTop &&- elementTop + elementHeight <= container.scrollTop + containerHeight;-- if (!isVisible) {- const targetScrollTop = elementTop - containerHeight / 2 + elementHeight / 2;- container.scrollTo({ top: Math.max(0, targetScrollTop), behavior: "smooth" });- }-};--// Compare values to determine if they're actually different-const areValuesEqual = (- oldValue: string | null | undefined,- newValue: string | null | undefined-): boolean => {- return (oldValue ?? "") === (newValue ?? "");-};--const isSingleLine = (str: string | null | undefined): boolean => {- if (!str || typeof str !== "string") return true;- return !str.includes("\n");-};--// Use jsdiff for line-by-line diffing - returns Change[] directly-const computeLineDiff = (oldText: string, newText: string): Change[] => {- return diffLines(oldText, newText, {- ignoreWhitespace: false,- newlineIsToken: false- });-};--// Use jsdiff for word-level diffing - returns Change[] directly or null-const computeWordDiff = (oldText: string, newText: string): Change[] | null => {- const changes = diffWords(oldText, newText);-- // Check if there are any common words (excluding whitespace and punctuation)- const hasCommonWords = changes.some(- (change) => !change.added && !change.removed && /\w/.test(change.value)- );-- // If no common words, return null to indicate entire line should be highlighted- if (!hasCommonWords && oldText.trim() !== "" && newText.trim() !== "") {- return null;- }-- return changes;-};--// Render single-line diff (just word highlighting, no container/+/-)-const renderSingleLineDiffForApproval = (- oldText: string,- newText: string,- isOldVersion: boolean-): JSX.Element => {- // If completely new or deleted, or no common words, show as single block with full highlight- const wordDiffs = computeWordDiff(oldText, newText);- const shouldShowAsBlock =- (oldText === "" && newText !== "") || (oldText !== "" && newText === "") || wordDiffs === null;-- if (shouldShowAsBlock) {- const value = isOldVersion ? oldText : newText;- // Apply highlight to the entire value when showing as block- const highlightClass = isOldVersion- ? "bg-red-600/70 rounded px-0.5"- : "bg-green-600/70 rounded px-0.5";- return (- <div className="font-mono text-sm break-words">- {value && <span className={highlightClass}>{value}</span>}- </div>- );- }-- // Show word-by-word diff when there are common words- return (- <div className="font-mono text-sm break-words">- {wordDiffs.map((change, wordIdx) => {- if (isOldVersion && change.added) return null;- if (!isOldVersion && change.removed) return null;-- const wordKey = `singleline-word-${wordIdx}`;- const wordClass = change.removed- ? "bg-red-600/70 rounded px-0.5"- : change.added- ? "bg-green-600/70 rounded px-0.5"- : "";-- return (- <span key={wordKey} className={wordClass}>- {change.value}- </span>- );- })}- </div>- );-};--// Helper to split change value into lines, removing trailing empty string from split-const splitChangeIntoLines = (value: string): string[] => {- const lines = value.split("\n");- // Remove trailing empty string (artifact of split when value ends with newline)- if (lines.length > 0 && lines[lines.length - 1] === "") {- lines.pop();- }- return lines;-};--// Render multiline diff for approval screen (side-by-side view)-const renderMultilineDiffForApproval = (- oldText: string,- newText: string,- isOldVersion: boolean-): JSX.Element => {- const lineChanges = computeLineDiff(oldText, newText);-- // Find the first changed line index- let firstChangedIndex = -1;- let lineIndex = 0;- for (let i = 0; i < lineChanges.length; i += 1) {- const change = lineChanges[i];- const lines = splitChangeIntoLines(change.value);-- const isChanged = isOldVersion ? change.removed : change.added;- if (isChanged && firstChangedIndex === -1) {- firstChangedIndex = lineIndex;- break;- }- lineIndex += lines.length;- }-- let currentLineIndex = 0;- let firstChangedFound = false;-- return (- <div className="min-w-full font-mono text-sm break-words whitespace-pre-wrap">- {lineChanges.map((change, changeIdx) => {- const nextChange = lineChanges[changeIdx + 1];- const lines = splitChangeIntoLines(change.value);-- return lines.map((line, lineIdx) => {- const lineKey = `multiline-${changeIdx}-${lineIdx}`;- const isFirstChanged = !firstChangedFound && currentLineIndex === firstChangedIndex;- if (isFirstChanged) firstChangedFound = true;- currentLineIndex += 1;-- if (isOldVersion) {- // Render old version- if (change.added) {- return null; // Skip added lines in old version- }-- const isChanged = change.removed;- const lineClass = isChanged- ? "flex min-w-full bg-red-500/70 rounded-xs text-red-300"- : "flex min-w-full";-- // If this is a removed line followed by an added line, it's a modification- if (change.removed && nextChange?.added) {- const nextLines = splitChangeIntoLines(nextChange.value);- const newLine = nextLines[lineIdx] ?? "";- const wordDiffs = computeWordDiff(line, newLine);-- // If no common words, just show the line with line-level background- if (wordDiffs === null) {- return (- <div- key={lineKey}- className={lineClass}- data-first-change={isFirstChanged ? "true" : undefined}- >- <div className="w-4 shrink-0">-</div>- <div className="min-w-0 flex-1 break-words">{line}</div>- </div>- );- }-- return (- <div- key={lineKey}- className={lineClass}- data-first-change={isFirstChanged ? "true" : undefined}- >- <div className="w-4 shrink-0">-</div>- <div className="min-w-0 flex-1 break-words">- {wordDiffs.map((wordChange, wordIdx) => {- if (wordChange.added) return null;- const wordKey = `${lineKey}-word-${wordIdx}`;- const wordClass = wordChange.removed ? "bg-red-600/70 rounded px-0.5" : "";- return (- <span key={wordKey} className={wordClass}>- {wordChange.value}- </span>- );- })}- </div>- </div>- );- }-- return (- <div- key={lineKey}- className={lineClass}- data-first-change={isFirstChanged ? "true" : undefined}- >- <div className="w-4 shrink-0">{isChanged ? "-" : " "}</div>- <div className="min-w-0 flex-1 break-words">{line}</div>- </div>- );- }-- // Render new version- if (change.removed) {- return null; // Skip deleted lines in new version- }-- // Check if previous change was removed (modification case)- const prevChange = changeIdx > 0 ? lineChanges[changeIdx - 1] : undefined;- const isModification = prevChange?.removed && change.added;-- const isChanged = change.added;- const lineClass = isChanged- ? "flex min-w-full bg-green-500/70 rounded-xs text-green-300"- : "flex min-w-full";-- // If this is a modification, show word-level diff- if (isModification && prevChange) {- const prevLines = splitChangeIntoLines(prevChange.value);- const oldLine = prevLines[lineIdx] ?? "";- const wordDiffs = computeWordDiff(oldLine, line);-- // If no common words, just show the line with line-level background- if (wordDiffs === null) {- return (- <div- key={lineKey}- className={lineClass}- data-first-change={isFirstChanged ? "true" : undefined}- >- <div className="w-4 shrink-0">+</div>- <div className="min-w-0 flex-1 break-words">{line}</div>- </div>- );- }-- return (- <div- key={lineKey}- className={lineClass}- data-first-change={isFirstChanged ? "true" : undefined}- >- <div className="w-4 shrink-0">+</div>- <div className="min-w-0 flex-1 break-words">- {wordDiffs.map((wordChange, wordIdx) => {- if (wordChange.removed) return null;- const wordKey = `${lineKey}-word-${wordIdx}`;- const wordClass = wordChange.added ? "bg-green-600/70 rounded px-0.5" : "";- return (- <span key={wordKey} className={wordClass}>- {wordChange.value}- </span>- );- })}- </div>- </div>- );- }-- return (- <div- key={lineKey}- className={lineClass}- data-first-change={isFirstChanged ? "true" : undefined}- >- <div className="w-4 shrink-0">{isChanged ? "+" : " "}</div>- <div className="min-w-0 flex-1 break-words">{line}</div>- </div>- );- });- })}- </div>- );-};-// ===== END MULTILINE DIFF FUNCTIONS =====-export type Props = {op: CommitType;secretVersion?: SecretV3Raw;@@ -346,194 +38,42 @@ const generateConflictText = (op: CommitType) => {return null;};-// Helper function to render old secret value-const renderOldSecretValue = ({- isRotatedSecret,- isValueHidden,- value,- isVisible,- onToggleVisibility,- hasValueChanges,- isBothSingleLine,- oldValue,- newValue,- oldDiffContainerRef-}: {- isRotatedSecret?: boolean;- isValueHidden?: boolean;- value?: string;- isVisible: boolean;- onToggleVisibility: () => void;- hasValueChanges: boolean;- isBothSingleLine: boolean;- oldValue: string;- newValue: string;- oldDiffContainerRef: React.RefObject<HTMLDivElement>;-}) => {- if (isRotatedSecret) {- return <span className="text-mineshaft-400">Rotated Secret value will not be affected</span>;- }-- if (isValueHidden) {- return (- <div className="relative">- <div className="absolute top-1/2 left-1 z-50 -translate-y-1/2">- <Tooltip position="right" content="You do not have access to view the old secret value.">- <FontAwesomeIcon className="pl-2 text-mineshaft-300" size="sm" icon={faEyeSlash} />- </Tooltip>- </div>- <SecretInput- isReadOnly- isVisible={isVisible}- valueAlwaysHidden={isValueHidden}- value={value}- containerClassName="border border-mineshaft-600 bg-bunker-700 py-1.5 text-bunker-300 hover:border-primary-400/50 pr-2 pl-8"- />- </div>- );- }-- if (hasValueChanges) {- if (isBothSingleLine) {- return (- <div- className="relative rounded-lg border border-mineshaft-600 p-2"- style={{ backgroundColor: "#120808" }}- >- {renderSingleLineDiffForApproval(oldValue, newValue, true)}- </div>- );- }-- return (- <div- ref={oldDiffContainerRef}- className="relative max-h-96 thin-scrollbar overflow-x-auto overflow-y-auto rounded-lg border border-mineshaft-600 p-2"- style={{ backgroundColor: "#120808" }}- >- <div className="min-w-max">{renderMultilineDiffForApproval(oldValue, newValue, true)}</div>- </div>- );+// Convert approval data to SecretVersionData format+const convertToSecretVersionData = (+ secret: SecretV3Raw | undefined,+ change?: Omit<TSecretApprovalSecChange, "tags"> & {+ tags?: WsTag[];+ secretMetadata?: { key: string; value: string }[];+ skipMultilineEncoding?: boolean;}-- return (- <div className="relative">- <SecretInput- isReadOnly- isVisible={isVisible}- valueAlwaysHidden={isValueHidden}- value={value}- containerClassName={twMerge(- "border border-mineshaft-600 bg-bunker-700 py-1.5 text-bunker-300 hover:border-primary-400/50",- isValueHidden ? "pr-2 pl-8" : "px-2"- )}- />- {!isValueHidden && (- <div className="absolute top-1 right-1" onClick={onToggleVisibility}>- <FontAwesomeIcon- icon={isVisible ? faEyeSlash : faEye}- className="cursor-pointer rounded-md border border-mineshaft-500 bg-mineshaft-800 p-1.5 text-mineshaft-300 hover:bg-mineshaft-700"- />- </div>- )}- </div>- );-};--// Helper function to render new secret value-const renderNewSecretValue = ({- isRotatedSecret,- isValueHidden,- value,- fallbackValue,- isVisible,- onToggleVisibility,- hasValueChanges,- isBothSingleLine,- oldValue,- newValue,- newDiffContainerRef-}: {- isRotatedSecret?: boolean;- isValueHidden?: boolean;- value?: string;- fallbackValue?: string;- isVisible: boolean;- onToggleVisibility: () => void;- hasValueChanges: boolean;- isBothSingleLine: boolean;- oldValue: string;- newValue: string;- newDiffContainerRef: React.RefObject<HTMLDivElement>;-}) => {- if (isRotatedSecret) {- return <span className="text-mineshaft-400">Rotated Secret value will not be affected</span>;+): SecretVersionData | undefined => {+ if (secret && !change) {+ return {+ secretKey: secret.secretKey,+ secretValue: secret.secretValue,+ secretValueHidden: secret.secretValueHidden,+ secretComment: secret.secretComment,+ tags: secret.tags?.map((t) => ({ slug: t.slug, color: t.color })),+ secretMetadata: secret.secretMetadata,+ skipMultilineEncoding: secret.skipMultilineEncoding+ };}- if (isValueHidden) {- return (- <div className="relative">- <div className="absolute top-1/2 left-1 z-50 -translate-y-1/2">- <Tooltip position="right" content="You do not have access to view the new secret value.">- <FontAwesomeIcon className="pl-2 text-mineshaft-300" size="sm" icon={faEyeSlash} />- </Tooltip>- </div>- <SecretInput- isReadOnly- valueAlwaysHidden={isValueHidden}- isVisible={isVisible}- value={value ?? fallbackValue}- containerClassName="border border-mineshaft-600 bg-bunker-700 py-1.5 text-bunker-300 hover:border-primary-400/50 pr-2 pl-8"- />- </div>- );- }-- if (hasValueChanges) {- if (isBothSingleLine) {- return (- <div- className="relative rounded-lg border border-mineshaft-600 p-2"- style={{ backgroundColor: "#081208" }}- >- {renderSingleLineDiffForApproval(oldValue, newValue, false)}- </div>- );- }-- return (- <div- ref={newDiffContainerRef}- className="relative max-h-96 thin-scrollbar overflow-x-auto overflow-y-auto rounded-lg border border-mineshaft-600 p-2"- style={{ backgroundColor: "#081208" }}- >- <div className="min-w-max">{renderMultilineDiffForApproval(oldValue, newValue, false)}</div>- </div>- );+ if (change) {+ return {+ secretKey: change.secretKey ?? secret?.secretKey,+ secretValue: change.secretValue ?? secret?.secretValue,+ secretValueHidden: change.secretValueHidden ?? secret?.secretValueHidden,+ secretComment: change.secretComment ?? secret?.secretComment,+ tags:+ change.tags?.map((t) => ({ slug: t.slug, color: t.color })) ??+ secret?.tags?.map((t) => ({ slug: t.slug, color: t.color })),+ secretMetadata: change.secretMetadata ?? secret?.secretMetadata,+ skipMultilineEncoding: change.skipMultilineEncoding ?? secret?.skipMultilineEncoding+ };}- return (- <div className="relative">- <SecretInput- isReadOnly- valueAlwaysHidden={isValueHidden}- isVisible={isVisible}- value={value ?? fallbackValue}- containerClassName={twMerge(- "border border-mineshaft-600 bg-bunker-700 py-1.5 text-bunker-300 hover:border-primary-400/50",- isValueHidden ? "pr-2 pl-8" : "px-2"- )}- />- {!isValueHidden && (- <div className="absolute top-1 right-1" onClick={onToggleVisibility}>- <FontAwesomeIcon- icon={isVisible ? faEyeSlash : faEye}- className="cursor-pointer rounded-md border border-mineshaft-500 bg-mineshaft-800 p-1.5 text-mineshaft-300 hover:bg-mineshaft-700"- />- </div>- )}- </div>- );+ return undefined;};export const SecretApprovalRequestChangeItem = ({@@ -549,29 +89,13 @@ export const SecretApprovalRequestChangeItem = ({const itemConflict =hasMerged && conflicts.find((el) => el.op === op && el.secretId === newVersion?.id);const hasConflict = Boolean(itemConflict);- const [isOldSecretValueVisible, setIsOldSecretValueVisible] = useState(false);- const [isNewSecretValueVisible, setIsNewSecretValueVisible] = useState(false);- const oldDiffContainerRef = useRef<HTMLDivElement>(null);- const newDiffContainerRef = useRef<HTMLDivElement>(null);- // Compute conditions for secret value comparisons- const oldSecretValue = secretVersion?.secretValue ?? "";- const newSecretValue = newVersion?.secretValue ?? "";- const newSecretValueForComparison = newVersion?.secretValue ?? secretVersion?.secretValue ?? "";- const hasValueChanges = !areValuesEqual(oldSecretValue, newSecretValue);- const hasValueChangesForNew = !areValuesEqual(oldSecretValue, newSecretValueForComparison);- const isBothSingleLine = isSingleLine(oldSecretValue) && isSingleLine(newSecretValue);- const isBothSingleLineForNew =- isSingleLine(oldSecretValue) && isSingleLine(newSecretValueForComparison);+ const oldSecretData = convertToSecretVersionData(secretVersion);+ const newSecretData = convertToSecretVersionData(secretVersion, newVersion);- // Scroll to first change when diff is rendered- useEffect(() => {- const timeout = setTimeout(() => {- if (oldDiffContainerRef.current) scrollToFirstChange(oldDiffContainerRef.current);- if (newDiffContainerRef.current) scrollToFirstChange(newDiffContainerRef.current);- }, 100);- return () => clearTimeout(timeout);- }, [secretVersion?.secretValue, newVersion?.secretValue]);+ let operationType: "create" | "update" | "delete" = "update";+ if (op === CommitType.CREATE) operationType = "create";+ else if (op === CommitType.DELETE) operationType = "delete";return (<div className="rounded-lg border border-mineshaft-600 bg-mineshaft-900 px-4 pt-2 pb-4">@@ -593,236 +117,11 @@ export const SecretApprovalRequestChangeItem = ({)}</div><div>- <div className="flex flex-col space-y-4 space-x-0 xl:flex-row xl:space-y-0 xl:space-x-4">- {op === CommitType.UPDATE || op === CommitType.DELETE ? (- <div className="flex w-full cursor-default flex-col rounded-lg border border-red-600/60 bg-red-600/10 p-4 xl:w-1/2">- <div className="mb-4 flex flex-row justify-between">- <span className="text-md font-medium">Previous Secret</span>- <div className="rounded-full bg-red px-2 pt-[0.2rem] pb-[0.14rem] text-xs font-medium">- <FontAwesomeIcon icon={faCircleXmark} className="pr-1 text-white" />- Previous- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Key</div>- <p className="max-w-lg text-sm break-words">{secretVersion?.secretKey}</p>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Value</div>- <div className="text-sm">- {renderOldSecretValue({- isRotatedSecret: newVersion?.isRotatedSecret,- isValueHidden: secretVersion?.secretValueHidden,- value: secretVersion?.secretValue,- isVisible: isOldSecretValueVisible,- onToggleVisibility: () => setIsOldSecretValueVisible(!isOldSecretValueVisible),- hasValueChanges,- isBothSingleLine,- oldValue: oldSecretValue,- newValue: newSecretValue,- oldDiffContainerRef- })}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Comment</div>- <div className="max-h-20 thin-scrollbar max-w-136 overflow-y-auto text-sm break-words xl:max-w-md">- {secretVersion?.secretComment || (- <span className="text-sm text-mineshaft-300">-</span>- )}{" "}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Tags</div>- <div className="flex flex-wrap gap-y-2">- {(secretVersion?.tags?.length ?? 0) ? (- secretVersion?.tags?.map(({ slug, id: tagId, color }) => (- <Tag- className="flex w-min items-center space-x-1.5 border border-mineshaft-500 bg-mineshaft-800"- key={`${secretVersion.id}-${tagId}`}- >- <div- className="h-3 w-3 rounded-full"- style={{ backgroundColor: color || "#bec2c8" }}- />- <div className="text-sm">{slug}</div>- </Tag>- ))- ) : (- <span className="text-sm text-mineshaft-300">-</span>- )}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Metadata</div>- <div>- {secretVersion?.secretMetadata?.length ? (- <div className="mt-1 flex flex-wrap gap-2 text-sm text-mineshaft-300">- {secretVersion.secretMetadata?.map((el) => (- <div key={el.key} className="flex items-center">- <Tag- size="xs"- className="mr-0 flex items-center rounded-r-none border border-mineshaft-500"- >- <FontAwesomeIcon icon={faKey} size="xs" className="mr-1" />- <Tooltip- className="max-w-lg break-words whitespace-normal"- content={el.key}- >- <div className="max-w-[125px] overflow-hidden text-ellipsis whitespace-nowrap">- {el.key}- </div>- </Tooltip>- </Tag>- <Tag- size="xs"- className="flex items-center rounded-l-none border border-mineshaft-500 bg-mineshaft-900 pl-1"- >- <Tooltip- className="max-w-lg break-words whitespace-normal"- content={el.value}- >- <div className="max-w-[125px] overflow-hidden text-ellipsis whitespace-nowrap">- {el.value}- </div>- </Tooltip>- </Tag>- </div>- ))}- </div>- ) : (- <p className="text-sm text-mineshaft-300">-</p>- )}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Multi-line Encoding</div>- <div className="text-sm">- {secretVersion?.skipMultilineEncoding?.toString() || "false"}- </div>- </div>- </div>- ) : (- <div className="text-md flex w-full items-center justify-center rounded-md border border-mineshaft-600 bg-mineshaft-800 text-mineshaft-300 xl:w-1/2">- Secret did not exist in the previous version.- </div>- )}- {op === CommitType.UPDATE || op === CommitType.CREATE ? (- <div className="flex w-full cursor-default flex-col rounded-lg border border-green-600/60 bg-green-600/10 p-4 xl:w-1/2">- <div className="mb-4 flex flex-row justify-between">- <span className="text-md font-medium">New Secret</span>- <div className="rounded-full bg-green-600 px-2 pt-[0.2rem] pb-[0.14rem] text-xs font-medium">- <FontAwesomeIcon icon={faCircleCheck} className="pr-1 text-white" />- New- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Key</div>- <div className="max-w-md text-sm break-words">{newVersion?.secretKey} </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Value</div>- <div className="text-sm">- {renderNewSecretValue({- isRotatedSecret: newVersion?.isRotatedSecret,- isValueHidden: newVersion?.secretValueHidden,- value: newVersion?.secretValue,- fallbackValue: secretVersion?.secretValue,- isVisible: isNewSecretValueVisible,- onToggleVisibility: () => setIsNewSecretValueVisible(!isNewSecretValueVisible),- hasValueChanges: hasValueChangesForNew,- isBothSingleLine: isBothSingleLineForNew,- oldValue: oldSecretValue,- newValue: newSecretValueForComparison,- newDiffContainerRef- })}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Comment</div>- <div className="max-h-20 thin-scrollbar max-w-136 overflow-y-auto text-sm break-words xl:max-w-md">- {(newVersion?.secretComment ?? secretVersion?.secretComment) || (- <span className="text-sm text-mineshaft-300">-</span>- )}{" "}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Tags</div>- <div className="flex flex-wrap gap-y-2">- {(newVersion?.tags?.length ?? 0) ? (- newVersion?.tags?.map(({ slug, id: tagId, color }) => (- <Tag- className="flex w-min items-center space-x-1.5 border border-mineshaft-500 bg-mineshaft-800"- key={`${newVersion.id}-${tagId}`}- >- <div- className="h-2.5 w-2.5 rounded-full"- style={{ backgroundColor: color || "#bec2c8" }}- />- <div className="text-sm">{slug}</div>- </Tag>- ))- ) : (- <span className="text-sm text-mineshaft-300">-</span>- )}- </div>- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Metadata</div>- {(newVersion?.secretMetadata ?? secretVersion?.secretMetadata)?.length ? (- <div className="mt-1 flex flex-wrap gap-2 text-sm text-mineshaft-300">- {(newVersion?.secretMetadata ?? secretVersion?.secretMetadata)?.map((el) => (- <div key={el.key} className="flex items-center">- <Tag- size="xs"- className="mr-0 flex items-center rounded-r-none border border-mineshaft-500"- >- <FontAwesomeIcon icon={faKey} size="xs" className="mr-1" />- <Tooltip- className="max-w-lg break-words whitespace-normal"- content={el.key}- >- <div className="max-w-[125px] overflow-hidden text-ellipsis whitespace-nowrap">- {el.key}- </div>- </Tooltip>- </Tag>- <Tag- size="xs"- className="flex items-center rounded-l-none border border-mineshaft-500 bg-mineshaft-900 pl-1"- >- <Tooltip- className="max-w-lg break-words whitespace-normal"- content={el.value}- >- <div className="max-w-[125px] overflow-hidden text-ellipsis whitespace-nowrap">- {el.value}- </div>- </Tooltip>- </Tag>- </div>- ))}- </div>- ) : (- <p className="text-sm text-mineshaft-300">-</p>- )}- </div>- <div className="mb-2">- <div className="text-sm font-medium text-mineshaft-300">Multi-line Encoding</div>- <div className="text-sm">- {newVersion?.skipMultilineEncoding?.toString() ??- secretVersion?.skipMultilineEncoding?.toString() ??- "false"}- </div>- </div>- </div>- ) : (- <div className="text-md flex w-full items-center justify-center rounded-md border border-mineshaft-600 bg-mineshaft-800 text-mineshaft-300 xl:w-1/2">- {" "}- Secret did not exist in the previous version.- </div>- )}- </div>+ <SecretDiffView+ operationType={operationType}+ oldVersion={oldSecretData}+ newVersion={newSecretData}+ /></div></div>);diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/CommitForm/CommitForm.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/CommitForm/CommitForm.tsxindex 20ad815acd..0ee69146e4 100644--- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/CommitForm/CommitForm.tsx+++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/CommitForm/CommitForm.tsx@@ -55,7 +55,7 @@ const RenderSecretChanges = ({ onDiscard, change }: RenderResourceProps) => {version: 1, // placeholder, not usedsecretKey: change.secretKey,secretValue: change.secretValue,- tags: change.tags,+ tags: change.tags?.map((tag) => tag.slug),secretMetadata: change.secretMetadata,skipMultilineEncoding: change.skipMultilineEncoding,comment: change.secretComment@@ -100,30 +100,27 @@ const RenderSecretChanges = ({ onDiscard, change }: RenderResourceProps) => {versions: [{version: 1, // placeholder, not used- secretKey: change.newSecretName ? existingSecret.key : undefined,- secretValue:- // eslint-disable-next-line no-nested-ternary- change.secretValue !== undefined- ? change.existingSecret.secretValueHidden- ? HIDDEN_SECRET_VALUE_API_MASK- : (change.originalValue ?? "")- : undefined,- tags: change.tags ? (existingSecret.tags?.map((tag) => tag.slug) ?? []) : undefined,- secretMetadata: change.secretMetadata ? existingSecret.secretMetadata : undefined,- skipMultilineEncoding:- typeof change.skipMultilineEncoding === "boolean"- ? existingSecret.skipMultilineEncoding- : undefined,- comment: change.secretComment !== undefined ? existingSecret.comment : undefined+ secretKey: existingSecret.key,+ secretValue: change.existingSecret.secretValueHidden+ ? HIDDEN_SECRET_VALUE_API_MASK+ : (change.originalValue ?? change.secretValue ?? existingSecret.value ?? ""),+ tags: existingSecret.tags?.map((tag) => tag.slug) ?? [],+ secretMetadata: existingSecret.secretMetadata,+ skipMultilineEncoding: existingSecret.skipMultilineEncoding,+ comment: existingSecret.comment},{version: 2, // placeholder, not used- secretKey: change.newSecretName,- secretValue: change.secretValue,- tags: change.tags?.map((tag) => tag.slug),- secretMetadata: change.secretMetadata,- skipMultilineEncoding: change.skipMultilineEncoding,- comment: change.secretComment+ secretKey: change.newSecretName ?? existingSecret.key,+ secretValue: change.secretValue ?? change.originalValue,+ tags:+ change.tags?.map((tag) => tag.slug) ??+ existingSecret.tags?.map((tag) => tag.slug) ??+ [],+ secretMetadata: change.secretMetadata ?? existingSecret.secretMetadata,+ skipMultilineEncoding:+ change.skipMultilineEncoding ?? existingSecret.skipMultilineEncoding,+ comment: change.secretComment ?? existingSecret.comment}]}}