Skip to content

Commit dae5e20

Browse files
Fix swagger UI missing (microsoft#3552)
Recent regression with the new program viewer refactoring
1 parent a81c7fb commit dae5e20

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
3+
changeKind: internal
4+
packages:
5+
- "@typespec/playground"
6+
---
7+
8+
Fix swagger UI missing

packages/playground/src/react/output-view/file-viewer.tsx

+18-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import { FolderListRegular } from "@fluentui/react-icons";
22
import { useCallback, useEffect, useState } from "react";
33
import { FileOutput } from "../file-output/file-output.js";
44
import { OutputTabs } from "../output-tabs/output-tabs.js";
5-
import type { OutputViewerProps, ProgramViewer } from "../types.js";
5+
import type { FileOutputViewer, OutputViewerProps, ProgramViewer } from "../types.js";
66

77
import style from "./output-view.module.css";
88

9-
const FileViewerComponent = ({ program, outputFiles }: OutputViewerProps) => {
9+
const FileViewerComponent = ({
10+
program,
11+
outputFiles,
12+
fileViewers,
13+
}: OutputViewerProps & { fileViewers: Record<string, FileOutputViewer> }) => {
1014
const [filename, setFilename] = useState<string>("");
1115
const [content, setContent] = useState<string>("");
1216

@@ -42,15 +46,20 @@ const FileViewerComponent = ({ program, outputFiles }: OutputViewerProps) => {
4246
<div className={style["file-viewer"]}>
4347
<OutputTabs filenames={outputFiles} selected={filename} onSelect={handleTabSelection} />
4448
<div className={style["file-viewer-content"]}>
45-
<FileOutput filename={filename} content={content} viewers={[] as any} />
49+
<FileOutput filename={filename} content={content} viewers={fileViewers} />
4650
</div>
4751
</div>
4852
);
4953
};
5054

51-
export const FileViewer: ProgramViewer = {
52-
key: "file-output",
53-
label: "Output explorer",
54-
icon: <FolderListRegular />,
55-
render: FileViewerComponent,
56-
};
55+
export function createFileViewer(fileViewers: FileOutputViewer[]): ProgramViewer {
56+
const viewerMap = Object.fromEntries(fileViewers.map((x) => [x.key, x]));
57+
return {
58+
key: "file-output",
59+
label: "Output explorer",
60+
icon: <FolderListRegular />,
61+
render: (props) => {
62+
return <FileViewerComponent {...props} fileViewers={viewerMap} />;
63+
},
64+
};
65+
}

packages/playground/src/react/output-view/output-view.tsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Tab, TabList, type SelectTabEventHandler } from "@fluentui/react-compon
22
import { useCallback, useMemo, useState, type FunctionComponent } from "react";
33
import type { PlaygroundEditorsOptions } from "../playground.js";
44
import type { CompilationState, CompileResult, FileOutputViewer, ProgramViewer } from "../types.js";
5-
import { FileViewer } from "./file-viewer.js";
5+
import { createFileViewer } from "./file-viewer.js";
66
import { TypeGraphViewer } from "./type-graph-viewer.js";
77

88
import style from "./output-view.module.css";
@@ -43,26 +43,22 @@ function resolveViewers(
4343
viewers: ProgramViewer[] | undefined,
4444
fileViewers: FileOutputViewer[] | undefined
4545
): ResolvedViewers {
46+
const fileViewer = createFileViewer(fileViewers ?? []);
4647
const output: ResolvedViewers = {
47-
fileViewers: {},
4848
programViewers: {
49-
[FileViewer.key]: FileViewer,
49+
[fileViewer.key]: fileViewer,
5050
[TypeGraphViewer.key]: TypeGraphViewer,
5151
},
5252
};
5353

5454
for (const item of viewers ?? []) {
5555
output.programViewers[item.key] = item;
5656
}
57-
for (const item of fileViewers ?? []) {
58-
output.fileViewers[item.key] = item;
59-
}
6057

6158
return output;
6259
}
6360

6461
interface ResolvedViewers {
65-
fileViewers: Record<string, FileOutputViewer>;
6662
programViewers: Record<string, ProgramViewer>;
6763
}
6864

0 commit comments

Comments
 (0)