-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor base cluster model architecture for clarity #473
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
Refactor base cluster model architecture for clarity #473
Conversation
…tion for resource IDs
…rity and separation of concerns
…onnections and database items
…ure proper sanitization of resource IDs
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.
Pull request overview
This PR refactors the cluster model type hierarchy to cleanly separate intrinsic cluster data from tree positioning concerns, removing Azure SDK dependencies from the Connections View.
Changes:
- Introduces a new type hierarchy:
BaseClusterModel(core data) →ConnectionClusterModel(Connections View) /AzureClusterModel(Azure/Discovery Views) - Separates tree positioning into
ClusterTreeContext(withtreeIdandviewId) and combines them viaTreeCluster<T>type - Migrates all views to use appropriate model types: Connections View uses
ConnectionClusterModel, Azure/Discovery Views useAzureClusterModel, generic tree items useBaseClusterModel - Makes
ClusterItemBasegeneric and safely accesses Azure-specific properties via runtime checks - Deprecates the old
ClusterModeltype as a union with clear migration guidance
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/tree/models/BaseClusterModel.ts | Defines core cluster data interface without tree positioning concerns |
| src/tree/models/BaseClusterModel.test.ts | Comprehensive tests for base model and tree context separation |
| src/tree/connections-view/models/ConnectionClusterModel.ts | Clean Connections View model with storageId and emulatorConfiguration |
| src/tree/connections-view/models/ConnectionClusterModel.test.ts | Tests for ConnectionClusterModel including folder hierarchy scenarios |
| src/tree/azure-views/models/AzureClusterModel.ts | Azure-specific model with ARM metadata and sanitization helper |
| src/tree/azure-views/models/AzureClusterModel.test.ts | Tests for AzureClusterModel including Discovery vs Azure Resources View patterns |
| src/tree/documentdb/ClusterModel.ts | Deprecated union type with clear migration guide for backward compatibility |
| src/tree/documentdb/ClusterItemBase.ts | Made generic, safely casts to Azure properties when needed |
| src/tree/connections-view/* | All Connections View files migrated to ConnectionClusterModel |
| src/tree/azure-resources-view/* | Azure Resources View files migrated to AzureClusterModel with proper treeId handling |
| src/plugins//discovery-tree/ | Discovery View files migrated to AzureClusterModel with treeId sanitization |
| src/tree/documentdb/{DatabaseItem,CollectionItem,etc}.ts | Generic tree items updated to use BaseClusterModel |
| src/documentdb/scrapbook/ScrapbookService.ts | Uses BaseClusterModel with safe type narrowing for emulatorConfiguration |
| src/commands/launchShell/launchShell.ts | Safe type narrowing for emulatorConfiguration access |
| .github/copilot-instructions.md | Updated with new model types and ID strategy clarification |
… models and tests
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.
Pull request overview
Copilot reviewed 37 out of 37 changed files in this pull request and generated 18 comments.
src/tree/azure-resources-view/documentdb/VCoreBranchDataProvider.ts
Outdated
Show resolved
Hide resolved
src/plugins/service-azure-mongo-vcore/discovery-tree/AzureSubscriptionItem.ts
Outdated
Show resolved
Hide resolved
src/plugins/service-azure-mongo-ru/discovery-tree/AzureMongoRUSubscriptionItem.ts
Outdated
Show resolved
Hide resolved
src/tree/azure-resources-view/documentdb/VCoreBranchDataProvider.ts
Outdated
Show resolved
Hide resolved
…ptimize resource routing
…timize cluster ID handling
…uster tree elements
…th cluster ID validation and augmentation
…d improve cluster ID handling
…ssary provider ID extraction and enhancing cluster node lookup
…ation and improve tree ID extraction
…lidation in Discovery services
…ts for simplification
…om a specific parent
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.
Pull request overview
Copilot reviewed 43 out of 43 changed files in this pull request and generated 4 comments.
… to replace '/' with '_' for consistency across models
|
@copilot open a new pull request to apply changes based on the comments in this thread |
…anitization Co-authored-by: tnaum-ms <171359267+tnaum-ms@users.noreply.github.com>
|
@copilot open a new pull request to apply changes based on the comments in this thread |
…stead of hyphen Co-authored-by: tnaum-ms <171359267+tnaum-ms@users.noreply.github.com>
4ef49d5
into
dev/tnaum/move-connection-protection
Refactor base cluster model architecture for clarity
Summary
This PR refactors the cluster model type hierarchy to cleanly separate intrinsic cluster data from tree positioning concerns, and to decouple the Connections View from Azure-specific types. It also fixes the "Could not find the specified collection in the tree" error when operating on collections from Discovery View webviews.
Problem
Type coupling:
ClusterModelinherited Azure SDKResourcemetadata, forcing all views (including Connections View) to carry Azure-specific fields.ID confusion: The single
idproperty served two incompatible purposes:Export/import failures in Discovery View: Operations on collections opened from Discovery View clusters failed because
findCollectionByClusterIdcouldn't translate theclusterIdback to atreeIdto locate the collection in the tree.Solution
1. New Type Hierarchy
Introduce explicit separation of concerns with a new type hierarchy:
Tree positioning is handled by
ClusterTreeContext, and tree items useTreeCluster<T>to combine data + positioning.2. Dual ID Architecture
treeIddiscoveryView/providerId/subId/clusterIdclusterIdazure-mongo-vcore-discovery_sanitizedId3. Discovery View Plugin Contract
Plugins must set
clusterIdwith a{providerId}_prefix:This enables
findCollectionByClusterIdto:_)findChildByIdmethod4. New
findChildByIdMethodAdded to
BaseExtendedTreeDataProviderto search from a specific parent without ancestor fallback. This prevents a bug where deleted collections would trigger expansion of ALL sibling clusters in the subscription.Key Changes
New Models:
src/tree/models/BaseClusterModel.ts- Core cluster interface withtreeId,clusterIdsrc/tree/connections-view/models/ConnectionClusterModel.ts- Connections View modelsrc/tree/azure-views/models/AzureClusterModel.ts- Azure Views model +sanitizeAzureResourceIdForTreeId()helperTree Infrastructure:
src/tree/BaseExtendedTreeDataProvider.ts- AddedfindChildById()methodsrc/tree/TreeParentCache.ts- AddedfindNodeBySuffix()methodsrc/tree/discovery-view/clusterItemTypeGuard.ts- Type guard for cluster itemsDiscovery View:
src/tree/discovery-view/DiscoveryBranchDataProvider.ts- AddedvalidateClusterIdPrefix(), updatedfindCollectionByClusterIdclusterIdConnections View:
src/tree/connections-view/ConnectionsBranchDataProvider.ts- UsesConnectionClusterModelsrc/tree/connections-view/FolderItem.ts- SetstreeIdandclusterIdcorrectlyCache Operations:
cluster.clusterIdfor cache lookupsCredentialCacheandClustersClientdocumentation updatedID Strategy Summary
clusterId(cache key)treeId(tree element ID)storageId(UUID)connectionsView/[folder/]storageId{providerId}_{sanitizedId}discoveryView/{providerId}/.../sanitizedId{sanitizedId}{sanitizedId}(same as clusterId)Key constraint: Original (unsanitized) Azure Resource IDs contain
/which breaks tree path parsing. We sanitize by replacing/with_.findCollectionByClusterIdImplementationConnections View: Uses
buildFullTreePath(clusterId)to reconstruct full tree path from storage.Discovery View (fixed in this PR):
Tests
npm run build✅npm run lint✅Breaking Changes
ClusterModelis now a deprecated union type pointing to the new specific typesNotes
findChildByIdmethod is preferred overfindNodeByIdwhen you have the parent, as it avoids ancestor fallback that can cause unintended tree expansionclusterIdstarts withproviderId