From f8addd61c0e52d8bff18f28212b2ae510c610009 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Mon, 21 Oct 2024 14:40:05 +0200 Subject: [PATCH] add active policy tipe and role to perf metadata --- src/libs/Firebase/types.ts | 2 ++ src/libs/Firebase/utils.ts | 5 ++++- src/libs/PolicyUtils.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libs/Firebase/types.ts b/src/libs/Firebase/types.ts index cf17dd27e01c..4c970375c226 100644 --- a/src/libs/Firebase/types.ts +++ b/src/libs/Firebase/types.ts @@ -17,6 +17,8 @@ type FirebaseAttributes = { transactionViolationsLength: string; policiesLength: string; transactionsLength: string; + policyType: string; + policyRole: string; }; export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes}; diff --git a/src/libs/Firebase/utils.ts b/src/libs/Firebase/utils.ts index 23e7c36ec36a..0235953bfcd3 100644 --- a/src/libs/Firebase/utils.ts +++ b/src/libs/Firebase/utils.ts @@ -1,6 +1,6 @@ import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import {getAllPoliciesLength} from '@libs/PolicyUtils'; +import {getActivePolicy, getAllPoliciesLength} from '@libs/PolicyUtils'; import {getReportActionsLength} from '@libs/ReportActionsUtils'; import * as ReportConnection from '@libs/ReportConnection'; import * as SessionUtils from '@libs/SessionUtils'; @@ -16,6 +16,7 @@ function getAttributes(): FirebaseAttributes { const transactionViolationsLength = getAllTransactionViolationsLength().toString(); const policiesLength = getAllPoliciesLength().toString(); const transactionsLength = getAllTransactions().toString(); + const policy = getActivePolicy(); return { accountId, @@ -25,6 +26,8 @@ function getAttributes(): FirebaseAttributes { transactionViolationsLength, policiesLength, transactionsLength, + policyType: policy?.type ?? '', + policyRole: policy?.role ?? '', }; } diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index ecd025755a1b..8c6e5c924ab7 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -49,6 +49,7 @@ type ConnectionWithLastSyncData = { }; let allPolicies: OnyxCollection; +let activePolicyId: OnyxEntry; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY, @@ -56,6 +57,11 @@ Onyx.connect({ callback: (value) => (allPolicies = value), }); +Onyx.connect({ + key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, + callback: (value) => (activePolicyId = value), +}); + /** * Filter out the active policies, which will exclude policies with pending deletion * These are policies that we can use to create reports with in NewDot. @@ -1049,6 +1055,10 @@ function getAllPoliciesLength() { return Object.keys(allPolicies ?? {}).length; } +function getActivePolicy(): OnyxEntry { + return getPolicy(activePolicyId); +} + export { canEditTaxRate, extractPolicyIDFromPath, @@ -1164,6 +1174,7 @@ export { getWorkflowApprovalsUnavailable, getNetSuiteImportCustomFieldLabel, getAllPoliciesLength, + getActivePolicy, }; export type {MemberEmailsToAccountIDs};