Skip to content

Commit

Permalink
Merge pull request #32470 from kubabutkiewicz/ts-migration/OptionsLis…
Browse files Browse the repository at this point in the history
…tUtils-lib

[TS migration] Migrate 'OptionsListUtils.js' lib to TypeScript
  • Loading branch information
deetergp authored Jan 25, 2024
2 parents 8cc80e6 + 691fef8 commit ac94dc5
Show file tree
Hide file tree
Showing 18 changed files with 651 additions and 637 deletions.
5 changes: 2 additions & 3 deletions src/components/AnonymousReportFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import React from 'react';
import {View} from 'react-native';
import type {OnyxCollection} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx/lib/types';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Session from '@userActions/Session';
import type {PersonalDetails, Report} from '@src/types/onyx';
import type {PersonalDetailsList, Report} from '@src/types/onyx';
import AvatarWithDisplayName from './AvatarWithDisplayName';
import Button from './Button';
import ExpensifyWordmark from './ExpensifyWordmark';
Expand All @@ -19,7 +18,7 @@ type AnonymousReportFooterProps = {
isSmallSizeLayout?: boolean;

/** Personal details of all the users */
personalDetails: OnyxCollection<PersonalDetails>;
personalDetails: OnyxEntry<PersonalDetailsList>;
};

