-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add feed
syntax key
#57454
base: main
Are you sure you want to change the base?
Add feed
syntax key
#57454
Changes from all commits
e872958
86e92a2
501d1cf
159244f
bcdfe7b
4711093
d897b00
c72972b
9221ae0
1497b84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,29 @@ function isCorporateCard(cardID: number) { | |
return !!allCards[cardID]; | ||
} | ||
|
||
/** | ||
* @param cardID | ||
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. if there is no extra description to @param then please remove it. This code used to be JS only, so IMO all the empty |
||
* @returns string with the 'cards_' part removed from the beginning | ||
*/ | ||
function getCardFeedKey(cardID: string): string { | ||
const splittedCardID = cardID.split('_'); | ||
if (splittedCardID.at(0) === 'cards') { | ||
return splittedCardID.slice(1).join('_'); | ||
} | ||
return cardID; | ||
} | ||
|
||
/** | ||
* @param cardID | ||
* @returns string with added 'cards_' substring at the beginning | ||
*/ | ||
function getWorkspaceCardFeedKey(cardID: string) { | ||
if (cardID.split('_').at(0) !== 'cards') { | ||
return `cards_${cardID}`; | ||
} | ||
return cardID; | ||
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. double check if these 2 functions can be improved |
||
} | ||
|
||
/** | ||
* @param cardID | ||
* @returns string in format %<bank> - <lastFourPAN || Not Activated>%. | ||
|
@@ -86,6 +109,32 @@ function getCardDescription(cardID?: number, cards: CardList = allCards) { | |
return cardDescriptor ? `${humanReadableBankName} - ${cardDescriptor}` : `${humanReadableBankName}`; | ||
} | ||
|
||
type DomainFeedData = {bank: string; domainName: string; correspondingCardIDs: string[]; fundID?: string}; | ||
|
||
/** | ||
* @param cardList - The list of cards to process. Can be undefined. | ||
* @returns a record where keys are domain names and values contain domain feed data. | ||
*/ | ||
function generateDomainFeedsData(cardList: CardList | undefined): Record<string, DomainFeedData> { | ||
return Object.values(cardList ?? {}).reduce((accumulator, currentCard) => { | ||
// Cards in cardList can also be domain cards, we use them to compute domain feed | ||
if (!currentCard.domainName.match(CONST.REGEX.EXPENSIFY_POLICY_DOMAIN_NAME) && !isCardHiddenFromSearch(currentCard)) { | ||
if (accumulator[currentCard.domainName]) { | ||
accumulator[currentCard.domainName].correspondingCardIDs.push(currentCard.cardID.toString()); | ||
} else { | ||
// if the cards belongs to the same domain, every card of it should have the same fundID | ||
accumulator[currentCard.domainName] = { | ||
fundID: currentCard.fundID, | ||
domainName: currentCard.domainName, | ||
bank: currentCard.bank, | ||
correspondingCardIDs: [currentCard.cardID.toString()], | ||
}; | ||
} | ||
} | ||
return accumulator; | ||
}, {} as Record<string, DomainFeedData>); | ||
} | ||
|
||
function isCard(item: Card | Record<string, string>): item is Card { | ||
return typeof item === 'object' && 'cardID' in item && !!item.cardID && 'bank' in item && !!item.bank; | ||
} | ||
|
@@ -549,4 +598,9 @@ export { | |
getFeedType, | ||
flatAllCardsList, | ||
checkIfFeedConnectionIsBroken, | ||
getCardFeedKey, | ||
getWorkspaceCardFeedKey, | ||
generateDomainFeedsData, | ||
}; | ||
|
||
export type {DomainFeedData}; |
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.
please add 1 test case to
buildSubstitutionsMap
tests that will cover cardFeedNames