Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions jest/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ jest.mock('react-native-reanimated', () => ({
}));

jest.mock('react-native-keyboard-controller', () => require<typeof RNKeyboardController>('react-native-keyboard-controller/jest'));

jest.mock('@src/libs/actions/Timing', () => ({
start: jest.fn(),
end: jest.fn(),
}));
24 changes: 21 additions & 3 deletions src/libs/Firebase/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import crashlytics from '@react-native-firebase/crashlytics';
import perf from '@react-native-firebase/perf';
import * as Environment from '@libs/Environment/Environment';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as ReportConnection from '@libs/ReportConnection';
import * as SessionUtils from '@libs/SessionUtils';
import type {Log, StartTrace, StopTrace, TraceMap} from './types';
import type {FirebaseAttributes, Log, StartTrace, StopTrace, TraceMap} from './types';

const traceMap: TraceMap = {};

Expand All @@ -17,12 +19,14 @@ const startTrace: StartTrace = (customEventName) => {
return;
}

const session = SessionUtils.getSession();
const attributes = getAttributes();

perf()
.startTrace(customEventName)
.then((trace) => {
trace.putAttribute('accountID', session?.accountID?.toString() ?? 'N/A');
Object.entries(attributes).forEach(([name, value]) => {
trace.putAttribute(name, value);
});
traceMap[customEventName] = {
trace,
start,
Expand Down Expand Up @@ -55,6 +59,20 @@ const log: Log = (action: string) => {
crashlytics().log(action);
};

function getAttributes(): FirebaseAttributes {
const session = SessionUtils.getSession();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB

Suggested change

const accountId = session?.accountID?.toString() ?? 'N/A';
const reportsLength = ReportConnection.getAllReportsLength().toString();
const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString();

return {
accountId,
reportsLength,
personalDetailsLength,
};
}

export default {
startTrace,
stopTrace,
Expand Down
7 changes: 6 additions & 1 deletion src/libs/Firebase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ type TraceMap = Record<string, Trace>;
type StartTrace = (customEventName: string) => void;
type StopTrace = (customEventName: string) => void;
type Log = (action: string) => void;
type FirebaseAttributes = {
accountId: string;
personalDetailsLength: string;
reportsLength: string;
};

export type {StartTrace, StopTrace, TraceMap, Log};
export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes};
5 changes: 5 additions & 0 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ function isPersonalDetailsEmpty() {
return !personalDetails.length;
}

function getPersonalDetailsLength() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB - probably we don't need a new method if we only use this one time.

return personalDetails.length;
}

export {
isPersonalDetailsEmpty,
getDisplayNameOrDefault,
Expand All @@ -339,4 +343,5 @@ export {
createDisplayName,
extractFirstAndLastNameFromAvailableDetails,
getNewAccountIDsAndLogins,
getPersonalDetailsLength,
};
6 changes: 5 additions & 1 deletion src/libs/ReportConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ function getAllReportsNameMap() {
return reportIDToNameMap;
}

export {getAllReports, getAllReportsNameMap};
function getAllReportsLength() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

return Object.keys(allReports ?? {}).length;
}

export {getAllReports, getAllReportsNameMap, getAllReportsLength};
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function BaseSidebarScreen() {

useEffect(() => {
Performance.markStart(CONST.TIMING.SIDEBAR_LOADED);
Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);
Timing.start(CONST.TIMING.SIDEBAR_LOADED);
}, []);

useEffect(() => {
Expand Down