Skip to content

Commit

Permalink
Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zfurtak committed Sep 30, 2024
1 parent b2295da commit 5c3bf8f
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 97 deletions.
4 changes: 2 additions & 2 deletions src/libs/PaginationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ function findFirstItem<TResource>(sortedItems: TResource[], page: string[], getI
*/
function findLastItem<TResource>(sortedItems: TResource[], page: string[], getID: (item: TResource) => string): ItemWithIndex | null {
for (let i = page.length - 1; i >= 0; i--) {
const id = page[i];
const id = page.at(i);
if (id === CONST.PAGINATION_END_ID) {
return {id, index: sortedItems.length - 1};
}
const index = sortedItems.findIndex((item) => getID(item) === id);
if (index !== -1) {
if (index !== -1 && id) {
return {id, index};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libs/Pusher/pusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function getChannel(channelName: string): Channel | undefined {
/**
* Binds an event callback to a channel + eventName
*/
function bindEventToChannel<EventName extends PusherEventName>(channel: Channel | undefined, eventName: EventName, eventCallback: (data: EventData<EventName>) => void = () => {}) {
function bindEventToChannel<EventName extends PusherEventName>(channel: Channel | undefined, eventName?: EventName, eventCallback: (data: EventData<EventName>) => void = () => {}) {
if (!eventName || !channel) {
return;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ function bindEventToChannel<EventName extends PusherEventName>(channel: Channel
*/
function subscribe<EventName extends PusherEventName>(
channelName: string,
eventName: EventName,
eventName?: EventName,
eventCallback: (data: EventData<EventName>) => void = () => {},
onResubscribe = () => {},
): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7012,12 +7012,12 @@ function getNextApproverAccountID(report: OnyxEntry<OnyxTypes.Report>) {
return submitToAccountID;
}

const nextApproverEmail = approvalChain.length === 1 ? approvalChain[0] : approvalChain[approvalChain.indexOf(currentUserEmail) + 1];
const nextApproverEmail = approvalChain.length === 1 ? approvalChain.at(0) : approvalChain.at(approvalChain.indexOf(currentUserEmail) + 1);
if (!nextApproverEmail) {
return submitToAccountID;
}

return PersonalDetailsUtils.getAccountIDsByLogins([nextApproverEmail])[0];
return PersonalDetailsUtils.getAccountIDsByLogins([nextApproverEmail]).at(0);
}

function approveMoneyRequest(expenseReport: OnyxEntry<OnyxTypes.Report>, full?: boolean) {
Expand Down Expand Up @@ -8312,7 +8312,7 @@ function resolveDuplicates(params: TransactionMergeParams) {
});
});

const transactionThreadReportID = getIOUActionForTransactions([params.transactionID], params.reportID)?.[0]?.childReportID;
const transactionThreadReportID = getIOUActionForTransactions([params.transactionID], params.reportID)?.at(0)?.childReportID;
const optimisticReportAction = ReportUtils.buildOptimisticDismissedViolationReportAction({
reason: 'manual',
violationName: CONST.VIOLATIONS.DUPLICATED_TRANSACTION,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ function playSoundForMessageType(pushJSON: OnyxServerUpdate[]) {
const reportActionsOnly = pushJSON.filter((update) => update.key?.includes('reportActions_'));
// "reportActions_5134363522480668" -> "5134363522480668"
const reportID = reportActionsOnly
.map((value) => value.key.split('_')[1])
.map((value) => value.key.split('_').at(1))
.find((reportKey) => reportKey === Navigation.getTopmostReportId() && Visibility.isVisible() && Visibility.hasFocus());

if (!reportID) {
Expand Down Expand Up @@ -1330,7 +1330,7 @@ function requestRefund() {

function subscribeToActiveGuides() {
const pusherChannelName = `${CONST.PUSHER.PRESENCE_ACTIVE_GUIDES}${CONFIG.PUSHER.SUFFIX}`;
Pusher.subscribe(pusherChannelName).catch(() => {
Pusher.subscribe(pusherChannelName, Pusher.TYPE.MULTIPLE_EVENTS).catch(() => {
Log.hmmm('[User] Failed to initially subscribe to Pusher channel', {pusherChannelName});
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function ReportActionItemSingle({
style={[styles.flex1]}
key={`person-${action?.reportActionID}-${0}`}
accountID={actorAccountID ?? -1}
fragment={{...personArray[0], type: 'TEXT', text: displayName ?? ''}}
fragment={{...personArray.at(0), type: 'TEXT', text: displayName ?? ''}}
delegateAccountID={action?.delegateAccountID}
isSingleLine
actorIcon={icon}
Expand All @@ -292,7 +292,7 @@ function ReportActionItemSingle({
style={[styles.flex1]}
key={`person-${action?.reportActionID}-${1}`}
accountID={parseInt(`${secondaryAvatar?.id ?? -1}`, 10)}
fragment={{...personArray[1], type: 'TEXT', text: secondaryAvatar.name ?? ''}}
fragment={{...personArray.at(1), type: 'TEXT', text: secondaryAvatar.name ?? ''}}
delegateAccountID={action?.delegateAccountID}
isSingleLine
actorIcon={secondaryAvatar}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy as PolicyType} from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import {PendingJoinRequestPolicy, PolicyDetailsForNonMembers} from '@src/types/onyx/Policy';
import type {PolicyDetailsForNonMembers} from '@src/types/onyx/Policy';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import WorkspacesListRow from './WorkspacesListRow';

Expand Down
1 change: 1 addition & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ type PendingJoinRequestPolicy = {
policyDetailsForNonMembers: Record<string, OnyxCommon.OnyxValueWithOfflineFeedback<PolicyDetailsForNonMembers>>;
};

/** Details of public policy */
type PolicyDetailsForNonMembers = {
/** Name of the policy */
name: string;
Expand Down
76 changes: 45 additions & 31 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ describe('actions/Report', () => {
return waitForBatchedUpdates();
})
.then(() => {
const resultAction: OnyxEntry<OnyxTypes.ReportAction> = Object.values(reportActions ?? {})[0];
reportActionID = resultAction.reportActionID;
const resultAction: OnyxEntry<OnyxTypes.ReportAction> = Object.values(reportActions ?? {}).at(0);
reportActionID = resultAction?.reportActionID ?? '-1';

expect(resultAction.message).toEqual(REPORT_ACTION.message);
expect(resultAction.person).toEqual(REPORT_ACTION.person);
expect(resultAction.pendingAction).toBeUndefined();
expect(resultAction?.message).toEqual(REPORT_ACTION.message);
expect(resultAction?.person).toEqual(REPORT_ACTION.person);
expect(resultAction?.pendingAction).toBeUndefined();

// We subscribed to the Pusher channel above and now we need to simulate a reportComment action
// Pusher event so we can verify that action was handled correctly and merged into the reportActions.
Expand Down Expand Up @@ -190,7 +190,7 @@ describe('actions/Report', () => {
.then(() => {
// THEN only ONE call to AddComment will happen
const URL_ARGUMENT_INDEX = 0;
const addCommentCalls = (global.fetch as jest.Mock).mock.calls.filter((callArguments: string[]) => callArguments[URL_ARGUMENT_INDEX].includes('AddComment'));
const addCommentCalls = (global.fetch as jest.Mock).mock.calls.filter((callArguments: string[]) => callArguments.at(URL_ARGUMENT_INDEX)?.includes('AddComment'));
expect(addCommentCalls.length).toBe(1);
});
});
Expand Down Expand Up @@ -579,7 +579,7 @@ describe('actions/Report', () => {
reportActionsReactions[key] = val ?? {};
},
});
let reportAction: OnyxTypes.ReportAction;
let reportAction: OnyxTypes.ReportAction | undefined;
let reportActionID: string;

// Set up Onyx with some test user data
Expand All @@ -596,15 +596,17 @@ describe('actions/Report', () => {
return waitForBatchedUpdates();
})
.then(() => {
reportAction = Object.values(reportActions)[0];
reportActionID = reportAction.reportActionID;
reportAction = Object.values(reportActions).at(0);
reportActionID = reportAction?.reportActionID ?? '-1';

// Add a reaction to the comment
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionsReactions[0]);
if (reportAction) {
// Add a reaction to the comment
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionsReactions[0]);
}
return waitForBatchedUpdates();
})
.then(() => {
reportAction = Object.values(reportActions)[0];
reportAction = Object.values(reportActions).at(0);

// Expect the reaction to exist in the reportActionsReactions collection
expect(reportActionsReactions).toHaveProperty(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`);
Expand All @@ -617,8 +619,10 @@ describe('actions/Report', () => {
const reportActionReactionEmoji = reportActionReaction?.[EMOJI.name];
expect(reportActionReactionEmoji?.users).toHaveProperty(`${TEST_USER_ACCOUNT_ID}`);

// Now we remove the reaction
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction);
if (reportAction) {
// Now we remove the reaction
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction);
}
return waitForBatchedUpdates();
})
.then(() => {
Expand All @@ -628,20 +632,24 @@ describe('actions/Report', () => {
expect(reportActionReaction?.[EMOJI.name].users[TEST_USER_ACCOUNT_ID]).toBeUndefined();
})
.then(() => {
reportAction = Object.values(reportActions)[0];
reportAction = Object.values(reportActions).at(0);

// Add the same reaction to the same report action with a different skintone
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionsReactions[0]);
if (reportAction) {
// Add the same reaction to the same report action with a different skintone
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionsReactions[0]);
}
return waitForBatchedUpdates()
.then(() => {
reportAction = Object.values(reportActions)[0];
reportAction = Object.values(reportActions).at(0);

const reportActionReaction = reportActionsReactions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`];
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction, EMOJI_SKIN_TONE);
if (reportAction) {
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction, EMOJI_SKIN_TONE);
}
return waitForBatchedUpdates();
})
.then(() => {
reportAction = Object.values(reportActions)[0];
reportAction = Object.values(reportActions).at(0);

// Expect the reaction to exist in the reportActionsReactions collection
expect(reportActionsReactions).toHaveProperty(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${reportActionID}`);
Expand All @@ -659,8 +667,10 @@ describe('actions/Report', () => {
expect(reportActionReactionEmojiUserSkinTones).toHaveProperty('-1');
expect(reportActionReactionEmojiUserSkinTones).toHaveProperty('2');

// Now we remove the reaction, and expect that both variations are removed
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction);
if (reportAction) {
// Now we remove the reaction, and expect that both variations are removed
Report.toggleEmojiReaction(REPORT_ID, reportAction, EMOJI, reportActionReaction);
}
return waitForBatchedUpdates();
})
.then(() => {
Expand Down Expand Up @@ -698,7 +708,7 @@ describe('actions/Report', () => {
},
});

let resultAction: OnyxTypes.ReportAction;
let resultAction: OnyxTypes.ReportAction | undefined;

// Set up Onyx with some test user data
return TestHelper.signInWithTestUser(TEST_USER_ACCOUNT_ID, TEST_USER_LOGIN)
Expand All @@ -714,26 +724,30 @@ describe('actions/Report', () => {
return waitForBatchedUpdates();
})
.then(() => {
resultAction = Object.values(reportActions)[0];
resultAction = Object.values(reportActions).at(0);

// Add a reaction to the comment
Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI, {});
if (resultAction) {
// Add a reaction to the comment
Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI, {});
}
return waitForBatchedUpdates();
})
.then(() => {
resultAction = Object.values(reportActions)[0];
resultAction = Object.values(reportActions).at(0);

// Now we toggle the reaction while the skin tone has changed.
// As the emoji doesn't support skin tones, the emoji
// should get removed instead of added again.
const reportActionReaction = reportActionsReactions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${resultAction.reportActionID}`];
Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI, reportActionReaction, 2);
const reportActionReaction = reportActionsReactions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${resultAction?.reportActionID}`];
if (resultAction) {
Report.toggleEmojiReaction(REPORT_ID, resultAction, EMOJI, reportActionReaction, 2);
}
return waitForBatchedUpdates();
})
.then(() => {
// Expect the reaction to have null where the users reaction used to be
expect(reportActionsReactions).toHaveProperty(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${resultAction.reportActionID}`);
const reportActionReaction = reportActionsReactions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${resultAction.reportActionID}`];
expect(reportActionsReactions).toHaveProperty(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${resultAction?.reportActionID}`);
const reportActionReaction = reportActionsReactions[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_REACTIONS}${resultAction?.reportActionID}`];
expect(reportActionReaction?.[EMOJI.name].users[TEST_USER_ACCOUNT_ID]).toBeUndefined();
});
});
Expand Down
Loading

0 comments on commit 5c3bf8f

Please sign in to comment.