Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

UI: invalidate queries to avoid refresh when getting into the overview page after a approval and merge operation

adilsonda7f71eb7ff4
diff --git a/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx b/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx
index fb90469f4b..deda3e9276 100644
--- a/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx
+++ b/frontend/src/hooks/api/secretApprovalRequest/mutation.tsx
@@ -2,6 +2,10 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
+import { dashboardKeys } from "../dashboard/queries";
+import { commitKeys } from "../folderCommits/queries";
+import { secretKeys } from "../secrets/queries";
+import { secretSnapshotKeys } from "../secretSnapshots/queries";
import { secretApprovalRequestKeys } from "./queries";
import {
TPerformSecretApprovalRequestMerge,
@@ -60,12 +64,36 @@ export const usePerformSecretApprovalRequestMerge = () => {
});
return data;
},
- onSuccess: (_, { id, projectId }) => {
+ onSuccess: (_, { id, projectId, environment, secretPath }) => {
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.detail({ id }) });
queryClient.invalidateQueries({
queryKey: secretApprovalRequestKeys.listAllForProject({ projectId })
});
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
+ queryClient.invalidateQueries({
+ queryKey: dashboardKeys.getDashboardSecrets({ projectId, secretPath })
+ });
+ queryClient.invalidateQueries({
+ predicate: (query) =>
+ (query.queryKey[0] as { projectId?: string })?.projectId === projectId &&
+ (query.queryKey[1] === "secrets-import-sec" ||
+ query.queryKey[1] === "imported-folders-all-envs")
+ });
+ queryClient.invalidateQueries({
+ queryKey: secretKeys.getProjectSecret({ projectId, environment, secretPath })
+ });
+ queryClient.invalidateQueries({
+ queryKey: secretSnapshotKeys.list({ environment, projectId, directory: secretPath })
+ });
+ queryClient.invalidateQueries({
+ queryKey: secretSnapshotKeys.count({ environment, projectId, directory: secretPath })
+ });
+ queryClient.invalidateQueries({
+ queryKey: commitKeys.count({ projectId, environment, directory: secretPath })
+ });
+ queryClient.invalidateQueries({
+ queryKey: commitKeys.history({ projectId, environment, directory: secretPath })
+ });
}
});
};
diff --git a/frontend/src/hooks/api/secretApprovalRequest/types.ts b/frontend/src/hooks/api/secretApprovalRequest/types.ts
index 498d833dba..de6ee72844 100644
--- a/frontend/src/hooks/api/secretApprovalRequest/types.ts
+++ b/frontend/src/hooks/api/secretApprovalRequest/types.ts
@@ -152,5 +152,7 @@ export type TUpdateSecretApprovalRequestStatusDTO = {
export type TPerformSecretApprovalRequestMerge = {
id: string;
projectId: string;
+ environment: string;
+ secretPath: string;
bypassReason?: string;
};
diff --git a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestAction.tsx b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestAction.tsx
index e0585dee4c..d018c1ef23 100644
--- a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestAction.tsx
+++ b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestAction.tsx
@@ -44,6 +44,8 @@ type Props = {
statusChangeByEmail?: string;
enforcementLevel: EnforcementLevel;
bypassReason?: string | null;
+ environment: string;
+ secretPath: string;
};
export const SecretApprovalRequestAction = ({
@@ -57,7 +59,9 @@ export const SecretApprovalRequestAction = ({
canApprove,
isCommitter,
isBypasser,
- bypassReason
+ bypassReason,
+ environment,
+ secretPath
}: Props) => {
const { projectId } = useProject();
const { mutateAsync: performSecretApprovalMerge, isPending: isMerging } =
@@ -75,6 +79,8 @@ export const SecretApprovalRequestAction = ({
await performSecretApprovalMerge({
id: approvalRequestId,
projectId,
+ environment,
+ secretPath,
bypassReason: byPassApproval ? bypassReasonInput : undefined
});
createNotification({
diff --git a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx
index e955064e88..de6cd0537f 100644
--- a/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx
+++ b/frontend/src/pages/secret-manager/SecretApprovalsPage/components/SecretApprovalRequest/components/SecretApprovalRequestChanges.tsx
@@ -205,7 +205,12 @@ export const SecretApprovalRequestChanges = ({
try {
setWillMerge(true);
await handleReview(ApprovalStatus.APPROVED);
- await performSecretApprovalMerge({ projectId, id: secretApprovalRequestDetails.id });
+ await performSecretApprovalMerge({
+ projectId,
+ id: secretApprovalRequestDetails.id,
+ environment: secretApprovalRequestDetails.environment,
+ secretPath: secretApprovalRequestDetails.secretPath
+ });
} catch {
// Approval or merge failed, error already shown via mutation
} finally {
@@ -684,6 +689,8 @@ export const SecretApprovalRequestChanges = ({
statusChangeByEmail={secretApprovalRequestDetails.statusChangedByUser?.email}
enforcementLevel={secretApprovalRequestDetails.policy.enforcementLevel}
bypassReason={secretApprovalRequestDetails.bypassReason}
+ environment={secretApprovalRequestDetails.environment}
+ secretPath={secretApprovalRequestDetails.secretPath}
/>
</SheetFooter>
)}