mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-10 17:29:14 +00:00
feat: integrate overview folder rename with new batch endpoint
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
TGetFoldersByEnvDTO,
|
TGetFoldersByEnvDTO,
|
||||||
TGetProjectFoldersDTO,
|
TGetProjectFoldersDTO,
|
||||||
TSecretFolder,
|
TSecretFolder,
|
||||||
|
TUpdateFolderBatchDTO,
|
||||||
TUpdateFolderDTO
|
TUpdateFolderDTO
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
@@ -190,3 +191,43 @@ export const useDeleteFolder = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useUpdateFolderBatch = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation<{}, {}, TUpdateFolderBatchDTO>({
|
||||||
|
mutationFn: async ({ projectId, folders }) => {
|
||||||
|
const { data } = await apiRequest.patch("/api/v1/folders/batch", {
|
||||||
|
folders,
|
||||||
|
workspaceId: projectId
|
||||||
|
});
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
onSuccess: (_, { projectId, folders }) => {
|
||||||
|
folders.forEach((folder) => {
|
||||||
|
queryClient.invalidateQueries(
|
||||||
|
folderQueryKeys.getSecretFolders({
|
||||||
|
projectId,
|
||||||
|
environment: folder.environment,
|
||||||
|
path: folder.path
|
||||||
|
})
|
||||||
|
);
|
||||||
|
queryClient.invalidateQueries(
|
||||||
|
secretSnapshotKeys.list({
|
||||||
|
workspaceId: projectId,
|
||||||
|
environment: folder.environment,
|
||||||
|
directory: folder.path
|
||||||
|
})
|
||||||
|
);
|
||||||
|
queryClient.invalidateQueries(
|
||||||
|
secretSnapshotKeys.count({
|
||||||
|
workspaceId: projectId,
|
||||||
|
environment: folder.environment,
|
||||||
|
directory: folder.path
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -36,3 +36,13 @@ export type TDeleteFolderDTO = {
|
|||||||
folderId: string;
|
folderId: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TUpdateFolderBatchDTO = {
|
||||||
|
projectId: string;
|
||||||
|
folders: {
|
||||||
|
name: string;
|
||||||
|
environment: string;
|
||||||
|
id: string;
|
||||||
|
path?: string;
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ import {
|
|||||||
useGetImportedSecretsAllEnvs,
|
useGetImportedSecretsAllEnvs,
|
||||||
useGetProjectSecretsAllEnv,
|
useGetProjectSecretsAllEnv,
|
||||||
useGetUserWsKey,
|
useGetUserWsKey,
|
||||||
useUpdateFolder,
|
|
||||||
useUpdateSecretV3
|
useUpdateSecretV3
|
||||||
} from "@app/hooks/api";
|
} from "@app/hooks/api";
|
||||||
|
import { useUpdateFolderBatch } from "@app/hooks/api/secretFolders/queries";
|
||||||
|
import { TUpdateFolderBatchDTO } from "@app/hooks/api/secretFolders/types";
|
||||||
import { TSecretFolder } from "@app/hooks/api/types";
|
import { TSecretFolder } from "@app/hooks/api/types";
|
||||||
import { ProjectVersion } from "@app/hooks/api/workspace/types";
|
import { ProjectVersion } from "@app/hooks/api/workspace/types";
|
||||||
|
|
||||||
@@ -205,7 +206,7 @@ export const SecretOverviewPage = () => {
|
|||||||
const { mutateAsync: updateSecretV3 } = useUpdateSecretV3();
|
const { mutateAsync: updateSecretV3 } = useUpdateSecretV3();
|
||||||
const { mutateAsync: deleteSecretV3 } = useDeleteSecretV3();
|
const { mutateAsync: deleteSecretV3 } = useDeleteSecretV3();
|
||||||
const { mutateAsync: createFolder } = useCreateFolder();
|
const { mutateAsync: createFolder } = useCreateFolder();
|
||||||
const { mutateAsync: updateFolder } = useUpdateFolder();
|
const { mutateAsync: updateFolderBatch } = useUpdateFolderBatch();
|
||||||
|
|
||||||
const { handlePopUpOpen, handlePopUpToggle, handlePopUpClose, popUp } = usePopUp([
|
const { handlePopUpOpen, handlePopUpToggle, handlePopUpClose, popUp } = usePopUp([
|
||||||
"addSecretsInAllEnvs",
|
"addSecretsInAllEnvs",
|
||||||
@@ -244,60 +245,54 @@ export const SecretOverviewPage = () => {
|
|||||||
|
|
||||||
const handleFolderUpdate = async (newFolderName: string) => {
|
const handleFolderUpdate = async (newFolderName: string) => {
|
||||||
const { name: oldFolderName } = popUp.updateFolder.data as TSecretFolder;
|
const { name: oldFolderName } = popUp.updateFolder.data as TSecretFolder;
|
||||||
let processedUpdates = 0;
|
|
||||||
let totalFolderMatchCount = 0;
|
|
||||||
|
|
||||||
await Promise.allSettled(
|
|
||||||
userAvailableEnvs.map(async (env) => {
|
|
||||||
if (
|
|
||||||
permission.cannot(
|
|
||||||
ProjectPermissionActions.Edit,
|
|
||||||
subject(ProjectPermissionSub.Secrets, { environment: env.slug, secretPath })
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const updatedFolders: TUpdateFolderBatchDTO["folders"] = [];
|
||||||
|
userAvailableEnvs.forEach((env) => {
|
||||||
|
if (
|
||||||
|
permission.can(
|
||||||
|
ProjectPermissionActions.Edit,
|
||||||
|
subject(ProjectPermissionSub.Secrets, { environment: env.slug, secretPath })
|
||||||
|
)
|
||||||
|
) {
|
||||||
const folder = getFolderByNameAndEnv(oldFolderName, env.slug);
|
const folder = getFolderByNameAndEnv(oldFolderName, env.slug);
|
||||||
if (folder) {
|
if (folder) {
|
||||||
totalFolderMatchCount += 1;
|
updatedFolders.push({
|
||||||
|
|
||||||
await updateFolder({
|
|
||||||
folderId: folder.id,
|
|
||||||
name: newFolderName,
|
|
||||||
path: secretPath,
|
|
||||||
environment: env.slug,
|
environment: env.slug,
|
||||||
projectId: workspaceId
|
name: newFolderName,
|
||||||
|
id: folder.id,
|
||||||
|
path: secretPath
|
||||||
});
|
});
|
||||||
|
|
||||||
processedUpdates += 1;
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
if (totalFolderMatchCount === 0) {
|
if (updatedFolders.length === 0) {
|
||||||
createNotification({
|
createNotification({
|
||||||
type: "info",
|
type: "info",
|
||||||
text: "You don't have access to rename selected folder"
|
text: "You don't have access to rename selected folder"
|
||||||
});
|
});
|
||||||
} else if (processedUpdates === totalFolderMatchCount) {
|
|
||||||
|
handlePopUpClose("updateFolder");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await updateFolderBatch({
|
||||||
|
projectId: workspaceId,
|
||||||
|
folders: updatedFolders
|
||||||
|
});
|
||||||
createNotification({
|
createNotification({
|
||||||
type: "success",
|
type: "success",
|
||||||
text: "Successfully renamed folder across environments"
|
text: "Successfully renamed folder across environments"
|
||||||
});
|
});
|
||||||
} else if (processedUpdates > 0) {
|
} catch (err) {
|
||||||
createNotification({
|
|
||||||
type: "warning",
|
|
||||||
text: "Partially renamed folder across environments"
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
createNotification({
|
createNotification({
|
||||||
type: "error",
|
type: "error",
|
||||||
text: "Failed to rename folder across environments"
|
text: "Failed to rename folder across environments"
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
handlePopUpClose("updateFolder");
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePopUpClose("updateFolder");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSecretCreate = async (env: string, key: string, value: string) => {
|
const handleSecretCreate = async (env: string, key: string, value: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user