Skip to content

Fix metadata filtering by package in Studio#1048

Merged
hotlong merged 2 commits intomainfrom
claude/fix-metadata-filtering-on-package-switch
Apr 2, 2026
Merged

Fix metadata filtering by package in Studio#1048
hotlong merged 2 commits intomainfrom
claude/fix-metadata-filtering-on-package-switch

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Apr 2, 2026

When switching packages in Studio's left sidebar, the metadata panel displayed items from all packages instead of filtering by the selected package. Two root causes: (1) selectedMeta state persisted across package switches, and (2) client.meta.getItem() lacked package filtering despite getItems() already supporting it.

Changes

Frontend

  • Clear selectedMeta state in handleSelectPackage to prevent stale metadata display
  • Thread packageId through PluginHostMetadataViewerPropsMetadataInspector
  • Pass selectedPackage.manifest.id from App to both object and metadata views

Client API

  • Add optional packageId parameter to meta.getItem(type, name, options?)
  • Construct ?package= query string when packageId provided

Backend

  • Extract packageId from query.package in /metadata/:type/:name handler
  • Pass to protocol.getMetaItem({ type, name, packageId })

All changes maintain backward compatibility—packageId is optional throughout.

// Before: metadata from all packages displayed
await client.meta.getItem('flow', 'my_flow')

// After: scoped to selected package
await client.meta.getItem('flow', 'my_flow', { packageId: 'my-package' })

@Claude Claude AI assigned Claude and hotlong Apr 2, 2026
@Claude Claude AI linked an issue Apr 2, 2026 that may be closed by this pull request
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-play Ready Ready Preview, Comment Apr 2, 2026 1:29am
spec Ready Ready Preview, Comment Apr 2, 2026 1:29am

Request Review

- Clear selectedMeta when switching packages in App.tsx
- Add packageId parameter to client.meta.getItem() method
- Pass selectedPackage.manifest.id through PluginHost to MetadataInspector
- Update backend http-dispatcher to extract and pass packageId to protocol.getMetaItem()
- Update MetadataViewerProps to include optional packageId field
- MetadataInspector now filters metadata by package when packageId is provided

Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/fd48007b-701b-4729-85ba-26954cf662ce

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
@Claude Claude AI changed the title [WIP] Fix metadata display issue when switching packages in Studio Fix metadata filtering by package in Studio Apr 2, 2026
@Claude Claude AI requested a review from hotlong April 2, 2026 01:28
@hotlong hotlong marked this pull request as ready for review April 2, 2026 02:42
Copilot AI review requested due to automatic review settings April 2, 2026 02:42
@hotlong hotlong merged commit da5c2f1 into main Apr 2, 2026
3 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 aims to ensure Studio’s metadata inspector is scoped to the currently selected package by clearing stale selection state on package switch and threading an optional packageId filter from Studio UI → client API → backend handler.

Changes:

  • Studio: clear selectedMeta when switching packages and pass selectedPackage.manifest.id into PluginHost/viewer props.
  • Studio plugin/viewer plumbing: add packageId?: string to MetadataViewerProps and forward it through the default viewer into MetadataInspector.
  • Client + runtime: add optional { packageId } to client.meta.getItem(...) and forward ?package= through the runtime metadata handler into protocol.getMetaItem(...).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/runtime/src/http-dispatcher.ts Extracts query.package and forwards it as packageId to protocol.getMetaItem(...).
packages/client/src/index.ts Extends meta.getItem to accept { packageId?: string } and appends ?package= when provided.
apps/studio/src/plugins/types.ts Adds optional packageId to MetadataViewerProps.
apps/studio/src/plugins/plugin-host.tsx Accepts packageId and forwards it into the resolved viewer component.
apps/studio/src/plugins/built-in/default-plugin.tsx Forwards packageId into MetadataInspector.
apps/studio/src/components/MetadataInspector.tsx Uses packageId when calling client.meta.getItem(...) and reloads when it changes.
apps/studio/src/App.tsx Clears selectedMeta on package switch and passes selected package ID into PluginHost.

Comment on lines 436 to 441
// Try Protocol Service First (Preferred)
const protocol = await this.resolveService('protocol');
if (protocol && typeof protocol.getMetaItem === 'function') {
try {
const data = await protocol.getMetaItem({ type: singularType, name });
const data = await protocol.getMetaItem({ type: singularType, name, packageId });
return { handled: true, response: this.success(data) };
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

packageId is being passed into protocol.getMetaItem(...), but the current protocol implementation in this repo (packages/objectql/src/protocol.ts) defines getMetaItem(request: { type, name }) and ignores any packageId field, so this change won’t actually scope lookups by package. To make package filtering effective, update the protocol contract + implementation to accept packageId and use it when resolving from SchemaRegistry (prefer ${packageId}:${name} / _packageId-tagged items) and in any DB fallback query (e.g., include packageId in the where clause when provided).

Copilot uses AI. Check for mistakes.
Comment on lines 441 to 443
return { handled: true, response: this.success(data) };
} catch (e: any) {
// Protocol might throw if not found or not supported
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

If protocol.getMetaItem(...) throws, this handler falls through to the broker-based lookup below, which currently does not receive packageId. That means package scoping can be lost depending on which backend implementation is active. Consider ensuring the fallback path also receives the package filter (or explicitly returning a scoped-not-found) to keep behavior consistent.

Copilot uses AI. Check for mistakes.
Comment on lines +387 to +388
// Extract optional package filter from query string
const packageId = query?.package || undefined;
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

There are existing unit tests for handleMetadata, but none assert the new query.packagepackageId behavior for GET /meta/:type/:name. Add a test that passes a query object with package set and verifies the protocol is invoked with that packageId (and/or that the scoped item is returned).

Copilot uses AI. Check for mistakes.
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.

Studio 左侧切换软件包时元数据未按包过滤

3 participants