-
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 5 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,39 @@ function getShouldShowMerchant(data: OnyxTypes.SearchResults['data']): boolean { | |||||
}); | ||||||
} | ||||||
|
||||||
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(transaction?.modifiedCreated ? transaction.modifiedCreated : transaction?.created || '').getFullYear(); | ||||||
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 think there is a utility method to get 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 |
||||||
return transactionYear !== new Date().getFullYear(); | ||||||
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. we can define the currentYear = new Date().getFullYear() out of this block 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 |
||||||
}); | ||||||
} | ||||||
|
||||||
const createdYear = new Date(item?.modifiedCreated ? item.modifiedCreated : item?.created || '').getFullYear(); | ||||||
mountiny marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
return createdYear !== new Date().getFullYear(); | ||||||
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. use currentYear ^ |
||||||
}); | ||||||
} | ||||||
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 = item?.modifiedCreated ? item.modifiedCreated : item?.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. App/src/libs/TransactionUtils.ts Line 465 in 95c8202
|
||||||
|
||||||
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 +135,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 +180,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 +265,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}; |
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