-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Show year as well in date column #43413
Changes from 6 commits
c7aae0f
920f4dd
bf1b1a8
05def94
840c253
d80faaf
9322531
6e6a02d
b1d44f4
f04ac39
d85b418
0ed2614
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -122,6 +122,8 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) { | |||||
|
||||||
const isSortingAllowed = sortableSearchTabs.includes(query); | ||||||
|
||||||
const doesAtleastOneExpenseBelongToAPastYear = SearchUtils.doesAtleastOneExpenseBelongToAPastYear(searchResults?.data); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
return ( | ||||||
<SelectionList<ReportListItemType | TransactionListItemType> | ||||||
customListHeader={ | ||||||
|
@@ -131,6 +133,7 @@ function Search({query, policyIDs, sortBy, sortOrder}: SearchProps) { | |||||
sortOrder={sortOrder} | ||||||
isSortingAllowed={isSortingAllowed} | ||||||
sortBy={sortBy} | ||||||
doesAtleastOneExpenseBelongToAPastYear={doesAtleastOneExpenseBelongToAPastYear} | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/> | ||||||
} | ||||||
// To enhance the smoothness of scrolling and minimize the risk of encountering blank spaces during scrolling, | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -168,6 +168,9 @@ type TransactionListItemType = ListItem & | |||||||||
|
||||||||||
/** Whether we should show the tax column */ | ||||||||||
shouldShowTax: boolean; | ||||||||||
|
||||||||||
/** Info about whether there's atleast one transaction that doesn't belong to the present year */ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
doesAtleastOneExpenseBelongToAPastYear: boolean; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
}; | ||||||||||
|
||||||||||
type ReportListItemType = ListItem & | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,6 +6,7 @@ import CONST from '@src/CONST'; | |||||
import ONYXKEYS from '@src/ONYXKEYS'; | ||||||
import type * as OnyxTypes from '@src/types/onyx'; | ||||||
import type {SearchAccountDetails, SearchDataTypes, SearchPersonalDetails, SearchTransaction, SearchTypeToItemMap, SectionsType} from '@src/types/onyx/SearchResults'; | ||||||
import DateUtils from './DateUtils'; | ||||||
import getTopmostCentralPaneRoute from './Navigation/getTopmostCentralPaneRoute'; | ||||||
import navigationRef from './Navigation/navigationRef'; | ||||||
import type {CentralPaneNavigatorParamList, RootStackParamList, State} from './Navigation/types'; | ||||||
|
@@ -76,9 +77,42 @@ function getShouldShowMerchant(data: OnyxTypes.SearchResults['data']): boolean { | |||||
}); | ||||||
} | ||||||
|
||||||
const currentYear = new Date().getFullYear(); | ||||||
|
||||||
function doesAtleastOneExpenseBelongToAPastYear(data: TransactionListItemType[] | ReportListItemType[] | OnyxTypes.SearchResults['data']): boolean { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just wonder why data has type of TransactionListItemType[] | ReportListItemType[]. I think it's OnyxTypes.SearchResults['data'] There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (Array.isArray(data)) { | ||||||
return data.some((item: TransactionListItemType | ReportListItemType) => { | ||||||
if ('transactions' in item) { | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// If the item is a ReportListItemType, iterate over its transactions and check them | ||||||
return item.transactions.some((transaction) => { | ||||||
const transactionYear = new Date(TransactionUtils.getCreatedDate(transaction)).getFullYear(); | ||||||
return transactionYear !== currentYear; | ||||||
}); | ||||||
} | ||||||
|
||||||
const createdYear = new Date(item?.modifiedCreated ? item.modifiedCreated : item?.created || '').getFullYear(); | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return createdYear !== currentYear; | ||||||
}); | ||||||
luacmartins marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
for (const [key, transactionItem] of Object.entries(data)) { | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) { | ||||||
const item = transactionItem as SearchTransaction; | ||||||
const date = TransactionUtils.getCreatedDate(item); | ||||||
|
||||||
if (DateUtils.doesDateBelongToAPastYear(date)) { | ||||||
return true; | ||||||
} | ||||||
} | ||||||
} | ||||||
return false; | ||||||
} | ||||||
|
||||||
function getTransactionsSections(data: OnyxTypes.SearchResults['data']): TransactionListItemType[] { | ||||||
const shouldShowMerchant = getShouldShowMerchant(data); | ||||||
|
||||||
const doesDataContainAPastYearTransaction = doesAtleastOneExpenseBelongToAPastYear(data); | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
return Object.entries(data) | ||||||
.filter(([key]) => key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) | ||||||
.map(([, transactionItem]) => { | ||||||
|
@@ -104,13 +138,16 @@ function getTransactionsSections(data: OnyxTypes.SearchResults['data']): Transac | |||||
shouldShowTag: true, | ||||||
shouldShowTax: true, | ||||||
keyForList: transactionItem.transactionID, | ||||||
doesAtleastOneExpenseBelongToAPastYear: doesDataContainAPastYearTransaction, | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; | ||||||
}); | ||||||
} | ||||||
|
||||||
function getReportSections(data: OnyxTypes.SearchResults['data']): ReportListItemType[] { | ||||||
const shouldShowMerchant = getShouldShowMerchant(data); | ||||||
|
||||||
const doesDataContainAPastYearTransaction = doesAtleastOneExpenseBelongToAPastYear(data); | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
const reportIDToTransactions: Record<string, ReportListItemType> = {}; | ||||||
for (const key in data) { | ||||||
if (key.startsWith(ONYXKEYS.COLLECTION.REPORT)) { | ||||||
|
@@ -146,6 +183,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data']): ReportListIte | |||||
shouldShowTag: true, | ||||||
shouldShowTax: true, | ||||||
keyForList: transactionItem.transactionID, | ||||||
doesAtleastOneExpenseBelongToAPastYear: doesDataContainAPastYearTransaction, | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
}; | ||||||
if (reportIDToTransactions[reportKey]?.transactions) { | ||||||
reportIDToTransactions[reportKey].transactions.push(transaction); | ||||||
|
@@ -230,5 +268,5 @@ function getSearchParams() { | |||||
return topmostCentralPaneRoute?.params as CentralPaneNavigatorParamList['Search_Central_Pane']; | ||||||
} | ||||||
|
||||||
export {getListItem, getQueryHash, getSections, getSortedSections, getShouldShowMerchant, getSearchType, getSearchParams}; | ||||||
export {getListItem, getQueryHash, getSections, getSortedSections, getShouldShowMerchant, getSearchType, getSearchParams, doesAtleastOneExpenseBelongToAPastYear}; | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
export type {SearchColumnType, SortOrder}; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -459,13 +459,16 @@ function getTagForDisplay(transaction: OnyxEntry<Transaction>, tagIndex?: number | |||
return getCleanedTagName(getTag(transaction, tagIndex)); | ||||
} | ||||
|
||||
function getCreatedDate(transaction: OnyxEntry<Transaction>): string { | ||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||||
return transaction?.modifiedCreated ? transaction.modifiedCreated : transaction?.created || ''; | ||||
} | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NAB: Could we reuse it here App/src/libs/TransactionUtils.ts Line 467 in b12556b
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I think we should rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mountiny Isn't this already there in my changes? Can you check line 471 in this file? |
||||
/** | ||||
* Return the created field from the transaction, return the modifiedCreated if present. | ||||
*/ | ||||
function getCreated(transaction: OnyxEntry<Transaction>, dateFormat: string = CONST.DATE.FNS_FORMAT_STRING): string { | ||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||||
const created = transaction?.modifiedCreated ? transaction.modifiedCreated : transaction?.created || ''; | ||||
|
||||
const created = getCreatedDate(transaction); | ||||
return DateUtils.formatWithUTCTimeZone(created, dateFormat); | ||||
} | ||||
|
||||
|
@@ -812,6 +815,7 @@ export { | |||
getOriginalAmount, | ||||
getMerchant, | ||||
getMCCGroup, | ||||
getCreatedDate, | ||||
getCreated, | ||||
getCategory, | ||||
getBillable, | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just need to calculate
doesAtleastOneExpenseBelongToAPastYear
in this place (within useMemo) and then pass it tosortedData
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1