function AnonymousReportFooter({isSmallSizeLayout = false, personalDetails, report}: AnonymousReportFooterProps) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/AvatarWithDisplayName.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useCallback, useEffect, useRef} from 'react';
import {View} from 'react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import useStyleUtils from '@hooks/useStyleUtils';
Expand All @@ -12,7 +12,7 @@ import * as ReportUtils from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PersonalDetails, Policy, Report, ReportActions} from '@src/types/onyx';
import type {PersonalDetails, PersonalDetailsList, Policy, Report, ReportActions} from '@src/types/onyx';
import DisplayNames from './DisplayNames';
import MultipleAvatars from './MultipleAvatars';
import ParentNavigationSubtitle from './ParentNavigationSubtitle';
Expand All @@ -36,7 +36,7 @@ type AvatarWithDisplayNameProps = AvatarWithDisplayNamePropsWithOnyx & {
size?: ValueOf<typeof CONST.AVATAR_SIZE>;

/** Personal details of all the users */
personalDetails: OnyxCollection<PersonalDetails>;
personalDetails: OnyxEntry<PersonalDetailsList>;

/** Whether if it's an unauthenticated user */
isAnonymous?: boolean;
Expand All @@ -63,7 +63,7 @@ function AvatarWithDisplayName({
const isMoneyRequestOrReport = ReportUtils.isMoneyRequestReport(report) || ReportUtils.isMoneyRequest(report);
const icons = ReportUtils.getIcons(report, personalDetails, null, '', -1, policy);
const ownerPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(report?.ownerAccountID ? [report.ownerAccountID] : [], personalDetails);
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails), false);
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(Object.values(ownerPersonalDetails) as PersonalDetails[], false);
const shouldShowSubscriptAvatar = ReportUtils.shouldReportShowSubscript(report);
const isExpenseRequest = ReportUtils.isExpenseRequest(report);
const avatarBorderColor = isAnonymous ? theme.highlightBG : theme.componentBG;
Expand Down
3 changes: 1 addition & 2 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function LHNOptionsList({
const transactionID = itemParentReportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? itemParentReportAction.originalMessage.IOUTransactionID ?? '' : '';
const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`] ?? null;
const itemComment = draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] ?? '';
const participants = [...ReportUtils.getParticipantsIDs(itemFullReport), itemFullReport?.ownerAccountID, itemParentReportAction?.actorAccountID];
const participants = [...ReportUtils.getParticipantsIDs(itemFullReport), itemFullReport?.ownerAccountID, itemParentReportAction?.actorAccountID].filter(Boolean) as number[];
const participantsPersonalDetails = OptionsListUtils.getPersonalDetailsForAccountIDs(participants, personalDetails);

return (
Expand All @@ -72,7 +72,6 @@ function LHNOptionsList({
reportActions={itemReportActions}
parentReportAction={itemParentReportAction}
policy={itemPolicy}
// @ts-expect-error TODO: Remove this once OptionsListUtils (https://github.com/Expensify/App/issues/24921) is migrated to TypeScript.
personalDetails={participantsPersonalDetails}
transaction={itemTransaction}
receiptTransactions={transactions}
Expand Down
8 changes: 7 additions & 1 deletion src/components/LHNOptionsList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type CustomLHNOptionsListProps = {
data: string[];

/** Callback to fire when a row is selected */
onSelectRow: (reportID: string) => void;
onSelectRow?: (optionItem: OptionData, popoverAnchor: RefObject<View>) => void;

/** Toggle between compact and default view of the option */
optionMode: OptionMode;
Expand Down Expand Up @@ -100,6 +100,12 @@ type OptionRowLHNDataProps = {

/** Whether the user can use violations */
canUseViolations: boolean | undefined;

/** Toggle between compact and default view */
viewMode?: OptionMode;

/** A function that is called when an option is selected. Selected option is passed as a param */
onSelectRow?: (optionItem: OptionData, popoverAnchor: RefObject<View>) => void;
};

type OptionRowLHNProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/OptionRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ function OptionRow({
shouldHaveOptionSeparator && styles.borderTop,
!onSelectRow && !isOptionDisabled ? styles.cursorDefault : null,
]}
accessibilityLabel={option.text}
accessibilityLabel={option.text ?? ''}
role={CONST.ROLE.BUTTON}
hoverDimmingValue={1}
hoverStyle={!optionIsFocused ? hoverStyle ?? styles.sidebarLinkHover : undefined}
Expand Down
6 changes: 1 addition & 5 deletions src/components/ReportWelcomeText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ function ReportWelcomeText({report, policy, personalDetails}: ReportWelcomeTextP
const isDefault = !(isChatRoom || isPolicyExpenseChat);
const participantAccountIDs = report?.participantAccountIDs ?? [];
const isMultipleParticipant = participantAccountIDs.length > 1;
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(
// @ts-expect-error TODO: Remove this once OptionsListUtils (https://github.com/Expensify/App/issues/24921) is migrated to TypeScript.
OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails),
isMultipleParticipant,
);
const displayNamesWithTooltips = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs(participantAccountIDs, personalDetails), isMultipleParticipant);
const isUserPolicyAdmin = PolicyUtils.isPolicyAdmin(policy);
const roomWelcomeMessage = ReportUtils.getRoomWelcomeMessage(report, isUserPolicyAdmin);
const moneyRequestOptions = ReportUtils.getMoneyRequestOptions(report, policy, participantAccountIDs);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getAuthenticateErrorMessage(response: Response): keyof TranslationFlatO
* Method used to get an error object with microsecond as the key.
* @param error - error key or message to be saved
*/
function getMicroSecondOnyxError(error: string): Record<number, string> {
function getMicroSecondOnyxError(error: string): Errors {
return {[DateUtils.getMicroseconds()]: error};
}

Expand Down
9 changes: 5 additions & 4 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PolicyTags, ReportAction} from '@src/types/onyx';
Expand Down Expand Up @@ -95,12 +96,12 @@ function getForDistanceRequest(newDistance: string, oldDistance: string, newAmou
* ModifiedExpense::getNewDotComment in Web-Expensify should match this.
* If we change this function be sure to update the backend as well.
*/
function getForReportAction(reportAction: ReportAction): string {
if (reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) {
function getForReportAction(reportAction: OnyxEntry<ReportAction>): string {
if (reportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE) {
return '';
}
const reportActionOriginalMessage = reportAction.originalMessage as ExpenseOriginalMessage | undefined;
const policyID = ReportUtils.getReportPolicyID(reportAction.reportID) ?? '';
const reportActionOriginalMessage = reportAction?.originalMessage as ExpenseOriginalMessage | undefined;
const policyID = ReportUtils.getReportPolicyID(reportAction?.reportID) ?? '';
const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
const policyTagListName = PolicyUtils.getTagListName(policyTags) || Localize.translateLocal('common.tag');

Expand Down
Loading

0 comments on commit ac94dc5

Please sign in to comment.