[WEB-2816] fix: Sync issues and workspace data when the issue properties are deleted#6165
[WEB-2816] fix: Sync issues and workspace data when the issue properties are deleted#6165sriramveeraghanta merged 1 commit intopreviewfrom
Conversation
…modules/cycles etc are deleted from the project
WalkthroughThe changes in this pull request primarily enhance the control flow and error handling of the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 8
🧹 Outside diff range and nitpick comments (3)
web/core/local-db/utils/load-workspace.ts (1)
108-227: Refactor Synchronization Functions to Reduce DuplicationThe functions
syncLabels,syncModules,syncCycles,syncStates, andsyncMembersshare similar logic for synchronizing deleted entities. Consider refactoring these into a generic function to enhance maintainability and reduce code duplication.Suggested Refactor:
Create a generic synchronization function:
const syncEntities = async ( entityName: string, currentEntities: any[], tableName: string, issueKey: string, updateIssueField: string ) => { const currentIdList = currentEntities.map((entity: any) => entity.id); const existingEntities = await persistence.db.exec(`SELECT id FROM ${tableName};`); const existingIdList = existingEntities.map((entity: any) => entity.id); const deletedIds = difference(existingIdList, currentIdList); await syncIssuesWithDeletedEntities(deletedIds as string[], issueKey, updateIssueField); };And a generic
syncIssuesWithDeletedEntitiesfunction:const syncIssuesWithDeletedEntities = async ( deletedIds: string[], issueKey: string, updateIssueField: string ) => { if (!deletedIds.length) { return; } const issues = await persistence.getIssues("", "", { [issueKey]: deletedIds.join(","), cursor: "10000:0:0" }, {}); if (issues?.results && Array.isArray(issues.results)) { const promises = issues.results.map(async (issue: TIssue) => { const updatedIssue = { ...issue, [updateIssueField]: Array.isArray(issue[updateIssueField]) ? issue[updateIssueField].filter((id: string) => !deletedIds.includes(id)) : null, is_local_update: 1, }; updateIssue(updatedIssue); }); await Promise.all(promises); } };Then call this generic function for each entity type.
web/core/store/label.store.ts (1)
279-279: Handle Asynchronous Operation indeleteLabelAfter deleting a label and removing it from
labelMap, consider awaiting thesyncIssuesWithDeletedLabelsfunction to ensure issues are properly synchronized before proceeding.Suggested Change:
- syncIssuesWithDeletedLabels([labelId]); + await syncIssuesWithDeletedLabels([labelId]);This ensures that the synchronization completes before the method finishes execution.
web/core/store/state.store.ts (1)
232-232: Await Synchronization indeleteStateIn the
deleteStatemethod, consider awaiting thesyncIssuesWithDeletedStatesfunction to ensure that issues are synchronized after the state is deleted.Suggested Change:
- syncIssuesWithDeletedStates([stateId]); + await syncIssuesWithDeletedStates([stateId]);This ensures proper sequencing of asynchronous operations.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
web/core/local-db/storage.sqlite.ts(1 hunks)web/core/local-db/utils/load-workspace.ts(4 hunks)web/core/local-db/utils/query-constructor.ts(1 hunks)web/core/local-db/utils/query.utils.ts(2 hunks)web/core/store/cycle.store.ts(2 hunks)web/core/store/label.store.ts(2 hunks)web/core/store/module.store.ts(2 hunks)web/core/store/state.store.ts(2 hunks)
🔇 Additional comments (3)
web/core/local-db/storage.sqlite.ts (1)
297-304: Improved error handling for projectId-less requests
The additional conditional logic efficiently handles cases where projectId is not provided, preventing unnecessary server calls and improving the overall performance of the application.
web/core/store/module.store.ts (1)
13-13: Enhanced data consistency with issue synchronization
The addition of syncIssuesWithDeletedModules ensures proper synchronization of issues when modules are deleted, maintaining data consistency across the application. This follows the established pattern used for other entities like cycles, labels, and states.
Also applies to: 442-442
web/core/store/cycle.store.ts (1)
23-23: Consistent implementation of issue synchronization
The addition of syncIssuesWithDeletedCycles aligns with the application's synchronization strategy, ensuring proper cleanup of issue references when cycles are deleted. This implementation maintains consistency with other stores like modules, labels, and states.
Also applies to: 679-679
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
These changes improve data integrity and user experience by ensuring that the application remains consistent when managing workspace entities.