mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 22:27:22 +00:00
Merge pull request #2182 from LemmyMwaura/delete-secret-modal
feat: add confirm step (modal) before deleting a secret
This commit is contained in:
+21
-4
@@ -1,3 +1,4 @@
|
|||||||
|
import { useState, useCallback } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { subject } from "@casl/ability";
|
import { subject } from "@casl/ability";
|
||||||
import { faCheck, faCopy, faTrash, faXmark } from "@fortawesome/free-solid-svg-icons";
|
import { faCheck, faCopy, faTrash, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||||
@@ -6,7 +7,7 @@ import { twMerge } from "tailwind-merge";
|
|||||||
|
|
||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||||
import { IconButton, Tooltip } from "@app/components/v2";
|
import { IconButton, Tooltip, DeleteActionModal } from "@app/components/v2";
|
||||||
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
import { InfisicalSecretInput } from "@app/components/v2/InfisicalSecretInput";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
|
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";
|
||||||
import { useToggle } from "@app/hooks";
|
import { useToggle } from "@app/hooks";
|
||||||
@@ -59,6 +60,11 @@ export const SecretEditRow = ({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
const [isDeleting, setIsDeleting] = useToggle();
|
const [isDeleting, setIsDeleting] = useToggle();
|
||||||
|
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
|
const toggleModal = useCallback(() => {
|
||||||
|
setIsModalOpen((prev) => !prev)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const handleFormReset = () => {
|
const handleFormReset = () => {
|
||||||
reset();
|
reset();
|
||||||
@@ -94,18 +100,29 @@ export const SecretEditRow = ({
|
|||||||
reset({ value });
|
reset({ value });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteSecret = async () => {
|
const handleDeleteSecret = useCallback(async () => {
|
||||||
setIsDeleting.on();
|
setIsDeleting.on();
|
||||||
|
setIsModalOpen(false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await onSecretDelete(environment, secretName, secretId);
|
await onSecretDelete(environment, secretName, secretId);
|
||||||
reset({ value: null });
|
reset({ value: null });
|
||||||
} finally {
|
} finally {
|
||||||
setIsDeleting.off();
|
setIsDeleting.off();
|
||||||
}
|
}
|
||||||
};
|
}, [onSecretDelete, environment, secretName, secretId, reset, setIsDeleting]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group flex w-full cursor-text items-center space-x-2">
|
<div className="group flex w-full cursor-text items-center space-x-2">
|
||||||
|
|
||||||
|
<DeleteActionModal
|
||||||
|
isOpen={isModalOpen}
|
||||||
|
onClose={toggleModal}
|
||||||
|
title="Do you want to delete the selected secret?"
|
||||||
|
deleteKey="delete"
|
||||||
|
onDeleteApproved={handleDeleteSecret}
|
||||||
|
/>
|
||||||
|
|
||||||
<div className="flex-grow border-r border-r-mineshaft-600 pr-2 pl-1">
|
<div className="flex-grow border-r border-r-mineshaft-600 pr-2 pl-1">
|
||||||
<Controller
|
<Controller
|
||||||
disabled={isImportedSecret && !defaultValue}
|
disabled={isImportedSecret && !defaultValue}
|
||||||
@@ -193,7 +210,7 @@ export const SecretEditRow = ({
|
|||||||
variant="plain"
|
variant="plain"
|
||||||
ariaLabel="delete-value"
|
ariaLabel="delete-value"
|
||||||
className="h-full"
|
className="h-full"
|
||||||
onClick={handleDeleteSecret}
|
onClick={toggleModal}
|
||||||
isDisabled={isDeleting || !isAllowed}
|
isDisabled={isDeleting || !isAllowed}
|
||||||
>
|
>
|
||||||
<FontAwesomeIcon icon={faTrash} />
|
<FontAwesomeIcon icon={faTrash} />
|
||||||
|
|||||||
@@ -49,8 +49,9 @@ export const SelectionPanel = ({
|
|||||||
"bulkDeleteEntries"
|
"bulkDeleteEntries"
|
||||||
] as const);
|
] as const);
|
||||||
|
|
||||||
const selectedCount =
|
const selectedFolderCount = Object.keys(selectedEntries.folder).length
|
||||||
Object.keys(selectedEntries.folder).length + Object.keys(selectedEntries.secret).length;
|
const selectedKeysCount = Object.keys(selectedEntries.secret).length
|
||||||
|
const selectedCount = selectedFolderCount + selectedKeysCount
|
||||||
|
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace } = useWorkspace();
|
||||||
const workspaceId = currentWorkspace?.id || "";
|
const workspaceId = currentWorkspace?.id || "";
|
||||||
@@ -68,6 +69,16 @@ export const SelectionPanel = ({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getDeleteModalTitle = () => {
|
||||||
|
if (selectedFolderCount > 0 && selectedKeysCount > 0) {
|
||||||
|
return "Do you want to delete the selected secrets and folders across environments?";
|
||||||
|
} else if (selectedKeysCount > 0 && selectedFolderCount === 0) {
|
||||||
|
return "Do you want to delete the selected secrets across environments?";
|
||||||
|
} else {
|
||||||
|
return "Do you want to delete the selected folders across environments?";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleBulkDelete = async () => {
|
const handleBulkDelete = async () => {
|
||||||
let processedEntries = 0;
|
let processedEntries = 0;
|
||||||
|
|
||||||
@@ -180,7 +191,7 @@ export const SelectionPanel = ({
|
|||||||
<DeleteActionModal
|
<DeleteActionModal
|
||||||
isOpen={popUp.bulkDeleteEntries.isOpen}
|
isOpen={popUp.bulkDeleteEntries.isOpen}
|
||||||
deleteKey="delete"
|
deleteKey="delete"
|
||||||
title="Do you want to delete the selected secrets and folders across envs?"
|
title={getDeleteModalTitle()}
|
||||||
onChange={(isOpen) => handlePopUpToggle("bulkDeleteEntries", isOpen)}
|
onChange={(isOpen) => handlePopUpToggle("bulkDeleteEntries", isOpen)}
|
||||||
onDeleteApproved={handleBulkDelete}
|
onDeleteApproved={handleBulkDelete}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user