mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 05:19:49 +00:00
Show when folders have imports in secret overview page
This commit is contained in:
@@ -167,6 +167,7 @@ export const useGetImportedSecretsAllEnvs = ({
|
||||
select: useCallback(
|
||||
(data: Awaited<ReturnType<typeof fetchImportedSecrets>>) =>
|
||||
data.map((el) => ({
|
||||
currentEnv: env,
|
||||
environment: el.environment,
|
||||
secretPath: el.secretPath,
|
||||
environmentInfo: el.environmentInfo,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SecretV3Raw } from "../secrets/types";
|
||||
import { WsTag } from "../types";
|
||||
import { WorkspaceEnv } from "../workspace/types";
|
||||
|
||||
export type TSecretImport = {
|
||||
@@ -90,3 +91,23 @@ export type TDeleteSecretImportDTO = {
|
||||
environment: string;
|
||||
path?: string;
|
||||
};
|
||||
|
||||
export type SecretImportData = {
|
||||
currentEnv: string;
|
||||
environment: string;
|
||||
secretPath: string;
|
||||
environmentInfo: WorkspaceEnv;
|
||||
folderId: string;
|
||||
secrets: {
|
||||
id: string;
|
||||
env: string;
|
||||
key: string;
|
||||
value: string;
|
||||
secretValueHidden: boolean;
|
||||
tags?: WsTag[];
|
||||
comment?: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
version: number;
|
||||
}[];
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@ import { useCallback, useMemo } from "react";
|
||||
|
||||
import { DashboardProjectSecretsOverview } from "@app/hooks/api/dashboard/types";
|
||||
|
||||
import { SecretImportData } from "../api/secretImports/types";
|
||||
|
||||
type FolderNameAndDescription = {
|
||||
name: string;
|
||||
description?: string;
|
||||
@@ -96,3 +98,40 @@ export const useSecretOverview = (secrets: DashboardProjectSecretsOverview["secr
|
||||
|
||||
return { secKeys, getSecretByKey, getEnvSecretKeyCount };
|
||||
};
|
||||
|
||||
export const useSecretImportOverview = (secretImports: SecretImportData[][] | undefined) => {
|
||||
const uniqueEnvSecretPaths = useMemo(() => {
|
||||
const uniqueMap: Record<string, SecretImportData[]> = {};
|
||||
secretImports?.forEach((importData) => {
|
||||
importData?.forEach((envImport) => {
|
||||
if (envImport) {
|
||||
const key = `${envImport.environment}-${envImport.secretPath}`;
|
||||
const existing = uniqueMap[key];
|
||||
uniqueMap[key] = existing ? [...existing, envImport] : [envImport];
|
||||
}
|
||||
});
|
||||
});
|
||||
return uniqueMap;
|
||||
}, [secretImports]);
|
||||
|
||||
const isSecretImportPresent = useCallback(
|
||||
(sourceEnv: string, targetEnv: string, secretPath: string) => {
|
||||
return (
|
||||
secretImports?.some((importData) =>
|
||||
importData?.some(
|
||||
(envImport) =>
|
||||
envImport?.currentEnv === sourceEnv &&
|
||||
envImport?.environment === targetEnv &&
|
||||
envImport?.secretPath === secretPath
|
||||
)
|
||||
) ?? false
|
||||
);
|
||||
},
|
||||
[secretImports]
|
||||
);
|
||||
|
||||
return {
|
||||
uniqueEnvSecretPaths,
|
||||
isSecretImportPresent
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user