mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 12:27:28 +00:00
feat: made encryption tab hidden for project v2 and v1
This commit is contained in:
@@ -2,18 +2,26 @@ import { Fragment } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Tab } from "@headlessui/react";
|
import { Tab } from "@headlessui/react";
|
||||||
|
|
||||||
|
import { useWorkspace } from "@app/context";
|
||||||
|
import { ProjectVersion } from "@app/hooks/api/workspace/types";
|
||||||
|
|
||||||
import { EncryptionTab } from "./components/EncryptionTab";
|
import { EncryptionTab } from "./components/EncryptionTab";
|
||||||
import { ProjectGeneralTab } from "./components/ProjectGeneralTab";
|
import { ProjectGeneralTab } from "./components/ProjectGeneralTab";
|
||||||
import { WebhooksTab } from "./components/WebhooksTab";
|
import { WebhooksTab } from "./components/WebhooksTab";
|
||||||
|
|
||||||
const tabs = [
|
|
||||||
{ name: "General", key: "tab-project-general" },
|
|
||||||
{ name: "Encryption", key: "tab-project-encryption" },
|
|
||||||
{ name: "Webhooks", key: "tab-project-webhooks" }
|
|
||||||
];
|
|
||||||
|
|
||||||
export const ProjectSettingsPage = () => {
|
export const ProjectSettingsPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { currentWorkspace } = useWorkspace();
|
||||||
|
const tabs = [
|
||||||
|
{ name: "General", key: "tab-project-general" },
|
||||||
|
{
|
||||||
|
name: "Encryption",
|
||||||
|
key: "tab-project-encryption",
|
||||||
|
isHidden: currentWorkspace?.version !== ProjectVersion.V3
|
||||||
|
},
|
||||||
|
{ name: "Webhooks", key: "tab-project-webhooks" }
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full justify-center bg-bunker-800 text-white">
|
<div className="flex h-full w-full justify-center bg-bunker-800 text-white">
|
||||||
<div className="w-full max-w-7xl px-6">
|
<div className="w-full max-w-7xl px-6">
|
||||||
@@ -22,28 +30,32 @@ export const ProjectSettingsPage = () => {
|
|||||||
</div>
|
</div>
|
||||||
<Tab.Group>
|
<Tab.Group>
|
||||||
<Tab.List className="mb-4 w-full border-b-2 border-mineshaft-800">
|
<Tab.List className="mb-4 w-full border-b-2 border-mineshaft-800">
|
||||||
{tabs.map((tab) => (
|
{tabs
|
||||||
<Tab as={Fragment} key={tab.key}>
|
.filter((el) => !el.isHidden)
|
||||||
{({ selected }) => (
|
.map((tab) => (
|
||||||
<button
|
<Tab as={Fragment} key={tab.key}>
|
||||||
type="button"
|
{({ selected }) => (
|
||||||
className={`w-30 mx-2 mr-4 py-2 text-sm font-medium outline-none ${
|
<button
|
||||||
selected ? "border-b border-white text-white" : "text-mineshaft-400"
|
type="button"
|
||||||
}`}
|
className={`w-30 mx-2 mr-4 py-2 text-sm font-medium outline-none ${
|
||||||
>
|
selected ? "border-b border-white text-white" : "text-mineshaft-400"
|
||||||
{tab.name}
|
}`}
|
||||||
</button>
|
>
|
||||||
)}
|
{tab.name}
|
||||||
</Tab>
|
</button>
|
||||||
))}
|
)}
|
||||||
|
</Tab>
|
||||||
|
))}
|
||||||
</Tab.List>
|
</Tab.List>
|
||||||
<Tab.Panels>
|
<Tab.Panels>
|
||||||
<Tab.Panel>
|
<Tab.Panel>
|
||||||
<ProjectGeneralTab />
|
<ProjectGeneralTab />
|
||||||
</Tab.Panel>
|
</Tab.Panel>
|
||||||
<Tab.Panel>
|
{currentWorkspace?.version === ProjectVersion.V3 && (
|
||||||
<EncryptionTab />
|
<Tab.Panel>
|
||||||
</Tab.Panel>
|
<EncryptionTab />
|
||||||
|
</Tab.Panel>
|
||||||
|
)}
|
||||||
<Tab.Panel>
|
<Tab.Panel>
|
||||||
<WebhooksTab />
|
<WebhooksTab />
|
||||||
</Tab.Panel>
|
</Tab.Panel>
|
||||||
|
|||||||
+37
-50
@@ -1,4 +1,4 @@
|
|||||||
import { ChangeEvent, useEffect, useRef, useState } from "react";
|
import { ChangeEvent, useRef, useState } from "react";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { faUpload } from "@fortawesome/free-solid-svg-icons";
|
import { faUpload } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
@@ -234,31 +234,19 @@ export const EncryptionTab = () => {
|
|||||||
"createBackupConfirmation",
|
"createBackupConfirmation",
|
||||||
"loadBackup"
|
"loadBackup"
|
||||||
] as const);
|
] as const);
|
||||||
const [kmsKeyId, setKmsKeyId] = useState("");
|
const kmsKeyId = activeKms?.isExternal ? activeKms.id : INTERNAL_KMS_KEY_ID;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
control,
|
control,
|
||||||
setValue,
|
|
||||||
formState: { isSubmitting, isDirty }
|
formState: { isSubmitting, isDirty }
|
||||||
} = useForm<TForm>({
|
} = useForm<TForm>({
|
||||||
resolver: zodResolver(formSchema)
|
resolver: zodResolver(formSchema),
|
||||||
|
values: {
|
||||||
|
kmsKeyId
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (activeKms) {
|
|
||||||
setKmsKeyId(activeKms.isExternal ? activeKms.id : INTERNAL_KMS_KEY_ID);
|
|
||||||
} else {
|
|
||||||
setKmsKeyId(INTERNAL_KMS_KEY_ID);
|
|
||||||
}
|
|
||||||
}, [activeKms]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (kmsKeyId) {
|
|
||||||
setValue("kmsKeyId", kmsKeyId);
|
|
||||||
}
|
|
||||||
}, [kmsKeyId]);
|
|
||||||
|
|
||||||
const onUpdateProjectKms = async (data: TForm) => {
|
const onUpdateProjectKms = async (data: TForm) => {
|
||||||
try {
|
try {
|
||||||
await updateProjectKms(
|
await updateProjectKms(
|
||||||
@@ -277,10 +265,7 @@ export const EncryptionTab = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<div className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4">
|
||||||
onSubmit={handleSubmit(onUpdateProjectKms)}
|
|
||||||
className="mb-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-4"
|
|
||||||
>
|
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<h2 className="mb-2 flex-1 text-xl font-semibold text-mineshaft-100">Key Management</h2>
|
<h2 className="mb-2 flex-1 text-xl font-semibold text-mineshaft-100">Key Management</h2>
|
||||||
{kmsKeyId !== INTERNAL_KMS_KEY_ID && (
|
{kmsKeyId !== INTERNAL_KMS_KEY_ID && (
|
||||||
@@ -304,34 +289,36 @@ export const EncryptionTab = () => {
|
|||||||
Select which Key Management System to use for encrypting your project data
|
Select which Key Management System to use for encrypting your project data
|
||||||
</p>
|
</p>
|
||||||
<div className="mb-6 max-w-md">
|
<div className="mb-6 max-w-md">
|
||||||
<ProjectPermissionCan I={ProjectPermissionActions.Edit} a={ProjectPermissionSub.Kms}>
|
<form onSubmit={handleSubmit(onUpdateProjectKms)}>
|
||||||
{(isAllowed) => (
|
<ProjectPermissionCan I={ProjectPermissionActions.Edit} a={ProjectPermissionSub.Kms}>
|
||||||
<Controller
|
{(isAllowed) => (
|
||||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
<Controller
|
||||||
<FormControl errorText={error?.message} isError={Boolean(error)}>
|
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||||
<Select
|
<FormControl errorText={error?.message} isError={Boolean(error)}>
|
||||||
{...field}
|
<Select
|
||||||
isDisabled={!isAllowed || isUpdatingProjectKms}
|
{...field}
|
||||||
onValueChange={onChange}
|
isDisabled={!isAllowed || isUpdatingProjectKms}
|
||||||
isLoading={isUpdatingProjectKms}
|
onValueChange={onChange}
|
||||||
className="w-3/4 bg-mineshaft-600"
|
isLoading={isUpdatingProjectKms}
|
||||||
>
|
className="w-3/4 bg-mineshaft-600"
|
||||||
<SelectItem value={INTERNAL_KMS_KEY_ID} key="kms-internal">
|
>
|
||||||
Default Infisical KMS
|
<SelectItem value={INTERNAL_KMS_KEY_ID} key="kms-internal">
|
||||||
</SelectItem>
|
Default Infisical KMS
|
||||||
{externalKmsList?.map((kms) => (
|
|
||||||
<SelectItem value={kms.id} key={`kms-${kms.id}`}>
|
|
||||||
{kms.slug}
|
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
{externalKmsList?.map((kms) => (
|
||||||
</Select>
|
<SelectItem value={kms.id} key={`kms-${kms.id}`}>
|
||||||
</FormControl>
|
{kms.slug}
|
||||||
)}
|
</SelectItem>
|
||||||
control={control}
|
))}
|
||||||
name="kmsKeyId"
|
</Select>
|
||||||
/>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
</ProjectPermissionCan>
|
control={control}
|
||||||
|
name="kmsKeyId"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</ProjectPermissionCan>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<ProjectPermissionCan I={ProjectPermissionActions.Edit} a={ProjectPermissionSub.Workspace}>
|
<ProjectPermissionCan I={ProjectPermissionActions.Edit} a={ProjectPermissionSub.Workspace}>
|
||||||
{(isAllowed) => (
|
{(isAllowed) => (
|
||||||
@@ -357,6 +344,6 @@ export const EncryptionTab = () => {
|
|||||||
org={currentOrg}
|
org={currentOrg}
|
||||||
workspace={currentWorkspace}
|
workspace={currentWorkspace}
|
||||||
/>
|
/>
|
||||||
</form>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user