-
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
API Refactor - DeleteWorkspace - Offline pattern B #10491
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
037d6c4
WIP: Use new API pattern B
aldo-expensify f084a68
Add padding
aldo-expensify 7035bd6
Correct menu item padding
aldo-expensify 75e635e
Clear errors, fix key prop
aldo-expensify 0c25fcd
Disable the workspace menu item while the delete request has not reso…
aldo-expensify f2d8b8f
Remove comments
aldo-expensify 79be75b
Remove whitespace
aldo-expensify 6482601
Resolve conflicts
aldo-expensify ffcb9f8
Style
aldo-expensify ac74c9d
Resolve conflicts
aldo-expensify 52ccba9
Fix error indicator for workspace delete
aldo-expensify 7407995
Use const for 'delete' pending action
aldo-expensify f740a07
Use CONST!
aldo-expensify 1089b8b
Update branch / Resolve conflicts
aldo-expensify eb4fb61
Merge branch 'main' into aldo_delete-workspace-api-refactor
luacmartins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ Onyx.connect({ | |
return; | ||
} | ||
|
||
allPolicies[key] = {...allPolicies[key], ...val}; | ||
allPolicies[key] = val; | ||
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. This was not allowing us to remove keys (like |
||
}, | ||
}); | ||
let sessionEmail = ''; | ||
|
@@ -108,32 +108,27 @@ function updateAllPolicies(policyCollection) { | |
} | ||
|
||
/** | ||
* Delete the policy | ||
* Delete the workspace | ||
* | ||
* @param {String} [policyID] | ||
* @returns {Promise} | ||
* @param {String} policyID | ||
*/ | ||
function deletePolicy(policyID) { | ||
return DeprecatedAPI.Policy_Delete({policyID}) | ||
.then((response) => { | ||
if (response.jsonCode !== 200) { | ||
// Show the user feedback | ||
const errorMessage = Localize.translateLocal('workspace.common.growlMessageOnDeleteError'); | ||
Growl.error(errorMessage, 5000); | ||
return; | ||
} | ||
|
||
Growl.show(Localize.translateLocal('workspace.common.growlMessageOnDelete'), CONST.GROWL.SUCCESS, 3000); | ||
function deleteWorkspace(policyID) { | ||
const optimisticData = [ | ||
{ | ||
onyxMethod: CONST.ONYX.METHOD.MERGE, | ||
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, | ||
value: { | ||
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, | ||
errors: null, | ||
}, | ||
}, | ||
]; | ||
|
||
// Removing the workspace data from Onyx and local array as well | ||
delete allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; | ||
return Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, null); | ||
}) | ||
.then(() => Report.fetchAllReports(false)) | ||
.then(() => { | ||
Navigation.goBack(); | ||
return Promise.resolve(); | ||
}); | ||
// We don't need success data since the push notification will update | ||
// the onyxData for all connected clients. | ||
const failureData = []; | ||
const successData = []; | ||
API.write('DeleteWorkspace', {policyID}, {optimisticData, successData, failureData}); | ||
} | ||
|
||
/** | ||
|
@@ -741,6 +736,18 @@ function clearAddMemberError(policyID, memberEmail) { | |
}); | ||
} | ||
|
||
/** | ||
* Removes an error after trying to delete a workspace | ||
* | ||
* @param {String} policyID | ||
*/ | ||
function clearDeleteWorkspaceError(policyID) { | ||
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { | ||
pendingAction: null, | ||
errors: null, | ||
}); | ||
} | ||
|
||
/** | ||
* Generate a policy name based on an email and policy list. | ||
* @returns {String} | ||
|
@@ -991,13 +998,14 @@ export { | |
setWorkspaceErrors, | ||
clearCustomUnitErrors, | ||
hideWorkspaceAlertMessage, | ||
deletePolicy, | ||
deleteWorkspace, | ||
updateWorkspaceCustomUnit, | ||
updateCustomUnitRate, | ||
updateLastAccessedWorkspace, | ||
subscribeToPolicyEvents, | ||
clearDeleteMemberError, | ||
clearAddMemberError, | ||
clearDeleteWorkspaceError, | ||
openWorkspaceReimburseView, | ||
generateDefaultWorkspaceName, | ||
updateGeneralSettings, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is to remove the BrickRoad indicator status from the workspace line if the error is in the workspace itself, otherwise we get a double red dot: