-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[QBO Export] Implement offline pattern B for manual report exports #44733
Changes from 17 commits
7ad0af4
8d1f659
deba812
533097a
5f448b8
1425235
652ce36
5f85e77
a2a1c41
afcee83
42b923c
eefd928
98c7443
1d2e00c
972f910
37a7735
8cbf964
d214d75
fdcd827
a029907
59d7c77
9af61d1
fce269d
d024caf
dd8d4bd
805ae17
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,6 +1,7 @@ | ||
type MarkAsExportedParams = { | ||
reportIDList: string; | ||
markedManually: true; | ||
optimisticReportActionID: string; | ||
}; | ||
|
||
export default MarkAsExportedParams; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,7 @@ import type { | |||||||||||||||||
UserWallet, | ||||||||||||||||||
} from '@src/types/onyx'; | ||||||||||||||||||
import type {Participant} from '@src/types/onyx/IOU'; | ||||||||||||||||||
import type {OriginalMessageExportedToIntegration} from '@src/types/onyx/OldDotAction'; | ||||||||||||||||||
import type Onboarding from '@src/types/onyx/Onboarding'; | ||||||||||||||||||
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon'; | ||||||||||||||||||
import type {OriginalMessageChangeLog, PaymentMethodType} from '@src/types/onyx/OriginalMessage'; | ||||||||||||||||||
|
@@ -283,6 +284,12 @@ type OptimisticChatReport = Pick< | |||||||||||||||||
isOptimisticReport: true; | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
type OptimisticExportAction = OriginalMessageExportedToIntegration & | ||||||||||||||||||
Pick< | ||||||||||||||||||
ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION>, | ||||||||||||||||||
'reportActionID' | 'actorAccountID' | 'avatar' | 'created' | 'lastModified' | 'message' | 'person' | 'shouldShow' | 'pendingAction' | 'errors' | 'automatic' | ||||||||||||||||||
>; | ||||||||||||||||||
|
||||||||||||||||||
type OptimisticTaskReportAction = Pick< | ||||||||||||||||||
ReportAction, | ||||||||||||||||||
| 'reportActionID' | ||||||||||||||||||
|
@@ -5131,6 +5138,33 @@ function buildOptimisticTaskReport( | |||||||||||||||||
}; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Builds an optimistic EXPORTED_TO_INTEGRATION report action | ||||||||||||||||||
* | ||||||||||||||||||
* @param label - The connectionName of the integration | ||||||||||||||||||
* @param markedManually - Whether the integration was marked as manually exported | ||||||||||||||||||
*/ | ||||||||||||||||||
function buildOptimisticExportIntegrationAction(label: ConnectionName, markedManually = false): OptimisticExportAction { | ||||||||||||||||||
return { | ||||||||||||||||||
reportActionID: NumberUtils.rand64(), | ||||||||||||||||||
actionName: CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION, | ||||||||||||||||||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, | ||||||||||||||||||
actorAccountID: currentUserAccountID, | ||||||||||||||||||
message: [], | ||||||||||||||||||
person: [], | ||||||||||||||||||
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
|
||||||||||||||||||
automatic: false, | ||||||||||||||||||
avatar: getCurrentUserAvatar(), | ||||||||||||||||||
created: DateUtils.getDBTime(), | ||||||||||||||||||
shouldShow: true, | ||||||||||||||||||
originalMessage: { | ||||||||||||||||||
label, | ||||||||||||||||||
lastModified: DateUtils.getDBTime(), | ||||||||||||||||||
markedManually, | ||||||||||||||||||
inProgress: true, | ||||||||||||||||||
}, | ||||||||||||||||||
}; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* A helper method to create transaction thread | ||||||||||||||||||
* | ||||||||||||||||||
|
@@ -7403,6 +7437,7 @@ export { | |||||||||||||||||
isAdminOwnerApproverOrReportOwner, | ||||||||||||||||||
createDraftWorkspaceAndNavigateToConfirmationScreen, | ||||||||||||||||||
isChatUsedForOnboarding, | ||||||||||||||||||
buildOptimisticExportIntegrationAction, | ||||||||||||||||||
getChatUsedForOnboarding, | ||||||||||||||||||
findPolicyExpenseChatByPolicyID, | ||||||||||||||||||
getIntegrationIcon, | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,13 +24,15 @@ import type { | |||||||||
InviteToGroupChatParams, | ||||||||||
InviteToRoomParams, | ||||||||||
LeaveRoomParams, | ||||||||||
MarkAsExportedParams, | ||||||||||
MarkAsUnreadParams, | ||||||||||
OpenReportParams, | ||||||||||
OpenRoomMembersPageParams, | ||||||||||
ReadNewestActionParams, | ||||||||||
RemoveEmojiReactionParams, | ||||||||||
RemoveFromGroupChatParams, | ||||||||||
RemoveFromRoomParams, | ||||||||||
ReportExportParams, | ||||||||||
ResolveActionableMentionWhisperParams, | ||||||||||
ResolveActionableReportMentionWhisperParams, | ||||||||||
SearchForReportsParams, | ||||||||||
|
@@ -3779,18 +3781,93 @@ function setGroupDraft(newGroupDraft: Partial<NewGroupChatDraft>) { | |||||||||
} | ||||||||||
|
||||||||||
function exportToIntegration(reportID: string, connectionName: ConnectionName) { | ||||||||||
API.write(WRITE_COMMANDS.REPORT_EXPORT, { | ||||||||||
const action = ReportUtils.buildOptimisticExportIntegrationAction(connectionName); | ||||||||||
const optimisticReportActionID = action.reportActionID; | ||||||||||
|
||||||||||
const optimisticData: OnyxUpdate[] = [ | ||||||||||
{ | ||||||||||
onyxMethod: Onyx.METHOD.MERGE, | ||||||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||||||
value: { | ||||||||||
[optimisticReportActionID]: action, | ||||||||||
}, | ||||||||||
}, | ||||||||||
]; | ||||||||||
|
||||||||||
const successData: OnyxUpdate[] = [ | ||||||||||
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. Let's not use any |
||||||||||
{ | ||||||||||
onyxMethod: Onyx.METHOD.MERGE, | ||||||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||||||
value: { | ||||||||||
[optimisticReportActionID]: null, | ||||||||||
}, | ||||||||||
}, | ||||||||||
]; | ||||||||||
const failureData: OnyxUpdate[] = [ | ||||||||||
{ | ||||||||||
onyxMethod: Onyx.METHOD.MERGE, | ||||||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||||||
value: { | ||||||||||
[optimisticReportActionID]: { | ||||||||||
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
]; | ||||||||||
|
||||||||||
const params = { | ||||||||||
reportIDList: reportID, | ||||||||||
connectionName, | ||||||||||
type: 'MANUAL', | ||||||||||
}); | ||||||||||
optimisticReportActionID, | ||||||||||
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
We're refactoring this a bit. Instead of just passing |
||||||||||
} satisfies ReportExportParams; | ||||||||||
|
||||||||||
API.write(WRITE_COMMANDS.REPORT_EXPORT, params, {optimisticData, successData, failureData}); | ||||||||||
} | ||||||||||
|
||||||||||
function markAsManuallyExported(reportID: string) { | ||||||||||
API.write(WRITE_COMMANDS.MARK_AS_EXPORTED, { | ||||||||||
function markAsManuallyExported(reportID: string, connectionName: ConnectionName) { | ||||||||||
const action = ReportUtils.buildOptimisticExportIntegrationAction(connectionName, true); | ||||||||||
const optimisticReportActionID = action.reportActionID; | ||||||||||
|
||||||||||
const optimisticData: OnyxUpdate[] = [ | ||||||||||
{ | ||||||||||
onyxMethod: Onyx.METHOD.MERGE, | ||||||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||||||
value: { | ||||||||||
[optimisticReportActionID]: action, | ||||||||||
}, | ||||||||||
}, | ||||||||||
]; | ||||||||||
|
||||||||||
const successData: OnyxUpdate[] = [ | ||||||||||
{ | ||||||||||
onyxMethod: Onyx.METHOD.MERGE, | ||||||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||||||
value: { | ||||||||||
[optimisticReportActionID]: null, | ||||||||||
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
Don't delete the optimistic action here. Just clear the pendingAction |
||||||||||
}, | ||||||||||
}, | ||||||||||
]; | ||||||||||
|
||||||||||
const failureData: OnyxUpdate[] = [ | ||||||||||
{ | ||||||||||
onyxMethod: Onyx.METHOD.MERGE, | ||||||||||
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, | ||||||||||
value: { | ||||||||||
[optimisticReportActionID]: { | ||||||||||
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), | ||||||||||
}, | ||||||||||
}, | ||||||||||
}, | ||||||||||
]; | ||||||||||
|
||||||||||
const params = { | ||||||||||
reportIDList: reportID, | ||||||||||
markedManually: true, | ||||||||||
}); | ||||||||||
optimisticReportActionID, | ||||||||||
arosiclair marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
} satisfies MarkAsExportedParams; | ||||||||||
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 also need to change the shape of MarkAsExported params:
|
||||||||||
|
||||||||||
API.write(WRITE_COMMANDS.MARK_AS_EXPORTED, params, {optimisticData, successData, failureData}); | ||||||||||
} | ||||||||||
|
||||||||||
export { | ||||||||||
|
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.