feat: review nits and changes in loading

This commit is contained in:
=
2024-10-25 13:11:15 +05:30
parent 104bff0586
commit 8094ef607a
5 changed files with 40 additions and 32 deletions
+4 -4
View File
@@ -671,10 +671,10 @@ export const RAW_SECRETS = {
workspaceId: "The ID of the project where the secret is located." workspaceId: "The ID of the project where the secret is located."
}, },
GET_REFERENCE_TREE: { GET_REFERENCE_TREE: {
secretName: "The name of the secret to get.", secretName: "The name of the secret to get the reference tree for.'.",
workspaceId: "The ID of the project to get the secret from.", workspaceId: "The ID of the project where the secret is located.",
environment: "The slug of the environment to get the secret from.", environment: "The slug of the environment where the the secret is located.",
secretPath: "The path of the secret to get." secretPath: "The folder path where the secret is located."
} }
} as const; } as const;
@@ -446,10 +446,10 @@ export const expandSecretReferencesFactory = ({
// eslint-disable-next-line no-continue // eslint-disable-next-line no-continue
if (!entities.length) continue; if (!entities.length) continue;
let referredSecretPath = ""; let referrencedSecretPath = "";
let referredSecretKey = ""; let referencedSecretKey = "";
let referredSecretEnvironmentSlug = ""; let referencedSecretEnvironmentSlug = "";
let referredSecretValue = ""; let referencedSecretValue = "";
if (entities.length === 1) { if (entities.length === 1) {
const [secretKey] = entities; const [secretKey] = entities;
@@ -464,10 +464,10 @@ export const expandSecretReferencesFactory = ({
const cacheKey = getCacheUniqueKey(environment, secretPath); const cacheKey = getCacheUniqueKey(environment, secretPath);
secretCache[cacheKey][secretKey] = referredValue; secretCache[cacheKey][secretKey] = referredValue;
referredSecretValue = referredValue.value; referencedSecretValue = referredValue.value;
referredSecretKey = secretKey; referencedSecretKey = secretKey;
referredSecretPath = secretPath; referrencedSecretPath = secretPath;
referredSecretEnvironmentSlug = environment; referencedSecretEnvironmentSlug = environment;
} else { } else {
const secretReferenceEnvironment = entities[0]; const secretReferenceEnvironment = entities[0];
const secretReferencePath = path.join("/", ...entities.slice(1, entities.length - 1)); const secretReferencePath = path.join("/", ...entities.slice(1, entities.length - 1));
@@ -483,23 +483,23 @@ export const expandSecretReferencesFactory = ({
const cacheKey = getCacheUniqueKey(secretReferenceEnvironment, secretReferencePath); const cacheKey = getCacheUniqueKey(secretReferenceEnvironment, secretReferencePath);
secretCache[cacheKey][secretReferenceKey] = referedValue; secretCache[cacheKey][secretReferenceKey] = referedValue;
referredSecretValue = referedValue.value; referencedSecretValue = referedValue.value;
referredSecretKey = secretReferenceKey; referencedSecretKey = secretReferenceKey;
referredSecretPath = secretReferencePath; referrencedSecretPath = secretReferencePath;
referredSecretEnvironmentSlug = secretReferenceEnvironment; referencedSecretEnvironmentSlug = secretReferenceEnvironment;
} }
const node = { const node = {
value: referredSecretValue, value: referencedSecretValue,
secretPath: referredSecretPath, secretPath: referrencedSecretPath,
environment: referredSecretEnvironmentSlug, environment: referencedSecretEnvironmentSlug,
depth: depth + 1, depth: depth + 1,
trace trace
}; };
const shouldExpandMore = INTERPOLATION_SYNTAX_REG.test(referredSecretValue); const shouldExpandMore = INTERPOLATION_SYNTAX_REG.test(referencedSecretValue);
if (dto.shouldStackTrace) { if (dto.shouldStackTrace) {
const stackTraceNode = { ...node, children: [], key: referredSecretKey, trace: null }; const stackTraceNode = { ...node, children: [], key: referencedSecretKey, trace: null };
trace?.children.push(stackTraceNode); trace?.children.push(stackTraceNode);
// if stack trace this would be child node // if stack trace this would be child node
if (shouldExpandMore) { if (shouldExpandMore) {
@@ -510,8 +510,8 @@ export const expandSecretReferencesFactory = ({
stack.push(node); stack.push(node);
} }
if (referredSecretValue) { if (referencedSecretValue) {
expandedValue = expandedValue.replaceAll(interpolationSyntax, referredSecretValue); expandedValue = expandedValue.replaceAll(interpolationSyntax, referencedSecretValue);
} }
} }
} }
@@ -1105,7 +1105,7 @@ export const secretServiceFactory = ({
if (!shouldUseSecretV2Bridge) if (!shouldUseSecretV2Bridge)
throw new BadRequestError({ throw new BadRequestError({
message: "Project version doesn't not support secret reference tree", message: "Project version does not support secret reference tree",
name: "SecretReferenceTreeNotSupported" name: "SecretReferenceTreeNotSupported"
}); });
@@ -7,7 +7,7 @@ import {
faCircleDot, faCircleDot,
faClock, faClock,
faPlus, faPlus,
faRoad, faProjectDiagram,
faShare, faShare,
faTag faTag
} from "@fortawesome/free-solid-svg-icons"; } from "@fortawesome/free-solid-svg-icons";
@@ -464,15 +464,15 @@ export const SecretDetailSidebar = ({
<Button <Button
variant="outline_bg" variant="outline_bg"
className="w-full px-2 py-1" className="w-full px-2 py-1"
leftIcon={<FontAwesomeIcon icon={faRoad} />} leftIcon={<FontAwesomeIcon icon={faProjectDiagram} />}
isDisabled={!isAllowed} isDisabled={!isAllowed}
> >
Reference tree Reference Tree
</Button> </Button>
</ModalTrigger> </ModalTrigger>
<ModalContent <ModalContent
title="Secret Reference Tree" title="Secret Reference Tree"
subTitle="Shows the actual value and reference tree" subTitle="Visual breakdown of secrets referenced by this secret."
> >
<SecretReferenceTree <SecretReferenceTree
secretPath={secretPath} secretPath={secretPath}
@@ -1,6 +1,6 @@
import { twMerge } from "tailwind-merge"; import { twMerge } from "tailwind-merge";
import { FormControl, SecretInput, Tag, Tooltip } from "@app/components/v2"; import { FormControl, SecretInput, Spinner, Tag, Tooltip } from "@app/components/v2";
import { useWorkspace } from "@app/context"; import { useWorkspace } from "@app/context";
import { useGetSecretReferenceTree } from "@app/hooks/api"; import { useGetSecretReferenceTree } from "@app/hooks/api";
import { SecretV3RawSanitized, TSecretReferenceTraceNode } from "@app/hooks/api/types"; import { SecretV3RawSanitized, TSecretReferenceTraceNode } from "@app/hooks/api/types";
@@ -39,7 +39,7 @@ export const SecretReferenceNode = ({
!node.value && "border-red-400 text-red-400" !node.value && "border-red-400 text-red-400"
)} )}
> >
{node.value ? "value" : "empty"} {node.value ? "Reveal Value" : "Empty"}
</span> </span>
</Tooltip> </Tooltip>
</div> </div>
@@ -96,7 +96,7 @@ export const SecretReferenceTree = ({ secretPath, environment, secret }: Props)
const { currentWorkspace } = useWorkspace(); const { currentWorkspace } = useWorkspace();
const projectId = currentWorkspace?.id || ""; const projectId = currentWorkspace?.id || "";
const { data } = useGetSecretReferenceTree({ const { data, isLoading } = useGetSecretReferenceTree({
secretPath, secretPath,
environmentSlug: environment, environmentSlug: environment,
projectId, projectId,
@@ -106,6 +106,14 @@ export const SecretReferenceTree = ({ secretPath, environment, secret }: Props)
const tree = data?.tree; const tree = data?.tree;
const secretValue = data?.value; const secretValue = data?.value;
if (isLoading) {
return (
<div className="flex items-center justify-center py-4">
<Spinner size="xs" />
</div>
);
}
return ( return (
<div> <div>
<FormControl label="Expanded value"> <FormControl label="Expanded value">
@@ -116,7 +124,7 @@ export const SecretReferenceTree = ({ secretPath, environment, secret }: Props)
containerClassName="text-bunker-300 hover:border-primary-400/50 border border-mineshaft-600 bg-bunker-800 px-2 py-1.5" containerClassName="text-bunker-300 hover:border-primary-400/50 border border-mineshaft-600 bg-bunker-800 px-2 py-1.5"
/> />
</FormControl> </FormControl>
<div className="max-h-80 overflow-auto"> <div className="max-h-96 overflow-auto">
{tree && <SecretReferenceNode node={tree} isRoot />} {tree && <SecretReferenceNode node={tree} isRoot />}
</div> </div>
</div> </div>