-
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
Fix report action draft still present after deleting the workspace #30049
Changes from 5 commits
d6504ca
2bb124b
229605f
613e254
e9855c7
2179169
c8286e8
9edcd3b
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import _ from 'underscore'; | ||
import Onyx from 'react-native-onyx'; | ||
import Log from '../Log'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
|
||
/** | ||
* This migration updates reportActionsDrafts data to be keyed by reportActionID. | ||
* | ||
* Before: reportActionsDrafts_reportID_reportActionID: value | ||
* After: reportActionsDrafts_reportID: {[reportActionID]: value} | ||
* | ||
* @returns {Promise} | ||
*/ | ||
export default function () { | ||
return new Promise((resolve) => { | ||
const connectionID = Onyx.connect({ | ||
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS, | ||
waitForCollectionCallback: true, | ||
callback: (allReportActionsDrafts) => { | ||
Onyx.disconnect(connectionID); | ||
|
||
if (!allReportActionsDrafts) { | ||
Log.info('[Migrate Onyx] Skipped migration KeyReportActionsDraftByReportActionID because there were no reportActionsDrafts'); | ||
return resolve(); | ||
} | ||
|
||
const newReportActionsDrafts = {}; | ||
_.each(allReportActionsDrafts, (reportActionDraft, onyxKey) => { | ||
if (!_.isString(reportActionDraft)) { | ||
return; | ||
} | ||
newReportActionsDrafts[onyxKey] = null; | ||
|
||
if (_.isEmpty(reportActionDraft)) { | ||
return; | ||
} | ||
|
||
const reportActionID = onyxKey.split('_').pop(); | ||
const newOnyxKey = onyxKey.replace(`_${reportActionID}`, ''); | ||
newReportActionsDrafts[newOnyxKey] = { | ||
...(newReportActionsDrafts[newOnyxKey] || allReportActionsDrafts[newOnyxKey]), | ||
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. What does 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. It's to cover a case where there is already an existing migrated draft of the example is on the 2nd unit test 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. Can you add a comment to make that obvious please? I see the test, and with one of the values for reportID 2 set to 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. Added the comment.
I'm not sure actually, but I see the other existing tests and they include that kind of case. |
||
[reportActionID]: reportActionDraft, | ||
}; | ||
}); | ||
|
||
if (_.isEmpty(newReportActionsDrafts)) { | ||
Log.info('[Migrate Onyx] Skipped migration KeyReportActionsDraftByReportActionID because there are no actions drafts to migrate'); | ||
return resolve(); | ||
} | ||
|
||
Log.info(`[Migrate Onyx] Re-keying reportActionsDrafts by reportActionID for ${_.keys(newReportActionsDrafts).length} actions drafts`); | ||
// eslint-disable-next-line rulesdir/prefer-actions-set-data | ||
return Onyx.multiSet(newReportActionsDrafts).then(resolve); | ||
}, | ||
}); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type ReportActionsDrafts = Record<string, string>; | ||
|
||
export default ReportActionsDrafts; |
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.
NAB: Is there any non-string case?
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.
One case is when the action draft is already migrated to an object, so we skip it.
I don't know if it is possible that a user have both old and new structure of action draft, but just to be safe.