From a1f59a7f40669a01dad1481ec33583d3b26fb199 Mon Sep 17 00:00:00 2001 From: Andrew Jiang Date: Fri, 3 May 2024 12:52:31 -0400 Subject: [PATCH] feat: render pdf and a download button in API Playground (#791) --- .../src/api-playground/PlaygroundDrawer.tsx | 7 ++- .../PlaygroundEndpointContent.tsx | 51 ++++++++++++++-- .../form/PlaygroundFileUploadForm.tsx | 58 ++++++++++++++----- .../ui/app/src/components/FernAudioPlayer.tsx | 4 +- .../app/src/components/FernErrorBoundary.tsx | 34 ++++++++++- 5 files changed, 128 insertions(+), 26 deletions(-) diff --git a/packages/ui/app/src/api-playground/PlaygroundDrawer.tsx b/packages/ui/app/src/api-playground/PlaygroundDrawer.tsx index 43ae426b9d..6b552c1d8e 100644 --- a/packages/ui/app/src/api-playground/PlaygroundDrawer.tsx +++ b/packages/ui/app/src/api-playground/PlaygroundDrawer.tsx @@ -363,7 +363,12 @@ export const PlaygroundDrawer: FC = ({ apis }) => { )}
{layoutBreakpoint === "mobile" ? mobileHeader : desktopHeader}
- + {selectionState?.type === "endpoint" && matchedEndpoint != null ? ( = ({ sendRequest, types, }) => { + const { domain } = useDocsContext(); const { isSnippetTemplatesEnabled } = useFeatureFlags(); const [requestType, setRequestType] = useAtom(requestTypeAtom); @@ -205,7 +208,21 @@ export const PlaygroundEndpointContent: FC = ({ loading: () =>
, loaded: (response) => response.type === "file" ? ( -
+ + + } + size="small" + variant="minimal" + onClick={() => { + const a = document.createElement("a"); + a.href = response.response.body; + a.download = createFilename(response.response, response.contentType); + a.click(); + }} + /> + + ) : ( @@ -237,17 +254,25 @@ export const PlaygroundEndpointContent: FC = ({ loaded: (response) => response.type !== "file" ? ( - ) : response.contentType.startsWith("audio/") ? ( + ) : response.contentType.startsWith("audio/") || + (domain.includes("ircamamplify") && response.contentType === "binary/octet-stream") ? ( + ) : response.contentType.includes("application/pdf") ? ( +