Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReportAction text for transactions edited in OldDot #30603

Merged
merged 52 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
94e2dee
ReportAction text for transactions edited in OldDot
cristipaval Oct 30, 2023
6e5d6b0
Make Lint happy.
cristipaval Oct 30, 2023
a7f3f38
Run prettier.
cristipaval Oct 30, 2023
a445ea6
Merge remote-tracking branch 'origin/main' into cristi_modified-expen…
cristipaval Nov 7, 2023
a0a856c
Improve message for MODIFIEDEXPENSE action
cristipaval Nov 7, 2023
960d00a
Add a safety check
cristipaval Nov 7, 2023
a4e82a8
Improve MODIFIEDEXPENSE action message
cristipaval Nov 7, 2023
b9b7ef4
Improve MODIFIEDEXPENSE action message
cristipaval Nov 7, 2023
5190539
Remove redundancy.
cristipaval Nov 7, 2023
b5518be
Update function doc
cristipaval Nov 8, 2023
be978f9
Create reusable function
cristipaval Nov 8, 2023
b31ba92
Run prettier
cristipaval Nov 8, 2023
376944c
Fix lint.
cristipaval Nov 8, 2023
b9f4243
Update src/libs/ReportUtils.js
cristipaval Nov 8, 2023
16df2d9
Merge remote-tracking branch 'origin/main' into cristi_modified-expen…
cristipaval Nov 20, 2023
bab1de4
Move logic in a separate unit
cristipaval Nov 20, 2023
4ea44ee
Move policy tags logic to PolicyUtils
cristipaval Nov 20, 2023
b9229a7
Better naming
cristipaval Nov 20, 2023
72714ad
Dry up code.
cristipaval Nov 20, 2023
18d1bf0
Run prettier
cristipaval Nov 20, 2023
5444abd
Fix lint errors
cristipaval Nov 20, 2023
371f138
Make it a ts file.
cristipaval Nov 21, 2023
ceaa915
Migrate to TS
cristipaval Nov 21, 2023
3bec4fd
Make Lint happy.
cristipaval Nov 21, 2023
b350c6b
Update src/libs/ModifiedExpenseMessage.ts
cristipaval Nov 28, 2023
03931a2
Update src/libs/ModifiedExpenseMessage.ts
cristipaval Nov 28, 2023
4e9a118
Update src/libs/ModifiedExpenseMessage.ts
cristipaval Nov 28, 2023
d855c90
Merge remote-tracking branch 'origin/main' into cristi_modified-expen…
cristipaval Nov 29, 2023
41f8a94
Resolve conflicts after merge.
cristipaval Nov 29, 2023
ceff5c1
Move policyTags to ModifiedExpenseMessage
cristipaval Nov 29, 2023
57f0837
Remove unused function.
cristipaval Nov 29, 2023
7dd7afb
Make lint happy.
cristipaval Nov 29, 2023
1cb7f47
Better checks.
cristipaval Nov 29, 2023
388962f
Update src/libs/ReportUtils.ts
cristipaval Nov 29, 2023
9cc7637
Update src/libs/ModifiedExpenseMessage.ts
cristipaval Nov 29, 2023
60a1493
Improve function doc.
cristipaval Nov 29, 2023
8dd3c99
Add return type declaration
cristipaval Nov 29, 2023
4606a46
Merge remote-tracking branch 'origin/main' into cristi_modified-expen…
cristipaval Nov 30, 2023
0d83c68
Merge remote-tracking branch 'origin/main' into cristi_modified-expen…
cristipaval Dec 13, 2023
a136b74
Fix conflicts after merge
cristipaval Dec 13, 2023
262cb52
RUn prettier
cristipaval Dec 13, 2023
cd28c61
Performance test for ModifiedExpenseMessage
cristipaval Dec 13, 2023
5219b6a
Fix typecheck failures
cristipaval Dec 13, 2023
df90850
Unit test for ModifiedExpenseMessage
cristipaval Dec 14, 2023
db1f935
More tests.
cristipaval Dec 14, 2023
8babd0e
One more test
cristipaval Dec 14, 2023
02c09f2
One more test
cristipaval Dec 14, 2023
a6a28a6
3 more tests
cristipaval Dec 14, 2023
27945e8
3 more tests
cristipaval Dec 14, 2023
8aad9bd
Make lint happy an run prettier
cristipaval Dec 14, 2023
d22c617
Merge remote-tracking branch 'origin/main' into cristi_modified-expen…
cristipaval Dec 18, 2023
13f7b9c
Add changes from main
cristipaval Dec 18, 2023
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
10 changes: 6 additions & 4 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,11 +573,10 @@ export default {
noReimbursableExpenses: 'This report has an invalid amount',
pendingConversionMessage: "Total will update when you're back online",
changedTheRequest: 'changed the request',
setTheRequest: ({valueName, newValueToDisplay}: SetTheRequestParams) => `set the ${valueName} to ${newValueToDisplay}`,
setTheRequest: ({valueName, newValueToDisplay}: SetTheRequestParams) => `the ${valueName} to ${newValueToDisplay}`,
setTheDistance: ({newDistanceToDisplay, newAmountToDisplay}: SetTheDistanceParams) => `set the distance to ${newDistanceToDisplay}, which set the amount to ${newAmountToDisplay}`,
removedTheRequest: ({valueName, oldValueToDisplay}: RemovedTheRequestParams) => `removed the ${valueName} (previously ${oldValueToDisplay})`,
updatedTheRequest: ({valueName, newValueToDisplay, oldValueToDisplay}: UpdatedTheRequestParams) =>
`changed the ${valueName} to ${newValueToDisplay} (previously ${oldValueToDisplay})`,
removedTheRequest: ({valueName, oldValueToDisplay}: RemovedTheRequestParams) => `the ${valueName} (previously ${oldValueToDisplay})`,
updatedTheRequest: ({valueName, newValueToDisplay, oldValueToDisplay}: UpdatedTheRequestParams) => `the ${valueName} to ${newValueToDisplay} (previously ${oldValueToDisplay})`,
updatedTheDistance: ({newDistanceToDisplay, oldDistanceToDisplay, newAmountToDisplay, oldAmountToDisplay}: UpdatedTheDistanceParams) =>
`changed the distance to ${newDistanceToDisplay} (previously ${oldDistanceToDisplay}), which updated the amount to ${newAmountToDisplay} (previously ${oldAmountToDisplay})`,
threadRequestReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `${formattedAmount} request${comment ? ` for ${comment}` : ''}`,
Expand All @@ -597,6 +596,9 @@ export default {
},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `Started settling up, payment is held until ${submitterDisplayName} enables their Wallet`,
enableWallet: 'Enable Wallet',
set: 'set',
changed: 'changed',
removed: 'removed',
},
notificationPreferencesPage: {
header: 'Notification preferences',
Expand Down
10 changes: 6 additions & 4 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,12 @@ export default {
noReimbursableExpenses: 'El importe de este informe no es válido',
pendingConversionMessage: 'El total se actualizará cuando estés online',
changedTheRequest: 'cambió la solicitud',
setTheRequest: ({valueName, newValueToDisplay}: SetTheRequestParams) => `estableció ${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay}`,
setTheRequest: ({valueName, newValueToDisplay}: SetTheRequestParams) => `${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay}`,
setTheDistance: ({newDistanceToDisplay, newAmountToDisplay}: SetTheDistanceParams) =>
`estableció la distancia a ${newDistanceToDisplay}, lo que estableció el importe a ${newAmountToDisplay}`,
removedTheRequest: ({valueName, oldValueToDisplay}: RemovedTheRequestParams) =>
`eliminó ${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} (previamente ${oldValueToDisplay})`,
removedTheRequest: ({valueName, oldValueToDisplay}: RemovedTheRequestParams) => `${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} (previamente ${oldValueToDisplay})`,
updatedTheRequest: ({valueName, newValueToDisplay, oldValueToDisplay}: UpdatedTheRequestParams) =>
`cambió ${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay} (previamente ${oldValueToDisplay})`,
`${valueName === 'comerciante' ? 'el' : 'la'} ${valueName} a ${newValueToDisplay} (previamente ${oldValueToDisplay})`,
updatedTheDistance: ({newDistanceToDisplay, oldDistanceToDisplay, newAmountToDisplay, oldAmountToDisplay}: UpdatedTheDistanceParams) =>
`cambió la distancia a ${newDistanceToDisplay} (previamente ${oldDistanceToDisplay}), lo que cambió el importe a ${newAmountToDisplay} (previamente ${oldAmountToDisplay})`,
threadRequestReportName: ({formattedAmount, comment}: ThreadRequestReportNameParams) => `Solicitud de ${formattedAmount}${comment ? ` para ${comment}` : ''}`,
Expand All @@ -591,6 +590,9 @@ export default {
},
waitingOnEnabledWallet: ({submitterDisplayName}: WaitingOnBankAccountParams) => `Inició el pago, pero no se procesará hasta que ${submitterDisplayName} active su Billetera`,
enableWallet: 'Habilitar Billetera',
set: 'estableció',
changed: 'cambió',
removed: 'eliminó',
},
notificationPreferencesPage: {
header: 'Preferencias de avisos',
Expand Down
130 changes: 122 additions & 8 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1857,7 +1857,7 @@ function getReportPreviewMessage(report, reportAction = {}, shouldConsiderReceip
}

/**
* Get the proper message schema for modified expense message.
* Get the proper message schema for a modified a field on the expense.
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {String} newValue
* @param {String} oldValue
Expand All @@ -1880,6 +1880,37 @@ function getProperSchemaForModifiedExpenseMessage(newValue, oldValue, valueName,
return Localize.translateLocal('iou.updatedTheRequest', {valueName: displayValueName, newValueToDisplay, oldValueToDisplay});
}

/**
* Get the proper message line for a modified expense.
*
* @param {String} newValue
* @param {String} oldValue
* @param {String} valueName
* @param {Boolean} valueInQuotes
* @returns {String}
*/

function getProperLineForModifiedExpenseMessage(prefix, messageFragments) {
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
if (messageFragments.length === 0) {
return '';
}
return messageFragments.reduce((acc, value, index) => {
if (index === messageFragments.length - 1) {
if (messageFragments.length === 1) {
return `${acc} ${value}.`;
}
if (messageFragments.length === 2) {
return `${acc} ${Localize.translateLocal('common.and')} ${value}.`;
}
return `${acc}, ${Localize.translateLocal('common.and')} ${value}.`;
}
if (index === 0) {
return `${acc} ${value}`;
}
return `${acc}, ${value}`;
}, prefix);
}

/**
* Get the proper message schema for modified distance message.
*
Expand Down Expand Up @@ -1917,6 +1948,10 @@ function getModifiedExpenseMessage(reportAction) {
return Localize.translateLocal('iou.changedTheRequest');
}

const removalFragments = [];
const setFragments = [];
const changeFragments = [];

const hasModifiedAmount =
_.has(reportActionOriginalMessage, 'oldAmount') &&
_.has(reportActionOriginalMessage, 'oldCurrency') &&
Expand All @@ -1937,40 +1972,119 @@ function getModifiedExpenseMessage(reportAction) {
return getProperSchemaForModifiedDistanceMessage(reportActionOriginalMessage.merchant, reportActionOriginalMessage.oldMerchant, amount, oldAmount);
}

return getProperSchemaForModifiedExpenseMessage(amount, oldAmount, Localize.translateLocal('iou.amount'), false);
const fragment = getProperSchemaForModifiedExpenseMessage(amount, oldAmount, Localize.translateLocal('iou.amount'), false);
if (!oldAmount) {
setFragments.push(fragment);
} else if (!amount) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
}

const hasModifiedComment = _.has(reportActionOriginalMessage, 'oldComment') && _.has(reportActionOriginalMessage, 'newComment');
if (hasModifiedComment) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.newComment, reportActionOriginalMessage.oldComment, Localize.translateLocal('common.description'), true);
const fragment = getProperSchemaForModifiedExpenseMessage(
reportActionOriginalMessage.newComment,
reportActionOriginalMessage.oldComment,
Localize.translateLocal('common.description'),
true,
);
if (!reportActionOriginalMessage.oldComment) {
setFragments.push(fragment);
} else if (!reportActionOriginalMessage.newComment) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
}

const hasModifiedCreated = _.has(reportActionOriginalMessage, 'oldCreated') && _.has(reportActionOriginalMessage, 'created');
if (hasModifiedCreated) {
// Take only the YYYY-MM-DD value as the original date includes timestamp
let formattedOldCreated = new Date(reportActionOriginalMessage.oldCreated);
formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING);
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, Localize.translateLocal('common.date'), false);
const fragment = getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, Localize.translateLocal('common.date'), false);
if (!formattedOldCreated) {
setFragments.push(fragment);
} else if (!reportActionOriginalMessage.created) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
}

if (hasModifiedMerchant) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.merchant, reportActionOriginalMessage.oldMerchant, Localize.translateLocal('common.merchant'), true);
const fragment = getProperSchemaForModifiedExpenseMessage(
reportActionOriginalMessage.merchant,
reportActionOriginalMessage.oldMerchant,
Localize.translateLocal('common.merchant'),
true,
);
if (!reportActionOriginalMessage.oldMerchant) {
setFragments.push(fragment);
} else if (!reportActionOriginalMessage.merchant) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
}

const hasModifiedCategory = _.has(reportActionOriginalMessage, 'oldCategory') && _.has(reportActionOriginalMessage, 'category');
if (hasModifiedCategory) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.category, reportActionOriginalMessage.oldCategory, Localize.translateLocal('common.category'), true);
const fragment = getProperSchemaForModifiedExpenseMessage(
reportActionOriginalMessage.category,
reportActionOriginalMessage.oldCategory,
Localize.translateLocal('common.category'),
true,
);
if (!reportActionOriginalMessage.oldCategory) {
setFragments.push(fragment);
} else if (!reportActionOriginalMessage.category) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
cristipaval marked this conversation as resolved.
Show resolved Hide resolved
}

const hasModifiedTag = _.has(reportActionOriginalMessage, 'oldTag') && _.has(reportActionOriginalMessage, 'tag');
if (hasModifiedTag) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.tag, reportActionOriginalMessage.oldTag, Localize.translateLocal('common.tag'), true);
const fragment = getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.tag, reportActionOriginalMessage.oldTag, Localize.translateLocal('common.tag'), true);
if (!reportActionOriginalMessage.oldTag) {
setFragments.push(fragment);
} else if (!reportActionOriginalMessage.tag) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
}

const hasModifiedBillable = _.has(reportActionOriginalMessage, 'oldBillable') && _.has(reportActionOriginalMessage, 'billable');
if (hasModifiedBillable) {
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.billable, reportActionOriginalMessage.oldBillable, Localize.translateLocal('iou.request'), true);
const fragment = getProperSchemaForModifiedExpenseMessage(
reportActionOriginalMessage.billable,
reportActionOriginalMessage.oldBillable,
Localize.translateLocal('iou.request'),
true,
);
if (!reportActionOriginalMessage.oldBillable) {
setFragments.push(fragment);
} else if (!reportActionOriginalMessage.billable) {
removalFragments.push(fragment);
} else {
changeFragments.push(fragment);
}
}

let message =
getProperLineForModifiedExpenseMessage(`\n${Localize.translateLocal('iou.changed')}`, changeFragments) +
getProperLineForModifiedExpenseMessage(`\n${Localize.translateLocal('iou.set')}`, setFragments) +
getProperLineForModifiedExpenseMessage(`\n${Localize.translateLocal('iou.removed')}`, removalFragments);
if (message === '') {
return message;
}
message = `${message.substring(1, message.length)}`;
return message;
}

/**
Expand Down