From 962541e3aea5b9d4ade8e8e7d6e5db8927ac86dd Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Thu, 19 Sep 2024 23:24:50 +0530 Subject: [PATCH 1/9] fixes optimistc case and delay submission current user bad grammar --- src/libs/NextStepUtils.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 6dc12d6d121..9f1b8ac7466 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -38,14 +38,16 @@ Onyx.connect({ function parseMessage(messages: Message[] | undefined) { let nextStepHTML = ''; - messages?.forEach((part) => { + messages?.forEach((part, index) => { const isEmail = Str.isValidEmail(part.text); let tagType = part.type ?? 'span'; let content = Str.safeEscape(part.text); if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) { tagType = 'strong'; - content = 'You'; + content = messages[index + 1].text === `'s` ? 'Your' : 'You'; + } else if (part.text === `'s` && (messages[index - 1].text === currentUserEmail || messages[index - 1].clickToCopyText === currentUserEmail)) { + content = ''; } else if (isEmail) { tagType = 'next-step-email'; content = EmailUtils.prefixMailSeparatorsWithBreakOpportunities(content); @@ -65,15 +67,15 @@ function parseMessage(messages: Message[] | undefined) { function getNextApproverDisplayName(policy: Policy, ownerAccountID: number, submitToAccountID: number, report: OnyxEntry) { const approvalChain = ReportUtils.getApprovalChain(policy, ownerAccountID, report?.total ?? 0); if (approvalChain.length === 0) { - return ReportUtils.getDisplayNameForParticipant(submitToAccountID); + return submitToAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(submitToAccountID); } const nextApproverEmail = approvalChain.length === 1 ? approvalChain[0] : approvalChain[approvalChain.indexOf(currentUserEmail) + 1]; if (!nextApproverEmail) { - return ReportUtils.getDisplayNameForParticipant(submitToAccountID); + return submitToAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(submitToAccountID); } - return PersonalDetailsUtils.getPersonalDetailByEmail(nextApproverEmail)?.displayName ?? nextApproverEmail; + return nextApproverEmail === currentUserEmail ? 'You' : PersonalDetailsUtils.getPersonalDetailByEmail(nextApproverEmail)?.displayName ?? nextApproverEmail; } /** @@ -98,9 +100,10 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf Date: Fri, 20 Sep 2024 00:08:36 +0530 Subject: [PATCH 2/9] resolve comments --- src/libs/NextStepUtils.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 9f1b8ac7466..7b2df19580f 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -43,10 +43,13 @@ function parseMessage(messages: Message[] | undefined) { let tagType = part.type ?? 'span'; let content = Str.safeEscape(part.text); + const previousPart = messages[index - 1]; + const nextPart = messages[index + 1]; + if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) { tagType = 'strong'; - content = messages[index + 1].text === `'s` ? 'Your' : 'You'; - } else if (part.text === `'s` && (messages[index - 1].text === currentUserEmail || messages[index - 1].clickToCopyText === currentUserEmail)) { + content = nextPart.text === `'s` ? 'Your' : 'You'; + } else if (part.text === `'s` && (previousPart?.text === currentUserEmail || previousPart?.clickToCopyText === currentUserEmail)) { content = ''; } else if (isEmail) { tagType = 'next-step-email'; @@ -67,15 +70,15 @@ function parseMessage(messages: Message[] | undefined) { function getNextApproverDisplayName(policy: Policy, ownerAccountID: number, submitToAccountID: number, report: OnyxEntry) { const approvalChain = ReportUtils.getApprovalChain(policy, ownerAccountID, report?.total ?? 0); if (approvalChain.length === 0) { - return submitToAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(submitToAccountID); + return ReportUtils.getDisplayNameForParticipant(submitToAccountID); } const nextApproverEmail = approvalChain.length === 1 ? approvalChain[0] : approvalChain[approvalChain.indexOf(currentUserEmail) + 1]; if (!nextApproverEmail) { - return submitToAccountID === currentUserAccountID ? 'You' : ReportUtils.getDisplayNameForParticipant(submitToAccountID); + return ReportUtils.getDisplayNameForParticipant(submitToAccountID); } - return nextApproverEmail === currentUserEmail ? 'You' : PersonalDetailsUtils.getPersonalDetailByEmail(nextApproverEmail)?.displayName ?? nextApproverEmail; + return PersonalDetailsUtils.getPersonalDetailByEmail(nextApproverEmail)?.displayName ?? nextApproverEmail; } /** @@ -103,7 +106,6 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf Date: Fri, 20 Sep 2024 00:13:16 +0530 Subject: [PATCH 3/9] resolve comments --- src/libs/NextStepUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 7b2df19580f..6519c9c776f 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -103,7 +103,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Fri, 20 Sep 2024 00:14:12 +0530 Subject: [PATCH 4/9] seperate 's --- src/libs/NextStepUtils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 6519c9c776f..a036503f5f1 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -140,9 +140,13 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Fri, 20 Sep 2024 00:15:15 +0530 Subject: [PATCH 5/9] lint fix --- src/libs/NextStepUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index a036503f5f1..543f76f0717 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -145,7 +145,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Fri, 20 Sep 2024 00:23:10 +0530 Subject: [PATCH 6/9] handle optimistic case --- src/libs/NextStepUtils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 543f76f0717..cc63d7837e1 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -48,7 +48,7 @@ function parseMessage(messages: Message[] | undefined) { if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) { tagType = 'strong'; - content = nextPart.text === `'s` ? 'Your' : 'You'; + content = nextPart?.text === `'s` ? 'Your' : 'You'; } else if (part.text === `'s` && (previousPart?.text === currentUserEmail || previousPart?.clickToCopyText === currentUserEmail)) { content = ''; } else if (isEmail) { @@ -121,6 +121,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf Date: Fri, 20 Sep 2024 00:32:50 +0530 Subject: [PATCH 7/9] fix tests --- tests/unit/NextStepUtilsTest.ts | 61 ++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 2b915fcfc4f..fd03a36c66e 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -1,15 +1,15 @@ -import {format, lastDayOfMonth, setDate} from 'date-fns'; +import { format, lastDayOfMonth, setDate } from 'date-fns'; import Onyx from 'react-native-onyx'; import DateUtils from '@libs/DateUtils'; import * as NextStepUtils from '@libs/NextStepUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Policy, Report, ReportNextStep} from '@src/types/onyx'; -import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; +import type { Policy, Report, ReportNextStep } from '@src/types/onyx'; +import { toCollectionDataSet } from '@src/types/utils/CollectionDataSet'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -Onyx.init({keys: ONYXKEYS}); +Onyx.init({ keys: ONYXKEYS }); describe('libs/NextStepUtils', () => { describe('buildNextStep', () => { @@ -44,7 +44,7 @@ describe('libs/NextStepUtils', () => { const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [policy], (item) => item.id); Onyx.multiSet({ - [ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: currentUserAccountID}, + [ONYXKEYS.SESSION]: { email: currentUserEmail, accountID: currentUserAccountID }, [ONYXKEYS.PERSONAL_DETAILS_LIST]: { [strangeAccountID]: { accountID: strangeAccountID, @@ -113,7 +113,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -143,7 +148,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -173,7 +183,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -203,7 +218,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -234,7 +254,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -267,7 +292,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -298,7 +328,12 @@ describe('libs/NextStepUtils', () => { text: 'Waiting for ', }, { - text: `${currentUserEmail}'s`, + text: `${currentUserEmail}`, + clickToCopyText: `${currentUserEmail}`, + type: 'strong', + }, + { + text: "'s", type: 'strong', }, { @@ -515,7 +550,7 @@ describe('libs/NextStepUtils', () => { }, ]; // mock the report as approved - const originalState = {stateNum: report.stateNum, statusNum: report.statusNum}; + const originalState = { stateNum: report.stateNum, statusNum: report.statusNum }; report.stateNum = CONST.REPORT.STATE_NUM.APPROVED; report.statusNum = CONST.REPORT.STATUS_NUM.APPROVED; From 5ae21d1b108cbcf060a662042921e6c5adae29a7 Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Fri, 20 Sep 2024 00:34:17 +0530 Subject: [PATCH 8/9] format with prettier --- tests/unit/NextStepUtilsTest.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index fd03a36c66e..7777f04c92d 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -1,15 +1,15 @@ -import { format, lastDayOfMonth, setDate } from 'date-fns'; +import {format, lastDayOfMonth, setDate} from 'date-fns'; import Onyx from 'react-native-onyx'; import DateUtils from '@libs/DateUtils'; import * as NextStepUtils from '@libs/NextStepUtils'; import * as ReportUtils from '@libs/ReportUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type { Policy, Report, ReportNextStep } from '@src/types/onyx'; -import { toCollectionDataSet } from '@src/types/utils/CollectionDataSet'; +import type {Policy, Report, ReportNextStep} from '@src/types/onyx'; +import {toCollectionDataSet} from '@src/types/utils/CollectionDataSet'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -Onyx.init({ keys: ONYXKEYS }); +Onyx.init({keys: ONYXKEYS}); describe('libs/NextStepUtils', () => { describe('buildNextStep', () => { @@ -44,7 +44,7 @@ describe('libs/NextStepUtils', () => { const policyCollectionDataSet = toCollectionDataSet(ONYXKEYS.COLLECTION.POLICY, [policy], (item) => item.id); Onyx.multiSet({ - [ONYXKEYS.SESSION]: { email: currentUserEmail, accountID: currentUserAccountID }, + [ONYXKEYS.SESSION]: {email: currentUserEmail, accountID: currentUserAccountID}, [ONYXKEYS.PERSONAL_DETAILS_LIST]: { [strangeAccountID]: { accountID: strangeAccountID, @@ -550,7 +550,7 @@ describe('libs/NextStepUtils', () => { }, ]; // mock the report as approved - const originalState = { stateNum: report.stateNum, statusNum: report.statusNum }; + const originalState = {stateNum: report.stateNum, statusNum: report.statusNum}; report.stateNum = CONST.REPORT.STATE_NUM.APPROVED; report.statusNum = CONST.REPORT.STATUS_NUM.APPROVED; From 83f9fdfc069ab74074e32bcbc13bc7b600267e2f Mon Sep 17 00:00:00 2001 From: Ishpaul Singh <104348397+ishpaul777@users.noreply.github.com> Date: Fri, 20 Sep 2024 00:54:50 +0530 Subject: [PATCH 9/9] add space --- src/libs/NextStepUtils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index cc63d7837e1..7f13e1297b6 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -134,6 +134,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf