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
fix(overview): preserve focus when autosaving pending secrets (#8928)
Andrew Huang1ee297d1613a
diff --git a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsxindex 037fa153cf..15a52c7d9d 100644--- a/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/OverviewPage.tsx@@ -1474,6 +1474,7 @@ const OverviewPageContent = () => {isSingleEnvView && (pendingChanges.secrets.length > 0 || pendingChanges.folders.length > 0);const [recentQuickAddKeys, setRecentQuickAddKeys] = useState<string[]>([]);+ const pendingSecretRowKeys = useRef(new Map<string, string>());const hadPendingBatchChangesRef = useRef(hasPendingBatchChanges);const isRecentQuickAddClearPendingRef = useRef(false);useEffect(() => {@@ -2367,6 +2368,15 @@ const OverviewPageContent = () => {);if (!pendingCreate) return;+ if (newSecretName && newSecretName !== key) {+ pendingSecretRowKeys.current.delete(+ overviewRowKey("secret", projectId, env, secretPath, key)+ );+ pendingSecretRowKeys.current.set(+ overviewRowKey("secret", projectId, env, secretPath, newSecretName),+ pendingCreate.id+ );+ }addPendingChange({...pendingCreate,@@ -3005,6 +3015,16 @@ const OverviewPageContent = () => {"","row");+ const [createdSecret] = appliedSecrets;+ if (pendingSecret.type === PendingAction.Create && createdSecret) {+ pendingSecretRowKeys.current.forEach((rowId, identity) => {+ if (rowId === pendingSecret.id) pendingSecretRowKeys.current.delete(identity);+ });+ pendingSecretRowKeys.current.set(+ overviewRowKey("secret", projectId, env, secretPath, createdSecret.secretKey),+ pendingSecret.id+ );+ }const context = { projectId, environment: env, secretPath };const draft = batchStoreApi.getState()@@ -3042,7 +3062,6 @@ const OverviewPageContent = () => {return;}- const [createdSecret] = appliedSecrets;if (pendingSecret.type !== PendingAction.Create ||draft?.type !== PendingAction.Create ||@@ -3638,6 +3657,17 @@ const OverviewPageContent = () => {</button>);+ const getSecretRowKey = (key: string, rowKey: string) => {+ if (!singleVisibleEnv) return rowKey;++ const identity = overviewRowKey("secret", projectId, singleVisibleEnv.slug, secretPath, key);+ const pendingCreate = pendingChanges.secrets.find(+ (change) => change.type === PendingAction.Create && change.secretKey === key+ );+ if (pendingCreate) pendingSecretRowKeys.current.set(identity, pendingCreate.id);+ return pendingSecretRowKeys.current.get(identity) ?? rowKey;+ };+const renderSecretRow = (key: string, rowKey: string) => (<SecretTableRowisSelected={!hasPendingBatchChanges && Boolean(selectedEntries.secret[key])}@@ -3654,7 +3684,7 @@ const OverviewPageContent = () => {onSecretCreate={handleSecretCreate}onSecretDelete={handleSecretDelete}onSecretUpdate={handleSecretUpdate}- key={rowKey}+ key={getSecretRowKey(key, rowKey)}environments={visibleEnvs}secretKey={key}getSecretByKey={getSecretByKeyWithPending}@@ -3669,7 +3699,7 @@ const OverviewPageContent = () => {intent: SecretAccessInsightsUpgradeIntent})}- activityId={getTableRowActivityId("secret", key)}+ activityId={getTableRowActivityId("secret", getSecretRowKey(key, rowKey))}onActivityChange={handleTableRowActivityChange}timestampSortField={isTimestampSort ? orderBy : undefined}/>diff --git a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsxindex fc5d125fb3..32e0ae08fa 100644--- a/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx+++ b/frontend/src/pages/secret-manager/OverviewPage/components/SecretTableRow/SecretEditTableRow.tsx@@ -252,6 +252,7 @@ export const SecretEditTableRow = ({const isPendingBatchChange = isBatchMode && hasPendingChange;const [isFieldFocused, setIsFieldFocused] = useToggle();+ const [isNameTooltipOpen, setIsNameTooltipOpen] = useState(false);const [isResolvedValueOpen, setIsResolvedValueOpen] = useToggle();const isFieldActive = isFieldFocused || isResolvedValueOpen;const [isCopied, , setIsCopied] = useTimedReset<boolean>({ initialState: false });@@ -506,11 +507,11 @@ export const SecretEditTableRow = ({tags: unknown;metadata: unknown;}>({- value: undefined,- key: undefined,- comment: undefined,- tags: undefined,- metadata: undefined+ value: isPendingCreate ? watchedValue : undefined,+ key: isPendingCreate ? watchedKey : undefined,+ comment: isPendingCreate ? watchedComment : undefined,+ tags: isPendingCreate ? watchedTags : undefined,+ metadata: isPendingCreate ? watchedMetadata : undefined});const areTagsEqual = (a: { id: string; slug: string }[], b: { id: string; slug: string }[]) => {@@ -587,7 +588,14 @@ export const SecretEditTableRow = ({!areMetadataEqual(watchedMetadata, originalMetadataRef.current);// If nothing changed from original, remove pending change directly- if (!isValueChanged && !isKeyDirty && !isCommentDirty && !isTagsDirty && !isMetadataDirty) {+ if (+ !isPendingCreate &&+ !isValueChanged &&+ !isKeyDirty &&+ !isCommentDirty &&+ !isTagsDirty &&+ !isMetadataDirty+ ) {if (lastAppliedRef.current.value !== undefined) {onBatchRevert?.(environment, secretName);lastAppliedRef.current = {@@ -640,6 +648,7 @@ export const SecretEditTableRow = ({// If only the key was dirty and it conflicted, reset key back and bailif (+ !isPendingCreate &&!isValueChanged &&!effectiveKeyDirty &&!isCommentDirty &&@@ -687,14 +696,14 @@ export const SecretEditTableRow = ({onSecretUpdate({env: environment,key: secretName,- value: isValueChanged ? ((watchedValue as string) ?? "") : undefined,+ value: isPendingCreate || isValueChanged ? ((watchedValue as string) ?? "") : undefined,secretValueHidden,type: SecretType.Shared,secretId,newSecretName: effectiveKeyDirty ? (watchedKey as string) : undefined,- secretComment: isCommentDirty ? (watchedComment as string) : undefined,- tags: isTagsDirty ? watchedTags : undefined,- secretMetadata: isMetadataDirty ? watchedMetadata : undefined,+ secretComment: isPendingCreate || isCommentDirty ? (watchedComment as string) : undefined,+ tags: isPendingCreate || isTagsDirty ? watchedTags : undefined,+ secretMetadata: isPendingCreate || isMetadataDirty ? watchedMetadata : undefined,originalValue: originalValueRef.current ?? undefined});}@@ -1204,7 +1213,8 @@ export const SecretEditTableRow = ({<TooltipdelayDuration={1000}skipDelayDuration={0}- open={isFieldFocused || !field.value ? false : undefined}+ open={isNameTooltipOpen && !isFieldFocused && Boolean(field.value)}+ onOpenChange={(open) => setIsNameTooltipOpen(open && !isFieldFocused)}><TooltipTrigger asChild><Input@@ -1226,12 +1236,16 @@ export const SecretEditTableRow = ({: event.currentTarget.value;field.onChange(value);}}- onFocus={() => setIsFieldFocused.on()}+ onFocus={() => {+ setIsNameTooltipOpen(false);+ setIsFieldFocused.on();+ }}onKeyDown={handleEditShortcut}onScroll={(e) => {if (document.activeElement !== e.currentTarget) e.currentTarget.scrollLeft = 0;}}onBlur={(e) => {+ setIsNameTooltipOpen(false);e.currentTarget.scrollLeft = 0;field.onBlur();if (!isBatchMode && field.onChange) field.onChange(e);