-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix broken feed connection error display on the Company Cards page #55286
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
Changes from all commits
8c3091c
40daa37
fc70fd9
4e83054
67cd525
eef9e26
291bbb2
76f8777
a22be65
07bfde8
7749530
fc686e0
40fc52c
16b2397
7a3f80a
afeda3f
1942215
befa0c3
3081c3c
d3d365d
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx'; | ||||||
| import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx'; | ||||||
| import Onyx from 'react-native-onyx'; | ||||||
| import * as API from '@libs/API'; | ||||||
| import type { | ||||||
|
|
@@ -18,10 +18,11 @@ import * as PolicyUtils from '@libs/PolicyUtils'; | |||||
| import * as ReportUtils from '@libs/ReportUtils'; | ||||||
| import CONST from '@src/CONST'; | ||||||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||||||
| import type {Card, CardFeeds} from '@src/types/onyx'; | ||||||
| import type {Card, CardFeeds, WorkspaceCardsList} from '@src/types/onyx'; | ||||||
| import type {AssignCard, AssignCardData} from '@src/types/onyx/AssignCard'; | ||||||
| import type {AddNewCardFeedData, AddNewCardFeedStep, CompanyCardFeed} from '@src/types/onyx/CardFeeds'; | ||||||
| import type {OnyxData} from '@src/types/onyx/Request'; | ||||||
| import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||||||
|
|
||||||
| type AddNewCompanyCardFlowData = { | ||||||
| /** Step to be set in Onyx */ | ||||||
|
|
@@ -403,8 +404,6 @@ function unassignWorkspaceCompanyCard(workspaceAccountID: number, bankName: stri | |||||
|
|
||||||
| function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, bankName: CompanyCardFeed) { | ||||||
| const authToken = NetworkStore.getAuthToken(); | ||||||
| const optimisticFeedUpdates = {[bankName]: {errors: null}}; | ||||||
| const failureFeedUpdates = {[bankName]: {errors: {error: CONST.COMPANY_CARDS.CONNECTION_ERROR}}}; | ||||||
|
|
||||||
| const optimisticData: OnyxUpdate[] = [ | ||||||
| { | ||||||
|
|
@@ -437,13 +436,6 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, | |||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| onyxMethod: Onyx.METHOD.MERGE, | ||||||
| key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||||||
| value: { | ||||||
| settings: {companyCards: optimisticFeedUpdates}, | ||||||
| }, | ||||||
| }, | ||||||
| ]; | ||||||
|
|
||||||
| const finallyData: OnyxUpdate[] = [ | ||||||
|
|
@@ -504,13 +496,6 @@ function updateWorkspaceCompanyCard(workspaceAccountID: number, cardID: string, | |||||
| }, | ||||||
| }, | ||||||
| }, | ||||||
| { | ||||||
| onyxMethod: Onyx.METHOD.MERGE, | ||||||
| key: `${ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER}${workspaceAccountID}`, | ||||||
| value: { | ||||||
| settings: {companyCards: failureFeedUpdates}, | ||||||
| }, | ||||||
| }, | ||||||
| ]; | ||||||
|
|
||||||
| const parameters = { | ||||||
|
|
@@ -740,6 +725,41 @@ function openPolicyCompanyCardsFeed(policyID: string, feed: CompanyCardFeed) { | |||||
| API.read(READ_COMMANDS.OPEN_POLICY_COMPANY_CARDS_FEED, parameters); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Takes the list of cards divided by workspaces and feeds and returns the flattened non-Expensify cards related to the provided workspace | ||||||
| * | ||||||
| * @param allCardsList the list where cards split by workspaces and feeds and stored under `card_${workspaceAccountID}_${feedName}` keys | ||||||
| * @param workspaceAccountID the workspace account id we want to get cards for | ||||||
| */ | ||||||
| function flatAllCardsList(allCardsList: OnyxCollection<WorkspaceCardsList>, workspaceAccountID: number): Record<string, Card> | undefined { | ||||||
| if (!allCardsList) { | ||||||
| return; | ||||||
| } | ||||||
|
|
||||||
| return Object.entries(allCardsList).reduce((acc, [key, allCards]) => { | ||||||
| if (!key.includes(workspaceAccountID.toString()) || key.includes(CONST.EXPENSIFY_CARD.BANK)) { | ||||||
| return acc; | ||||||
| } | ||||||
| const {cardList, ...feedCards} = allCards ?? {}; | ||||||
| Object.assign(acc, feedCards); | ||||||
| return acc; | ||||||
| }, {}); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Check if any feed card has a broken connection | ||||||
|
Contributor
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
|
||||||
| * | ||||||
| * @param feedCards the list of the cards, related to one or several feeds | ||||||
| * @param [feedToExclude] the feed to ignore during the check, it's useful for checking broken connection error only in the feeds other than the selected one | ||||||
| */ | ||||||
| function checkIfFeedConnectionIsBroken(feedCards: Record<string, Card> | undefined, feedToExclude?: string): boolean { | ||||||
|
Contributor
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. Could you please add docs here as well and try to explain why the |
||||||
| if (!feedCards || isEmptyObject(feedCards)) { | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| return Object.values(feedCards).some((card) => card.bank !== feedToExclude && card.lastScrapeResult !== 200); | ||||||
| } | ||||||
|
|
||||||
| export { | ||||||
| setWorkspaceCompanyCardFeedName, | ||||||
| deleteWorkspaceCompanyCardFeed, | ||||||
|
|
@@ -757,4 +777,6 @@ export { | |||||
| clearAddNewCardFlow, | ||||||
| setAssignCardStepAndData, | ||||||
| clearAssignCardStepAndData, | ||||||
| checkIfFeedConnectionIsBroken, | ||||||
| flatAllCardsList, | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ type CompanyCardBankConnection = { | |
| isNewDot: string; | ||
| }; | ||
|
|
||
| export default function getCompanyCardBankConnection(policyID?: string, bankName?: string, scrapeMinDate?: string) { | ||
| export default function getCompanyCardBankConnection(policyID?: string, bankName?: string) { | ||
| const bankConnection = Object.keys(CONST.COMPANY_CARDS.BANKS).find((key) => CONST.COMPANY_CARDS.BANKS[key as keyof typeof CONST.COMPANY_CARDS.BANKS] === bankName); | ||
|
|
||
| if (!bankName || !bankConnection || !policyID) { | ||
|
|
@@ -23,7 +23,7 @@ export default function getCompanyCardBankConnection(policyID?: string, bankName | |
| isNewDot: 'true', | ||
| domainName: PolicyUtils.getDomainNameForPolicy(policyID), | ||
| isCorporate: 'true', | ||
| scrapeMinDate: scrapeMinDate ?? '', | ||
| scrapeMinDate: '', | ||
|
Contributor
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. hey @VickyStash do you remember why this was removed? I'm looking at #84401
Contributor
Author
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. Sorry, but I don't remember |
||
| }; | ||
| const commandURL = getApiRoot({ | ||
| shouldSkipWebProxy: true, | ||
|
|
||
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 this method would deserve some plain English explanation of what its used for and what is the expected output format (unit test possibly too)