MCPcopy
hub / github.com/coder/mux / partitionWorkspacesBySection

Function partitionWorkspacesBySection

src/browser/utils/ui/workspaceFiltering.ts:829–859  ·  view source on GitHub ↗
(
  workspaces: FrontendWorkspaceMetadata[],
  sections: WorkspaceGroupConfig[]
)

Source from the content-addressed store, hash-verified

827 * @returns Partitioned workspaces
828 */
829export function partitionWorkspacesBySection(
830 workspaces: FrontendWorkspaceMetadata[],
831 sections: WorkspaceGroupConfig[]
832): SectionPartitionResult {
833 const sectionIds = new Set(sections.map((s) => s.id));
834 const unsectioned: FrontendWorkspaceMetadata[] = [];
835 const bySectionId = new Map<string, FrontendWorkspaceMetadata[]>();
836
837 // Initialize all sections with empty arrays to ensure consistent ordering
838 for (const section of sections) {
839 bySectionId.set(section.id, []);
840 }
841
842 // Build workspace lookup for parent resolution
843 const byId = new Map<string, FrontendWorkspaceMetadata>();
844 for (const workspace of workspaces) {
845 byId.set(workspace.id, workspace);
846 }
847
848 for (const workspace of workspaces) {
849 const effectiveSectionId = resolveEffectiveSectionId(workspace, byId, sectionIds);
850 if (effectiveSectionId) {
851 const list = bySectionId.get(effectiveSectionId)!;
852 list.push(workspace);
853 } else {
854 unsectioned.push(workspace);
855 }
856 }
857
858 return { unsectioned, bySectionId };
859}
860
861/**
862 * Resolve the effective sub-project section ID for a workspace, matching how

Callers 1

ProjectSidebarInnerFunction · 0.90

Calls 4

setMethod · 0.80
getMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected