feat: removed trailing slash from secret input and fixed overview not showing nested imported secrets

This commit is contained in:
=
2024-06-12 00:17:42 +05:30
parent 3929a82099
commit 9a2355fe63
3 changed files with 14 additions and 20 deletions
@@ -78,7 +78,8 @@ export const SecretPathInput = ({
const validPaths = inputValue.split("/"); const validPaths = inputValue.split("/");
validPaths.pop(); validPaths.pop();
const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}/`; // removed trailing slash
const newValue = `${validPaths.join("/")}/${suggestions[selectedIndex]}`;
onChange?.(newValue); onChange?.(newValue);
setInputValue(newValue); setInputValue(newValue);
setSecretPath(newValue); setSecretPath(newValue);
@@ -264,13 +264,12 @@ export const useGetImportedSecretsAllEnvs = ({
}); });
const isImportedSecretPresentInEnv = useCallback( const isImportedSecretPresentInEnv = useCallback(
(secPath: string, envSlug: string, secretName: string) => { (envSlug: string, secretName: string) => {
const selectedEnvIndex = environments.indexOf(envSlug); const selectedEnvIndex = environments.indexOf(envSlug);
if (selectedEnvIndex !== -1) { if (selectedEnvIndex !== -1) {
const isPresent = secretImports?.[selectedEnvIndex]?.data?.find( const isPresent = secretImports?.[selectedEnvIndex]?.data?.find(({ secrets }) =>
({ secretPath, secrets }) => secrets.some((s) => s.key === secretName)
secretPath === secPath && secrets.some((s) => s.key === secretName)
); );
return Boolean(isPresent); return Boolean(isPresent);
@@ -29,7 +29,7 @@ type Props = {
onSecretCreate: (env: string, key: string, value: string) => Promise<void>; onSecretCreate: (env: string, key: string, value: string) => Promise<void>;
onSecretUpdate: (env: string, key: string, value: string, secretId?: string) => Promise<void>; onSecretUpdate: (env: string, key: string, value: string, secretId?: string) => Promise<void>;
onSecretDelete: (env: string, key: string, secretId?: string) => Promise<void>; onSecretDelete: (env: string, key: string, secretId?: string) => Promise<void>;
isImportedSecretPresentInEnv: (name: string, env: string, secretName: string) => boolean; isImportedSecretPresentInEnv: (env: string, secretName: string) => boolean;
}; };
export const SecretOverviewTableRow = ({ export const SecretOverviewTableRow = ({
@@ -53,9 +53,8 @@ export const SecretOverviewTableRow = ({
<> <>
<Tr isHoverable isSelectable onClick={() => setIsFormExpanded.toggle()} className="group"> <Tr isHoverable isSelectable onClick={() => setIsFormExpanded.toggle()} className="group">
<Td <Td
className={`sticky left-0 z-10 bg-mineshaft-800 bg-clip-padding py-0 px-0 group-hover:bg-mineshaft-700 ${ className={`sticky left-0 z-10 bg-mineshaft-800 bg-clip-padding py-0 px-0 group-hover:bg-mineshaft-700 ${isFormExpanded && "border-t-2 border-mineshaft-500"
isFormExpanded && "border-t-2 border-mineshaft-500" }`}
}`}
> >
<div className="h-full w-full border-r border-mineshaft-600 py-2.5 px-5"> <div className="h-full w-full border-r border-mineshaft-600 py-2.5 px-5">
<div className="flex items-center space-x-5"> <div className="flex items-center space-x-5">
@@ -83,7 +82,7 @@ export const SecretOverviewTableRow = ({
{environments.map(({ slug }, i) => { {environments.map(({ slug }, i) => {
const secret = getSecretByKey(slug, secretKey); const secret = getSecretByKey(slug, secretKey);
const isSecretImported = isImportedSecretPresentInEnv(secretPath, slug, secretKey); const isSecretImported = isImportedSecretPresentInEnv(slug, secretKey);
const isSecretPresent = Boolean(secret); const isSecretPresent = Boolean(secret);
const isSecretEmpty = secret?.value === ""; const isSecretEmpty = secret?.value === "";
@@ -108,8 +107,8 @@ export const SecretOverviewTableRow = ({
isSecretPresent isSecretPresent
? "Present secret" ? "Present secret"
: isSecretImported : isSecretImported
? "Imported secret" ? "Imported secret"
: "Missing secret" : "Missing secret"
} }
> >
<FontAwesomeIcon <FontAwesomeIcon
@@ -133,9 +132,8 @@ export const SecretOverviewTableRow = ({
<Tr> <Tr>
<Td <Td
colSpan={totalCols} colSpan={totalCols}
className={`bg-bunker-600 px-0 py-0 ${ className={`bg-bunker-600 px-0 py-0 ${isFormExpanded && "border-b-2 border-mineshaft-500"
isFormExpanded && "border-b-2 border-mineshaft-500" }`}
}`}
> >
<div <div
className="ml-2 p-2" className="ml-2 p-2"
@@ -180,11 +178,7 @@ export const SecretOverviewTableRow = ({
const secret = getSecretByKey(slug, secretKey); const secret = getSecretByKey(slug, secretKey);
const isCreatable = !secret; const isCreatable = !secret;
const isImportedSecret = isImportedSecretPresentInEnv( const isImportedSecret = isImportedSecretPresentInEnv(slug, secretKey);
secretPath,
slug,
secretKey
);
return ( return (
<tr <tr