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
23 changes: 19 additions & 4 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
let personalDetails: Array<PersonalDetails | null> = [];
let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
let emailToPersonalDetailsCache: Record<string, PersonalDetails> = {};
Onyx.connect({

Check warning on line 25 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
personalDetails = Object.values(val ?? {});
Expand All @@ -36,15 +36,31 @@
},
});

let hiddenTranslation = '';
let youTranslation = '';

Onyx.connect({

Check warning on line 42 in src/libs/PersonalDetailsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.ARE_TRANSLATIONS_LOADING,
initWithStoredValues: false,
callback: (value) => {
if (value ?? true) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
hiddenTranslation = translateLocal('common.hidden');
// eslint-disable-next-line @typescript-eslint/no-deprecated
youTranslation = translateLocal('common.you').toLowerCase();
},
});

const regexMergedAccount = new RegExp(CONST.REGEX.MERGED_ACCOUNT_PREFIX);

function getDisplayNameOrDefault(
passedPersonalDetails?: Partial<PersonalDetails> | null,
defaultValue = '',
shouldFallbackToHidden = true,
shouldAddCurrentUserPostfix = false,
// eslint-disable-next-line @typescript-eslint/no-deprecated
youAfterTranslation = translateLocal('common.you').toLowerCase(),
youAfterTranslation = youTranslation,
): string {
let displayName = passedPersonalDetails?.displayName ?? '';

Expand Down Expand Up @@ -84,8 +100,7 @@
if (login) {
return login;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
return shouldFallbackToHidden ? translateLocal('common.hidden') : '';
return shouldFallbackToHidden ? hiddenTranslation : '';
}

/**
Expand Down
23 changes: 19 additions & 4 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@
conciergeReportID = value;
},
});

Check warning on line 954 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({
key: ONYXKEYS.SESSION,
Expand All @@ -959,7 +959,7 @@
// When signed out, val is undefined
if (!value) {
return;
}

Check warning on line 962 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

currentUserEmail = value.email;
currentUserAccountID = value.accountID;
Expand All @@ -977,7 +977,7 @@
if (currentUserAccountID) {
currentUserPersonalDetails = value?.[currentUserAccountID] ?? undefined;
}
allPersonalDetails = value ?? {};

Check warning on line 980 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
allPersonalDetailLogins = Object.values(allPersonalDetails).map((personalDetail) => personalDetail?.login ?? '');
},
});
Expand All @@ -989,14 +989,14 @@
callback: (value) => (allReportsDraft = value),
});

let allPolicies: OnyxCollection<Policy>;

Check warning on line 992 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
});

let allReports: OnyxCollection<Report>;

Check warning on line 999 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({
key: ONYXKEYS.COLLECTION.REPORT,
Expand All @@ -1004,7 +1004,7 @@
callback: (value) => {
allReports = value;

if (!value) {

Check warning on line 1007 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
return;
}

Expand Down Expand Up @@ -1045,14 +1045,14 @@
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};

Check warning on line 1048 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
Onyx.connect({
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
return;
}

Check warning on line 1055 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
allTransactions = Object.fromEntries(Object.entries(value).filter(([, transaction]) => transaction));

reportsTransactions = Object.values(value).reduce<Record<string, Transaction[]>>((all, transaction) => {
Expand Down Expand Up @@ -1171,6 +1171,23 @@
},
});

let hiddenTranslation = '';
let unavailableTranslation = '';

Onyx.connect({
key: ONYXKEYS.ARE_TRANSLATIONS_LOADING,
initWithStoredValues: false,
callback: (value) => {
if (value ?? true) {
return;
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
hiddenTranslation = translateLocal('common.hidden');
// eslint-disable-next-line @typescript-eslint/no-deprecated
unavailableTranslation = translateLocal('workspace.common.unavailable');
},
});

function getCurrentUserAvatar(): AvatarSource | undefined {
return currentUserPersonalDetails?.avatar;
}
Expand Down Expand Up @@ -1314,8 +1331,7 @@
* Get the policy name from a given report
*/
function getPolicyName({report, returnEmptyIfNotFound = false, policy, policies, reports}: GetPolicyNameParams): string {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const noPolicyFound: string = returnEmptyIfNotFound ? '' : translateLocal('workspace.common.unavailable');
const noPolicyFound = returnEmptyIfNotFound ? '' : unavailableTranslation;
const parentReport = report ? getRootParentReport({report, reports}) : undefined;

if (isEmptyObject(report) || (isEmptyObject(policies) && isEmptyObject(allPolicies) && !report?.policyName && !parentReport?.policyName)) {
Expand Down Expand Up @@ -3100,8 +3116,7 @@
}

// If the user's personal details (first name) should be hidden, make sure we return "hidden" instead of the short name
// eslint-disable-next-line @typescript-eslint/no-deprecated
if (shouldFallbackToHidden && longName === translateLocal('common.hidden')) {
if (shouldFallbackToHidden && longName === hiddenTranslation) {
return longName;
}

Expand Down
Loading