From 6158b8a91da62520508eff0147d7a3cd715968d6 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 16 Oct 2024 12:08:29 +0530 Subject: [PATCH] feat: corrected dummy column in overview and main page --- .../secret-approval-request-service.ts | 2 +- .../secret-rotation-service.ts | 4 ++-- .../secret-v2-bridge-service.ts | 4 ++-- frontend/src/hooks/api/dashboard/queries.tsx | 17 +++++++++++++++- frontend/src/hooks/api/dashboard/types.ts | 3 +++ frontend/src/lib/fn/array.ts | 19 ++++++++++++++++++ .../views/SecretMainPage/SecretMainPage.tsx | 1 + .../SecretOverviewPage/SecretOverviewPage.tsx | 20 +++++++++++++++++-- 8 files changed, 62 insertions(+), 8 deletions(-) diff --git a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts index 1cd8b68b5..1b960ab33 100644 --- a/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts +++ b/backend/src/ee/services/secret-approval-request/secret-approval-request-service.ts @@ -1301,7 +1301,7 @@ export const secretApprovalRequestServiceFactory = ({ environment, secretPath, secretName: commit.key, - secretTags: commitTagIds[commit.key].map((secretTagId) => tagsGroupById[secretTagId][0].slug) + secretTags: commitTagIds?.[commit.key]?.map((secretTagId) => tagsGroupById[secretTagId][0].slug) }) ); }); diff --git a/backend/src/ee/services/secret-rotation/secret-rotation-service.ts b/backend/src/ee/services/secret-rotation/secret-rotation-service.ts index 4c3c61b0c..9eadca32b 100644 --- a/backend/src/ee/services/secret-rotation/secret-rotation-service.ts +++ b/backend/src/ee/services/secret-rotation/secret-rotation-service.ts @@ -1,7 +1,7 @@ import { ForbiddenError, subject } from "@casl/ability"; import Ajv from "ajv"; -import { ProjectVersion } from "@app/db/schemas"; +import { ProjectVersion, TableName } from "@app/db/schemas"; import { decryptSymmetric128BitHexKeyUTF8, infisicalSymmetricEncypt } from "@app/lib/crypto/encryption"; import { BadRequestError, NotFoundError } from "@app/lib/errors"; import { TProjectPermission } from "@app/lib/types"; @@ -106,7 +106,7 @@ export const secretRotationServiceFactory = ({ if (shouldUseBridge) { const selectedSecrets = await secretV2BridgeDAL.find({ folderId: folder.id, - $in: { id: Object.values(outputs) } + $in: { [`${TableName.SecretV2}.id` as "id"]: Object.values(outputs) } }); if (selectedSecrets.length !== Object.values(outputs).length) throw new NotFoundError({ message: "Secrets not found" }); diff --git a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts index 821ac1e00..5d715bbc0 100644 --- a/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts +++ b/backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts @@ -1,7 +1,7 @@ import { ForbiddenError, PureAbility, subject } from "@casl/ability"; import { z } from "zod"; -import { ProjectMembershipRole, SecretsV2Schema, SecretType } from "@app/db/schemas"; +import { ProjectMembershipRole, SecretsV2Schema, SecretType, TableName } from "@app/db/schemas"; import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service"; import { ProjectPermissionActions, ProjectPermissionSub } from "@app/ee/services/permission/project-permission"; import { TSecretApprovalPolicyServiceFactory } from "@app/ee/services/secret-approval-policy/secret-approval-policy-service"; @@ -1617,7 +1617,7 @@ export const secretV2BridgeServiceFactory = ({ const sourceSecrets = await secretDAL.find({ type: SecretType.Shared, $in: { - id: secretIds + [`${TableName.SecretV2}.id` as "id"]: secretIds } }); sourceSecrets.forEach((secret) => { diff --git a/frontend/src/hooks/api/dashboard/queries.tsx b/frontend/src/hooks/api/dashboard/queries.tsx index 29fcbe895..ec018e953 100644 --- a/frontend/src/hooks/api/dashboard/queries.tsx +++ b/frontend/src/hooks/api/dashboard/queries.tsx @@ -15,6 +15,7 @@ import { } from "@app/hooks/api/dashboard/types"; import { OrderByDirection } from "@app/hooks/api/generic/types"; import { mergePersonalSecrets } from "@app/hooks/api/secrets/queries"; +import { unique } from "@app/lib/fn/array"; export const dashboardKeys = { all: () => ["dashboard"] as const, @@ -154,10 +155,24 @@ export const useGetProjectSecretsOverview = ( }, select: useCallback((data: Awaited>) => { const { secrets, ...select } = data; + const uniqueSecrets = secrets + ? unique(secrets, (i) => `${i.secretKey}:${i.environment}`) + : []; + + const uniqueFolders = select.folders + ? unique(select.folders, (i) => `${i.name}:${i.environment}`) + : []; + + const uniqueDynamicSecrets = select.dynamicSecrets + ? unique(select.dynamicSecrets, (i) => `${i.name}:${i.environment}`) + : []; return { ...select, - secrets: secrets ? mergePersonalSecrets(secrets) : undefined + secrets: secrets ? mergePersonalSecrets(secrets) : undefined, + totalUniqueSecretsInPage: uniqueSecrets.length, + totalUniqueDynamicSecretsInPage: uniqueDynamicSecrets.length, + totalUniqueFoldersInPage: uniqueFolders.length }; }, []), keepPreviousData: true diff --git a/frontend/src/hooks/api/dashboard/types.ts b/frontend/src/hooks/api/dashboard/types.ts index 08e75ee3b..865d8541d 100644 --- a/frontend/src/hooks/api/dashboard/types.ts +++ b/frontend/src/hooks/api/dashboard/types.ts @@ -12,6 +12,9 @@ export type DashboardProjectSecretsOverviewResponse = { totalFolderCount?: number; totalDynamicSecretCount?: number; totalCount: number; + totalUniqueSecretsInPage: number; + totalUniqueDynamicSecretsInPage: number; + totalUniqueFoldersInPage: number; }; export type DashboardProjectSecretsDetailsResponse = { diff --git a/frontend/src/lib/fn/array.ts b/frontend/src/lib/fn/array.ts index b92390697..eef80a892 100644 --- a/frontend/src/lib/fn/array.ts +++ b/frontend/src/lib/fn/array.ts @@ -13,3 +13,22 @@ export const groupBy = ( acc[groupId].push(item); return acc; }, {} as Record); + +/** + * Given a list of items returns a new list with only + * unique items. Accepts an optional identity function + * to convert each item in the list to a comparable identity + * value + */ +export const unique = ( + array: readonly T[], + toKey?: (item: T) => K +): T[] => { + const valueMap = array.reduce((acc, item) => { + const key = toKey ? toKey(item) : (item as unknown as string | number | symbol); + if (acc[key]) return acc; + acc[key] = item; + return acc; + }, {} as Record); + return Object.values(valueMap); +}; diff --git a/frontend/src/views/SecretMainPage/SecretMainPage.tsx b/frontend/src/views/SecretMainPage/SecretMainPage.tsx index 43608444e..6c51584dc 100644 --- a/frontend/src/views/SecretMainPage/SecretMainPage.tsx +++ b/frontend/src/views/SecretMainPage/SecretMainPage.tsx @@ -409,6 +409,7 @@ export const SecretMainPage = () => { totalCount ? totalCount % perPage : perPage) - + (imports?.length || 0) - (folders?.length || 0) - (secrets?.length || 0) - (dynamicSecrets?.length || 0), diff --git a/frontend/src/views/SecretOverviewPage/SecretOverviewPage.tsx b/frontend/src/views/SecretOverviewPage/SecretOverviewPage.tsx index 652fac1cf..57773220d 100644 --- a/frontend/src/views/SecretOverviewPage/SecretOverviewPage.tsx +++ b/frontend/src/views/SecretOverviewPage/SecretOverviewPage.tsx @@ -71,7 +71,10 @@ import { SecretType, TSecretFolder } from "@app/hooks/api/types"; import { ProjectVersion } from "@app/hooks/api/workspace/types"; import { useDynamicSecretOverview, useFolderOverview, useSecretOverview } from "@app/hooks/utils"; import { SecretOverviewDynamicSecretRow } from "@app/views/SecretOverviewPage/components/SecretOverviewDynamicSecretRow"; -import { SecretOverviewTableRow } from "@app/views/SecretOverviewPage/components/SecretOverviewTableRow"; +import { + SecretNoAccessOverviewTableRow, + SecretOverviewTableRow +} from "@app/views/SecretOverviewPage/components/SecretOverviewTableRow"; import { SecretTableResourceCount } from "@app/views/SecretOverviewPage/components/SecretTableResourceCount"; import { FolderForm } from "../SecretMainPage/components/ActionBar/FolderForm"; @@ -239,7 +242,10 @@ export const SecretOverviewPage = () => { totalFolderCount, totalSecretCount, totalDynamicSecretCount, - totalCount = 0 + totalCount = 0, + totalUniqueFoldersInPage, + totalUniqueSecretsInPage, + totalUniqueDynamicSecretsInPage } = overview ?? {}; useEffect(() => { @@ -968,6 +974,16 @@ export const SecretOverviewPage = () => { expandableColWidth={expandableTableWidth} /> ))} + totalCount ? totalCount % perPage : perPage) - + (totalUniqueFoldersInPage || 0) - + (totalUniqueDynamicSecretsInPage || 0) - + (totalUniqueSecretsInPage || 0), + 0 + )} + /> )}