-
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
[No QA][CRITICAL] [Advanced Approval Workflows] Implement Onyx Actions (API calls & Onyx writes) #46189
[No QA][CRITICAL] [Advanced Approval Workflows] Implement Onyx Actions (API calls & Onyx writes) #46189
Conversation
…kflows/onyx-setup
@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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.
Do you happen to know if policy change logs get created optimistically and are posted to the workspace #admins room? Or do we just want for the server to send out the change logs via pusher?
src/libs/actions/Workflow.ts
Outdated
}); | ||
|
||
function createApprovalWorkflow(policyID: string, approvalWorkflow: ApprovalWorkflow) { | ||
const authToken = NetworkStore.getAuthToken(); |
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.
getAuthToken()
is a new method for me. I think this file should use Onyx.connect()
and grab the authToken from the SESSION onyx key. Again, maybe there was a good reason for this change that I didn't know about.
Typically, people have proposed using singletons like this because of a perception that having lots of Onyx.connect()
for the same key is bad for performance. Yet, I haven't ever seen evidence of this problem and I always direct people to keep using Onyx.connect()
.
The downsides to singletons is that they end up being used in react components to get Onyx data, which results in the component not being "reactive" to data changes at all. So, if we use singletons, we must be sure to only use them in lib code, and only when there is a good and clear reason to use them.
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.
You can see in #27262 the big effort that I had to go through to fix a lot of those bad patterns.
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.
Thanks for the context, I looked for authToken in other actions and saw this pattern that's I went for it. Changing it to Onyx.connect 😄
src/libs/actions/Workflow.ts
Outdated
{ | ||
onyxMethod: Onyx.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: {employeeList}, |
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.
There is something else you need to add to this (I'm not sure if you're planning to implement it later or not).
- When the first workflow is added, the
policy.approvalMode
will switch from BASIC to ADVANCED. - When the last workflow is removed, the
policy.approvalMode
will switch from ADVANCED to BASIC.
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 knew I forgot about something, thanks. Just updated the logic
@mananjadhav I believe we decided we don't require your review on this one, so mainly a heads up! |
Reviewer Checklist
Screenshots/VideosAndroid: NativeAndroid: mWeb ChromeiOS: NativeiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
🚀 Cherry-picked to staging by https://github.com/roryabraham in version: 9.0.14-1 🚀
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.0.14-6 🚀
|
const successData: OnyxUpdate[] = [ | ||
{ | ||
onyxMethod: Onyx.METHOD.SET, | ||
key: ONYXKEYS.APPROVAL_WORKFLOW, | ||
value: null, | ||
}, | ||
]; |
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.
Clearing this workflow should have been done in the optimisticData
because the data is no longer needed as soon as the form is submitted.
Also clearing this in successData
caused a bug if you submit the form offline and go back to the workflow page and get online. The page will suddenly becomes blank (#51468).
Details
libs/actions/Workflow.ts (from the design doc's detailed section)
createApprovalWorkflow
- takes a list of member’s emails, approvers and uses API.write with CreateWorkspaceApproval command to create an approval workflow on the backend.updateApprovalWorkflow
- takes a list of member’s emails, approvers and uses API.write with UpdateWorkspaceApproval command to edit an existing approval workflow on the backend.removeApprovalWorkflow
- takes a list of member’s emails and uses API.write with RemoveWorkspaceApproval command to remove existing approval workflow on the backend.setApprovalWorkflowMembers
- takes a list of emails and sets them underONYXKEYS.APPROVAL_WORKFLOW
key (ApprovalWorkflow[‘members’]
).setApprovalWorkflowApprover
- takes an index (0 for 1st approver, 1 for 2nd, etc.) and approver’s email, forwardsTo and sets it underONYXKEYS.APPROVAL_WORKFLOW
key (ApprovalWorkflow[‘approvers’][index]
).setApprovalWorkflow
- takes the whole ApprovalWorkflow object and saves it under theONYXKEYS.APPROVAL_WORKFLOW
key.clearApprovalWorkflow
- clears the ApprovalWorkflow object under theONYXKEYS.APPROVAL_WORKFLOW
key.Fixed Issues
$ #45959
PROPOSAL: N/A
Tests
N/A
Offline tests
N/A
QA Steps
N/A
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop