mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 23:47:06 +00:00
Fix: Restructured frontend
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
export { useCreateSecretImport, useDeleteSecretImport, useUpdateSecretImport } from "./mutation";
|
||||
export { useGetImportedSecrets, useGetSecretImports } from "./queries";
|
||||
export { useGetImportedFoldersByEnv, useGetImportedSecrets, useGetSecretImports } from "./queries";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback } from "react";
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
import { useQueries, useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
decryptAssymmetric,
|
||||
@@ -7,7 +7,15 @@ import {
|
||||
} from "@app/components/utilities/cryptography/crypto";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { TGetImportedSecrets, TGetSecretImports, TImportedSecrets, TSecretImport } from "./types";
|
||||
import {
|
||||
TGetImportedFoldersByEnvDTO,
|
||||
TGetImportedSecrets,
|
||||
TGetSecretImports,
|
||||
TImportedSecretFolder,
|
||||
TImportedSecrets,
|
||||
TSecretImport,
|
||||
TuseGetImportedFoldersByEnv
|
||||
} from "./types";
|
||||
|
||||
export const secretImportKeys = {
|
||||
getProjectSecretImports: ({ environment, projectId, path }: TGetSecretImports) =>
|
||||
@@ -17,7 +25,9 @@ export const secretImportKeys = {
|
||||
projectId,
|
||||
path
|
||||
}: Omit<TGetImportedSecrets, "decryptFileKey">) =>
|
||||
[{ environment, path, projectId }, "secrets-import-sec"] as const
|
||||
[{ environment, path, projectId }, "secrets-import-sec"] as const,
|
||||
getImportedFoldersByEnv: ({ environment, projectId, path }: TGetImportedFoldersByEnvDTO) =>
|
||||
[{ environment, projectId, path }, "imported-folders"] as const
|
||||
};
|
||||
|
||||
const fetchSecretImport = async ({ projectId, environment, path = "/" }: TGetSecretImports) => {
|
||||
@@ -75,6 +85,24 @@ const fetchImportedSecrets = async (
|
||||
return data.secrets;
|
||||
};
|
||||
|
||||
const fetchImportedFolders = async ({
|
||||
projectId,
|
||||
environment,
|
||||
path
|
||||
}: TGetImportedFoldersByEnvDTO) => {
|
||||
const { data } = await apiRequest.get<{ secretImports: TImportedSecretFolder[] }>(
|
||||
"/api/v1/secret-imports",
|
||||
{
|
||||
params: {
|
||||
workspaceId: projectId,
|
||||
environment,
|
||||
path
|
||||
}
|
||||
}
|
||||
);
|
||||
return data.secretImports;
|
||||
};
|
||||
|
||||
export const useGetImportedSecrets = ({
|
||||
environment,
|
||||
decryptFileKey,
|
||||
@@ -159,3 +187,43 @@ export const useGetImportedSecrets = ({
|
||||
[decryptFileKey]
|
||||
)
|
||||
});
|
||||
|
||||
export const useGetImportedFoldersByEnv = ({
|
||||
projectId,
|
||||
environments,
|
||||
path = "/"
|
||||
}: TuseGetImportedFoldersByEnv) => {
|
||||
const queryParams = new URLSearchParams(window.location.search);
|
||||
|
||||
const importedFolders = useQueries({
|
||||
queries: environments.map((env) => ({
|
||||
queryKey: secretImportKeys.getImportedFoldersByEnv({
|
||||
projectId,
|
||||
environment: env,
|
||||
path
|
||||
}),
|
||||
queryFn: async () => fetchImportedFolders({ projectId, environment: env, path }),
|
||||
enabled: Boolean(projectId) && Boolean(env)
|
||||
}))
|
||||
});
|
||||
|
||||
const isImportedFolderPresentInEnv = useCallback(
|
||||
(name: string, env: string) => {
|
||||
const selectedEnvIndex = environments.indexOf(env);
|
||||
|
||||
if (selectedEnvIndex !== -1) {
|
||||
const currentlyBrowsingPath = queryParams.get("secretPath") || "";
|
||||
|
||||
const isPresent = importedFolders?.[selectedEnvIndex]?.data?.find(
|
||||
({ importPath }) => importPath === `${currentlyBrowsingPath}/${name}`
|
||||
);
|
||||
|
||||
return Boolean(isPresent);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[(importedFolders || []).map((response) => response.data)]
|
||||
);
|
||||
|
||||
return { importedFolders, isImportedFolderPresentInEnv };
|
||||
};
|
||||
|
||||
@@ -12,6 +12,25 @@ export type TSecretImport = {
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TImportedSecretFolder = {
|
||||
id: string;
|
||||
folderId: string;
|
||||
importEnv: {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
};
|
||||
importPath: string;
|
||||
|
||||
// ... It got more fields, but we won't need them.
|
||||
};
|
||||
|
||||
export type TGetImportedFoldersByEnvDTO = {
|
||||
projectId: string;
|
||||
environment: string;
|
||||
path?: string;
|
||||
};
|
||||
|
||||
export type TImportedSecrets = {
|
||||
environment: string;
|
||||
environmentInfo: WorkspaceEnv;
|
||||
@@ -33,6 +52,12 @@ export type TGetImportedSecrets = {
|
||||
decryptFileKey: UserWsKeyPair;
|
||||
};
|
||||
|
||||
export type TuseGetImportedFoldersByEnv = {
|
||||
environments: string[];
|
||||
projectId: string;
|
||||
path?: string;
|
||||
};
|
||||
|
||||
export type TCreateSecretImportDTO = {
|
||||
projectId: string;
|
||||
environment: string;
|
||||
|
||||
Reference in New Issue
Block a user