Skip to content

refactor: move organization to service layer - #10390

Merged
xiaodemen merged 2 commits into
developfrom
refactor/org
Aug 25, 2026
Merged

refactor: move organization to service layer#10390
xiaodemen merged 2 commits into
developfrom
refactor/org

Conversation

@xiaodemen

@xiaodemen xiaodemen commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Copilot AI lite review requested due to automatic review settings August 13, 2026 10:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 syncOrganizations into packages/insomnia/src/common/organization.ts and updated routes to import it from there.
  • Moved project syncing (fetchTeamProjects + DB reconciliation) into packages/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-rules in 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));
}
Comment thread packages/insomnia/src/routes/organization.$organizationId._index.tsx Outdated
@xiaodemen
xiaodemen force-pushed the refactor/org branch 4 times, most recently from 40103a9 to 54af0ee Compare August 14, 2026 07:13
ZxBing0066
ZxBing0066 previously approved these changes Aug 17, 2026

@ZxBing0066 ZxBing0066 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should place this file into ui instead of common, as it uses localStorage?

@xiaodemen
xiaodemen enabled auto-merge (squash) August 25, 2026 09:00
@xiaodemen
xiaodemen disabled auto-merge August 25, 2026 09:08
@xiaodemen
xiaodemen enabled auto-merge (squash) August 25, 2026 09:08
@xiaodemen
xiaodemen merged commit bf982e7 into develop Aug 25, 2026
21 checks passed
@xiaodemen
xiaodemen deleted the refactor/org branch August 25, 2026 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants