Skip to content

Show index count on the Indexes folder node 🔢 #659

@tnaum-ms

Description

@tnaum-ms

Problem

The "Indexes" folder node in the tree view shows no indication of how many indexes a collection has. Users must expand the node to see its contents.

Current:
▼ my-collection
    ▶ Documents
    ▶ Indexes                        <-- no count

Expected:
▼ my-collection
    ▶ Documents
    ▶ Indexes                        (5 indexes)

Expected Behavior

After the IndexesItem node is rendered, it should show the index count as its description. Since the index list is fetched when the node is expanded (in getChildren()), the count can be updated after the first expansion, or loaded lazily in the background.

Development Hints

Since this is a good first issue, here are some hints on where to start:

Pattern to follow: src/tree/documentdb/CollectionItem.ts

CollectionItem implements a lazy loading pattern for document count that you can replicate. The approach uses:

  • A cached count field with three states: undefined (not loaded), number (loaded), null (failed)
  • A boolean guard to prevent duplicate fetches
  • A fire-and-forget method that loads the count and calls ext.state.notifyChildrenChanged(this.id) to refresh the tree item

Important consideration: Unlike document counts, the index list is already fetched when the user expands the IndexesItem node (via getChildren() which calls ClustersClient.listIndexes()). You should investigate whether the count can be derived from that existing fetch rather than making an extra API call. Possible approaches:

  1. After-expansion update: Cache the count after getChildren() runs and refresh the tree item to show it. This means the count appears after the first expansion.
  2. Lazy background loading: Replicate the CollectionItem pattern with a separate background fetch. This shows the count before expansion but makes an extra API call.

Evaluate which approach makes more sense. Copying the lazy loading code from CollectionItem is fine for this issue. We can create a follow-up refactoring issue to deduplicate the pattern later. The focus here is the feature, not code reuse.

File to modify: src/tree/documentdb/IndexesItem.ts

In getTreeItem(), add:

description: typeof this.indexCount === 'number'
    ? (this.indexCount === 1 ? l10n.t('1 index') : l10n.t('{0} indexes', this.indexCount))
    : undefined

The parent that creates IndexesItem is CollectionItem.getChildren() in src/tree/documentdb/CollectionItem.ts.

Files to Modify

File Change
src/tree/documentdb/IndexesItem.ts Add count tracking and description in getTreeItem()
src/tree/documentdb/CollectionItem.ts Optionally trigger lazy count loading when creating IndexesItem

Acceptance Criteria

  • IndexesItem shows index count as description (e.g., 5 indexes or 1 index)
  • Count loading does not block tree expansion
  • If count loading fails, no description is shown
  • Tooltip behavior unchanged

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions