Skip to content

Commit

Permalink
FUI - Getting language from content-type header in GQL console (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorohova authored Jan 30, 2025
1 parent dc1449a commit a7e6dbf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const TableBodyApis = ({ showApiType, apis, getReferenceUrl, detailsPageTarget }
{!!api.apiVersion && " - " + api.apiVersion}
</a>
</TableCell>
<TableCell style={{padding: ".5rem 0"}}>
<TableCell>
<MarkdownProcessor markdownToDisplay={api.description} maxChars={markdownMaxCharsMap.table} />
</TableCell>
{showApiType && <TableCell>{api.typeName}</TableCell>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ export const OperationConsoleGql = ({
response = await sendFromBrowser(request);
}

const responseLanguageValue = response.headers?.find(x => x.name === KnownHttpHeaders.ContentType)?.value;
const contentTypeHeader = response.headers?.get(x => x.name === KnownHttpHeaders.ContentType);
const mimeType = contentTypeHeader?.split(';').split('/');
const responseLanguageValue = ["css", "javascript", "json", "xml"].includes(mimeType[1]) ? mimeType[1] : "html";

console.log('response lang', contentTypeHeader, mimeType, responseLanguageValue);


const responseStr = Buffer.from(response.body.buffer).toString();
setSelectedTab(ConsoleTab.response);
setResponse(responseStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ConsoleBody = ({
const [file, setFile] = useState<File>(binary);
const [bodyFormatState, setBodyFormatState] = useState<RequestBodyType>(bodyFormat ?? RequestBodyType.raw);
const [selectedRepresentation, setSelectedRepresentation] = useState<ConsoleRepresentation>(representations?.[0] ?? null);
const [selectedRepresentationId, setSelectedRepresentationId] = useState<string>(selectedRepresentation?.typeName + "+" + selectedRepresentation?.contentType ?? "");
const [selectedRepresentationId, setSelectedRepresentationId] = useState<string>(selectedRepresentation ? selectedRepresentation.typeName + "+" + selectedRepresentation.contentType : "");
const [initialBody, setInitialBody] = useState<string>(selectedRepresentation?.sample ?? "");
const [isBodyEdited, setIsBodyEdited] = useState<boolean>(
(bodyFormat === RequestBodyType.raw && body !== initialBody) || (bodyFormat === RequestBodyType.binary && binary !== null) || false
Expand All @@ -48,7 +48,7 @@ export const ConsoleBody = ({
setFile(binary);
setBodyFormatState(bodyFormat);
setSelectedRepresentation(representations[0] ?? null);
setSelectedRepresentationId(representations[0]?.typeName + "+" + representations[0]?.contentType ?? "");
setSelectedRepresentationId(representations[0] ? representations[0].typeName + "+" + representations[0].contentType : "");
setInitialBody(representations[0]?.sample ?? "");
}, [binary, bodyFormat, representations]);

Expand Down

0 comments on commit a7e6dbf

Please sign in to comment.