mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 21:27:31 +00:00
Fix: Improved UI import indicators
This commit is contained in:
@@ -14,7 +14,8 @@ const replaceContentWithDot = (str: string) => {
|
|||||||
return finalStr;
|
return finalStr;
|
||||||
};
|
};
|
||||||
|
|
||||||
const syntaxHighlight = (content?: string | null, isVisible?: boolean) => {
|
const syntaxHighlight = (content?: string | null, isVisible?: boolean, isImport?: boolean) => {
|
||||||
|
if (isImport) return "IMPORTED";
|
||||||
if (content === "") return "EMPTY";
|
if (content === "") return "EMPTY";
|
||||||
if (!content) return "EMPTY";
|
if (!content) return "EMPTY";
|
||||||
if (!isVisible) return replaceContentWithDot(content);
|
if (!isVisible) return replaceContentWithDot(content);
|
||||||
@@ -46,6 +47,7 @@ const syntaxHighlight = (content?: string | null, isVisible?: boolean) => {
|
|||||||
type Props = TextareaHTMLAttributes<HTMLTextAreaElement> & {
|
type Props = TextareaHTMLAttributes<HTMLTextAreaElement> & {
|
||||||
value?: string | null;
|
value?: string | null;
|
||||||
isVisible?: boolean;
|
isVisible?: boolean;
|
||||||
|
isImport?: boolean;
|
||||||
isReadOnly?: boolean;
|
isReadOnly?: boolean;
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
containerClassName?: string;
|
containerClassName?: string;
|
||||||
@@ -55,7 +57,17 @@ const commonClassName = "font-mono text-sm caret-white border-none outline-none
|
|||||||
|
|
||||||
export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
|
export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
|
||||||
(
|
(
|
||||||
{ value, isVisible, containerClassName, onBlur, isDisabled, isReadOnly, onFocus, ...props },
|
{
|
||||||
|
value,
|
||||||
|
isVisible,
|
||||||
|
isImport,
|
||||||
|
containerClassName,
|
||||||
|
onBlur,
|
||||||
|
isDisabled,
|
||||||
|
isReadOnly,
|
||||||
|
onFocus,
|
||||||
|
...props
|
||||||
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
const [isSecretFocused, setIsSecretFocused] = useToggle();
|
const [isSecretFocused, setIsSecretFocused] = useToggle();
|
||||||
@@ -69,7 +81,7 @@ export const SecretInput = forwardRef<HTMLTextAreaElement, Props>(
|
|||||||
<pre aria-hidden className="m-0 ">
|
<pre aria-hidden className="m-0 ">
|
||||||
<code className={`inline-block w-full ${commonClassName}`}>
|
<code className={`inline-block w-full ${commonClassName}`}>
|
||||||
<span style={{ whiteSpace: "break-spaces" }}>
|
<span style={{ whiteSpace: "break-spaces" }}>
|
||||||
{syntaxHighlight(value, isVisible || isSecretFocused)}
|
{syntaxHighlight(value, isVisible || isSecretFocused, isImport)}
|
||||||
</span>
|
</span>
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
@@ -269,8 +269,8 @@ export const useGetImportedSecretsAllEnvs = ({
|
|||||||
|
|
||||||
if (selectedEnvIndex !== -1) {
|
if (selectedEnvIndex !== -1) {
|
||||||
const isPresent = secretImports?.[selectedEnvIndex]?.data?.find(
|
const isPresent = secretImports?.[selectedEnvIndex]?.data?.find(
|
||||||
({ secretPath, ...rest }) =>
|
({ secretPath, secrets }) =>
|
||||||
secretPath === secPath && rest.secrets.some((s) => s.key === secretName)
|
secretPath === secPath && secrets.some((s) => s.key === secretName)
|
||||||
);
|
);
|
||||||
|
|
||||||
return Boolean(isPresent);
|
return Boolean(isPresent);
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import {
|
|||||||
useCreateSecretV3,
|
useCreateSecretV3,
|
||||||
useDeleteSecretV3,
|
useDeleteSecretV3,
|
||||||
useGetFoldersByEnv,
|
useGetFoldersByEnv,
|
||||||
useGetImportedFoldersByEnv,
|
|
||||||
useGetImportedSecretsAllEnvs,
|
useGetImportedSecretsAllEnvs,
|
||||||
useGetProjectSecretsAllEnv,
|
useGetProjectSecretsAllEnv,
|
||||||
useGetUserWsKey,
|
useGetUserWsKey,
|
||||||
@@ -133,11 +132,6 @@ export const SecretOverviewPage = () => {
|
|||||||
environments: userAvailableEnvs.map(({ slug }) => slug)
|
environments: userAvailableEnvs.map(({ slug }) => slug)
|
||||||
});
|
});
|
||||||
|
|
||||||
const { isImportedFolderPresentInEnv } = useGetImportedFoldersByEnv({
|
|
||||||
projectId: workspaceId,
|
|
||||||
environments: userAvailableEnvs.map(({ slug }) => slug)
|
|
||||||
});
|
|
||||||
|
|
||||||
const { isImportedSecretPresentInEnv } = useGetImportedSecretsAllEnvs({
|
const { isImportedSecretPresentInEnv } = useGetImportedSecretsAllEnvs({
|
||||||
projectId: workspaceId,
|
projectId: workspaceId,
|
||||||
decryptFileKey: latestFileKey!,
|
decryptFileKey: latestFileKey!,
|
||||||
@@ -652,7 +646,6 @@ export const SecretOverviewPage = () => {
|
|||||||
<SecretOverviewFolderRow
|
<SecretOverviewFolderRow
|
||||||
folderName={folderName}
|
folderName={folderName}
|
||||||
isFolderPresentInEnv={isFolderPresentInEnv}
|
isFolderPresentInEnv={isFolderPresentInEnv}
|
||||||
isImportedFolderPresentInEnv={isImportedFolderPresentInEnv}
|
|
||||||
environments={visibleEnvs}
|
environments={visibleEnvs}
|
||||||
key={`overview-${folderName}-${index + 1}`}
|
key={`overview-${folderName}-${index + 1}`}
|
||||||
onClick={handleFolderClick}
|
onClick={handleFolderClick}
|
||||||
|
|||||||
+11
-18
@@ -1,14 +1,13 @@
|
|||||||
import { faCheck, faFileImport, faFolder, faXmark } from "@fortawesome/free-solid-svg-icons";
|
import { faCheck, faFolder, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { twMerge } from "tailwind-merge";
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
import { Td, Tooltip, Tr } from "@app/components/v2";
|
import { Td, Tr } from "@app/components/v2";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
folderName: string;
|
folderName: string;
|
||||||
environments: { name: string; slug: string }[];
|
environments: { name: string; slug: string }[];
|
||||||
isFolderPresentInEnv: (name: string, env: string) => boolean;
|
isFolderPresentInEnv: (name: string, env: string) => boolean;
|
||||||
isImportedFolderPresentInEnv: (name: string, env: string) => boolean;
|
|
||||||
onClick: (path: string) => void;
|
onClick: (path: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ export const SecretOverviewFolderRow = ({
|
|||||||
folderName,
|
folderName,
|
||||||
environments = [],
|
environments = [],
|
||||||
isFolderPresentInEnv,
|
isFolderPresentInEnv,
|
||||||
isImportedFolderPresentInEnv,
|
|
||||||
onClick
|
onClick
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
return (
|
return (
|
||||||
@@ -31,27 +30,21 @@ export const SecretOverviewFolderRow = ({
|
|||||||
</Td>
|
</Td>
|
||||||
{environments.map(({ slug }, i) => {
|
{environments.map(({ slug }, i) => {
|
||||||
const isPresent = isFolderPresentInEnv(folderName, slug);
|
const isPresent = isFolderPresentInEnv(folderName, slug);
|
||||||
const isImportPresent = isImportedFolderPresentInEnv(folderName, slug);
|
|
||||||
return (
|
return (
|
||||||
<Td
|
<Td
|
||||||
key={`sec-overview-${slug}-${i + 1}-folder`}
|
key={`sec-overview-${slug}-${i + 1}-folder`}
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
"border-r border-mineshaft-600 py-3 group-hover:bg-mineshaft-700",
|
"border-r border-mineshaft-600 py-3 group-hover:bg-mineshaft-700",
|
||||||
isPresent || isImportPresent ? "text-green-600" : "text-red-600"
|
isPresent ? "text-green-600" : "text-red-600"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<div className="flex justify-center">
|
||||||
center
|
<FontAwesomeIcon
|
||||||
isDisabled={!isImportPresent}
|
// eslint-disable-next-line no-nested-ternary
|
||||||
content="Folder is imported from another environment"
|
icon={isPresent ? faCheck : faXmark}
|
||||||
>
|
/>
|
||||||
<div className="flex justify-center">
|
</div>
|
||||||
<FontAwesomeIcon
|
|
||||||
// eslint-disable-next-line no-nested-ternary
|
|
||||||
icon={isPresent ? faCheck : isImportPresent ? faFileImport : faXmark}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</Tooltip>
|
|
||||||
</Td>
|
</Td>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
+16
-2
@@ -2,6 +2,7 @@ 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";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { twMerge } from "tailwind-merge";
|
||||||
|
|
||||||
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||||
@@ -15,6 +16,7 @@ type Props = {
|
|||||||
secretId?: string;
|
secretId?: string;
|
||||||
isCreatable?: boolean;
|
isCreatable?: boolean;
|
||||||
isVisible?: boolean;
|
isVisible?: boolean;
|
||||||
|
isImportedSecret: boolean;
|
||||||
environment: string;
|
environment: string;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
onSecretCreate: (env: string, key: string, value: string) => Promise<void>;
|
onSecretCreate: (env: string, key: string, value: string) => Promise<void>;
|
||||||
@@ -25,6 +27,7 @@ type Props = {
|
|||||||
export const SecretEditRow = ({
|
export const SecretEditRow = ({
|
||||||
defaultValue,
|
defaultValue,
|
||||||
isCreatable,
|
isCreatable,
|
||||||
|
isImportedSecret,
|
||||||
onSecretUpdate,
|
onSecretUpdate,
|
||||||
secretName,
|
secretName,
|
||||||
onSecretCreate,
|
onSecretCreate,
|
||||||
@@ -90,14 +93,25 @@ export const SecretEditRow = ({
|
|||||||
<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">
|
||||||
<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}
|
||||||
control={control}
|
control={control}
|
||||||
name="value"
|
name="value"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<SecretInput {...field} value={field.value as string} isVisible={isVisible} />
|
<SecretInput
|
||||||
|
{...field}
|
||||||
|
value={field.value as string}
|
||||||
|
isVisible={isVisible}
|
||||||
|
isImport={isImportedSecret}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex w-16 justify-center space-x-3 pl-2 transition-all">
|
<div
|
||||||
|
className={twMerge(
|
||||||
|
"flex w-16 justify-center space-x-3 pl-2 transition-all",
|
||||||
|
isImportedSecret && "pointer-events-none opacity-0"
|
||||||
|
)}
|
||||||
|
>
|
||||||
{isDirty ? (
|
{isDirty ? (
|
||||||
<>
|
<>
|
||||||
<ProjectPermissionCan
|
<ProjectPermissionCan
|
||||||
|
|||||||
+8
-1
@@ -90,7 +90,7 @@ export const SecretOverviewTableRow = ({
|
|||||||
isSecretPresent
|
isSecretPresent
|
||||||
? "Present secret"
|
? "Present secret"
|
||||||
: isSecretImported
|
: isSecretImported
|
||||||
? "Secret is imported from another environment"
|
? "Imported secret"
|
||||||
: "Missing secret"
|
: "Missing secret"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -162,6 +162,12 @@ export const SecretOverviewTableRow = ({
|
|||||||
const secret = getSecretByKey(slug, secretKey);
|
const secret = getSecretByKey(slug, secretKey);
|
||||||
const isCreatable = !secret;
|
const isCreatable = !secret;
|
||||||
|
|
||||||
|
const isImportedSecret = isImportedSecretPresentInEnv(
|
||||||
|
secretPath,
|
||||||
|
slug,
|
||||||
|
secretKey
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
key={`secret-expanded-${slug}-${secretKey}`}
|
key={`secret-expanded-${slug}-${secretKey}`}
|
||||||
@@ -182,6 +188,7 @@ export const SecretOverviewTableRow = ({
|
|||||||
secretName={secretKey}
|
secretName={secretKey}
|
||||||
defaultValue={secret?.value}
|
defaultValue={secret?.value}
|
||||||
secretId={secret?.id}
|
secretId={secret?.id}
|
||||||
|
isImportedSecret={isImportedSecret}
|
||||||
isCreatable={isCreatable}
|
isCreatable={isCreatable}
|
||||||
onSecretDelete={onSecretDelete}
|
onSecretDelete={onSecretDelete}
|
||||||
onSecretCreate={onSecretCreate}
|
onSecretCreate={onSecretCreate}
|
||||||
|
|||||||
Reference in New Issue
Block a user