Address PR #1214 code review feedback
- Fix template-expanded URIs not rendering: construct synthetic Resource from readState.uri when the URI is absent from the resources list - Fix non-image blob content rendering raw base64: show placeholder message; also handle audio blobs properly - Hide mimeType display when multiple content items to avoid confusion - Rename ResourceControls selectedTemplate → selectedTemplateUri for consistency with selectedUri and selectedResourceUri Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d817c46911
commit
8c9aac6df1
3 changed files with 26 additions and 12 deletions
|
|
@ -22,7 +22,7 @@ export interface ResourceControlsProps {
|
|||
templates: ResourceTemplate[];
|
||||
subscriptions: InspectorResourceSubscription[];
|
||||
selectedUri?: string;
|
||||
selectedTemplate?: string;
|
||||
selectedTemplateUri?: string;
|
||||
listChanged: boolean;
|
||||
onRefreshList: () => void;
|
||||
onSelectUri: (uri: string) => void;
|
||||
|
|
@ -46,7 +46,7 @@ export function ResourceControls({
|
|||
templates,
|
||||
subscriptions,
|
||||
selectedUri,
|
||||
selectedTemplate,
|
||||
selectedTemplateUri,
|
||||
listChanged,
|
||||
onRefreshList,
|
||||
onSelectUri,
|
||||
|
|
@ -137,9 +137,9 @@ export function ResourceControls({
|
|||
<ResourceListItem
|
||||
key={template.uriTemplate}
|
||||
resource={template}
|
||||
selected={template.uriTemplate === selectedTemplate}
|
||||
selected={template.uriTemplate === selectedTemplateUri}
|
||||
onClick={() => {
|
||||
if (template.uriTemplate !== selectedTemplate)
|
||||
if (template.uriTemplate !== selectedTemplateUri)
|
||||
onSelectTemplate(template.uriTemplate);
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -30,7 +30,13 @@ function toContentBlock(
|
|||
if (mimeType.startsWith("image/")) {
|
||||
return { type: "image", data: item.blob, mimeType };
|
||||
}
|
||||
return { type: "text", text: item.blob };
|
||||
if (mimeType.startsWith("audio/")) {
|
||||
return { type: "audio", data: item.blob, mimeType };
|
||||
}
|
||||
return {
|
||||
type: "text",
|
||||
text: `[Binary content (${mimeType}) — preview not supported]`,
|
||||
};
|
||||
}
|
||||
|
||||
function formatLastUpdated(date: Date): string {
|
||||
|
|
@ -113,7 +119,7 @@ export function ResourcePreviewPanel({
|
|||
) : (
|
||||
<Spacer />
|
||||
)}
|
||||
<MimeText>{mimeType}</MimeText>
|
||||
{contents.length <= 1 && <MimeText>{mimeType}</MimeText>}
|
||||
</MetaRow>
|
||||
<FooterRow>
|
||||
<AnnotationGroup>
|
||||
|
|
|
|||
|
|
@ -96,6 +96,14 @@ export function ResourcesScreen({
|
|||
? templates.find((t) => t.uriTemplate === selectedTemplateUri)
|
||||
: undefined;
|
||||
|
||||
// For template-expanded URIs that don't appear in the resources list,
|
||||
// construct a synthetic Resource so the preview panel can render.
|
||||
const readResource: Resource | undefined =
|
||||
selectedResource ??
|
||||
(readState?.uri && readState.uri === selectedResourceUri
|
||||
? { name: readState.uri, uri: readState.uri }
|
||||
: undefined);
|
||||
|
||||
function renderReadState() {
|
||||
if (!readState) return null;
|
||||
|
||||
|
|
@ -120,17 +128,17 @@ export function ResourcesScreen({
|
|||
);
|
||||
}
|
||||
|
||||
if (readState.result && selectedResource) {
|
||||
if (readState.result && readResource) {
|
||||
return (
|
||||
<DetailCard>
|
||||
<ResourcePreviewPanel
|
||||
resource={selectedResource}
|
||||
resource={readResource}
|
||||
contents={readState.result.contents}
|
||||
lastUpdated={readState.lastUpdated}
|
||||
isSubscribed={readState.isSubscribed ?? false}
|
||||
onRefresh={() => onReadResource(selectedResource.uri)}
|
||||
onSubscribe={() => onSubscribeResource(selectedResource.uri)}
|
||||
onUnsubscribe={() => onUnsubscribeResource(selectedResource.uri)}
|
||||
onRefresh={() => onReadResource(readResource.uri)}
|
||||
onSubscribe={() => onSubscribeResource(readResource.uri)}
|
||||
onUnsubscribe={() => onUnsubscribeResource(readResource.uri)}
|
||||
/>
|
||||
</DetailCard>
|
||||
);
|
||||
|
|
@ -148,7 +156,7 @@ export function ResourcesScreen({
|
|||
templates={templates}
|
||||
subscriptions={subscriptions}
|
||||
selectedUri={selectedResourceUri}
|
||||
selectedTemplate={selectedTemplateUri}
|
||||
selectedTemplateUri={selectedTemplateUri}
|
||||
listChanged={listChanged}
|
||||
onRefreshList={onRefreshList}
|
||||
onSelectUri={onSelectUri}
|
||||
|
|
|
|||
Loading…
Reference in a new issue