Skip to content

Commit

Permalink
Merge pull request #51176 from callstack-internal/feat/extend-perf-an…
Browse files Browse the repository at this point in the history
…alytics-with-policy

Add active policy type and role to perf metadata
  • Loading branch information
neil-marcellini authored Oct 21, 2024
2 parents f3d918b + f8addd6 commit bab932c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/libs/Firebase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type FirebaseAttributes = {
transactionViolationsLength: string;
policiesLength: string;
transactionsLength: string;
policyType: string;
policyRole: string;
};

export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes};
5 changes: 4 additions & 1 deletion src/libs/Firebase/utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,6 +16,7 @@ function getAttributes(): FirebaseAttributes {
const transactionViolationsLength = getAllTransactionViolationsLength().toString();
const policiesLength = getAllPoliciesLength().toString();
const transactionsLength = getAllTransactions().toString();
const policy = getActivePolicy();

return {
accountId,
Expand All @@ -25,6 +26,8 @@ function getAttributes(): FirebaseAttributes {
transactionViolationsLength,
policiesLength,
transactionsLength,
policyType: policy?.type ?? '',
policyRole: policy?.role ?? '',
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ type ConnectionWithLastSyncData = {
};

let allPolicies: OnyxCollection<Policy>;
let activePolicyId: OnyxEntry<string>;

Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
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.
Expand Down Expand Up @@ -1054,6 +1060,10 @@ function getAllPoliciesLength() {
return Object.keys(allPolicies ?? {}).length;
}

function getActivePolicy(): OnyxEntry<Policy> {
return getPolicy(activePolicyId);
}

export {
canEditTaxRate,
extractPolicyIDFromPath,
Expand Down Expand Up @@ -1170,6 +1180,7 @@ export {
getWorkflowApprovalsUnavailable,
getNetSuiteImportCustomFieldLabel,
getAllPoliciesLength,
getActivePolicy,
};

export type {MemberEmailsToAccountIDs};

0 comments on commit bab932c

Please sign in to comment.