refactor: move organization to service layer - #10390
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors organization- and project-sync responsibilities out of ui/organization-utils.ts into shared/common modules and the insomnia-data service layer, updating routes/components to call the new locations.
Changes:
- Moved
syncOrganizationsintopackages/insomnia/src/common/organization.tsand updated routes to import it from there. - Moved project syncing (
fetchTeamProjects+ DB reconciliation) intopackages/insomnia-data/node-src/services/project.ts, updating routes to call the service. - Relocated organization storage-rules imports (
DEFAULT_STORAGE_RULES,fetchAndCacheOrganizationStorageRule) to~/common/organization-storage-rulesin affected UI/routes.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/organization-utils.ts | Removes org/plan/project sync responsibilities from UI util (leaves VCS/migration helpers). |
| packages/insomnia/src/ui/components/dropdowns/git-project-sync-dropdown.tsx | Updates DEFAULT_STORAGE_RULES import source. |
| packages/insomnia/src/routes/trial.start.tsx | Inlines current-plan sync logic for trial start flow. |
| packages/insomnia/src/routes/organization.sync.tsx | Switches to ~/common/organization for org sync. |
| packages/insomnia/src/routes/organization.sync-organizations-and-projects.tsx | Uses new org sync import; switches project sync call to service. |
| packages/insomnia/src/routes/organization.$organizationId.sync-projects.tsx | Switches project sync call to service. |
| packages/insomnia/src/routes/organization.$organizationId.storage-rules.tsx | Switches storage-rules import to common module. |
| packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.spec.tsx | Updates DEFAULT_STORAGE_RULES import source. |
| packages/insomnia/src/routes/organization.$organizationId.project.$projectId.tsx | Updates DEFAULT_STORAGE_RULES import source. |
| packages/insomnia/src/routes/organization.$organizationId.project.$projectId._index.tsx | Updates DEFAULT_STORAGE_RULES import source. |
| packages/insomnia/src/routes/organization.$organizationId.project._index.tsx | Updates DEFAULT_STORAGE_RULES import source (plus minor formatting in a helper signature). |
| packages/insomnia/src/routes/organization.$organizationId._index.tsx | Switches project sync call to service in org entry loader. |
| packages/insomnia/src/routes/organization._index.tsx | Switches to ~/common/organization for org sync. |
| packages/insomnia/src/common/project.ts | Adds a locked syncProjects helper that delegates to services.project.syncProjects. |
| packages/insomnia/src/common/organization.ts | Introduces shared syncOrganizations implementation (writes org/user/plan to localStorage). |
| packages/insomnia-data/node-src/services/project.ts | Implements service-layer team project fetch + reconciliation + syncProjects. |
| packages/insomnia-data/node-src/services/organization.ts | Adds isScratchpad helper for scratchpad org detection. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+21
to
+23
| localStorage.setItem(`${accountId}:organizations`, JSON.stringify(organizations)); | ||
| localStorage.setItem(`${accountId}:user`, JSON.stringify(user)); | ||
| localStorage.setItem(`${accountId}:currentPlan`, JSON.stringify(currentPlan)); |
Comment on lines
8
to
12
| export async function clientAction({ params }: Route.ClientActionArgs) { | ||
| const { organizationId } = params; | ||
|
|
||
| await syncProjects(organizationId); | ||
| await services.project.syncProjects(organizationId); | ||
|
|
Comment on lines
11
to
15
| try { | ||
| await syncProjects(organizationId); | ||
| await services.project.syncProjects(organizationId); | ||
| } catch { | ||
| console.log('[project] Could not fetch remote projects.'); | ||
| } |
Comment on lines
42
to
45
| if (asyncTaskList.includes(AsyncTask.SyncProjects)) { | ||
| invariant(organizationId, 'organizationId is required'); | ||
| taskPromiseList.push(syncProjects(organizationId)); | ||
| taskPromiseList.push(services.project.syncProjects(organizationId)); | ||
| } |
ZxBing0066
reviewed
Aug 13, 2026
xiaodemen
force-pushed
the
refactor/org
branch
4 times, most recently
from
August 14, 2026 07:13
40103a9 to
54af0ee
Compare
ZxBing0066
previously approved these changes
Aug 17, 2026
ZxBing0066
left a comment
Member
There was a problem hiding this comment.
LGTM.
Ideally, projectLock should live in the project service as all atomic-level operations are there.
|
|
||
| invariant(accountId, 'Account ID is not defined'); | ||
|
|
||
| localStorage.setItem(`${accountId}:spaces`, JSON.stringify(organizations)); |
Member
There was a problem hiding this comment.
Do you think we should place this file into ui instead of common, as it uses localStorage?
xiaodemen
force-pushed
the
refactor/org
branch
from
August 25, 2026 08:23
54af0ee to
30a4537
Compare
xiaodemen
force-pushed
the
refactor/org
branch
from
August 25, 2026 08:30
30a4537 to
201e022
Compare
yaoweiprc
approved these changes
Aug 25, 2026
xiaodemen
enabled auto-merge (squash)
August 25, 2026 09:00
xiaodemen
disabled auto-merge
August 25, 2026 09:08
xiaodemen
enabled auto-merge (squash)
August 25, 2026 09:08
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
INS-2682