Skip to content

Commit

Permalink
Fix: sovereign clouds metadata (#676)
Browse files Browse the repository at this point in the history
* fix crashing when fetching soverign metadata

* remove dead code

* add comment to explain why only the first value is taken
  • Loading branch information
thewahome committed Sep 1, 2020
1 parent 5e634dd commit d0de298
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/app/services/actions/query-action-creator-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function authenticatedRequest(dispatch: Function, query: IQuery,
return makeRequest(query.selectedVerb, scopes)(dispatch, query);
}

export function isImageResponse(contentType: string) {
export function isImageResponse(contentType: string | undefined) {
if (!contentType) { return false; }
return (
contentType === 'application/octet-stream' ||
Expand Down
6 changes: 2 additions & 4 deletions src/app/views/common/monaco/Monaco.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FocusZone, getTheme } from 'office-ui-fabric-react';
import { FocusZone } from 'office-ui-fabric-react';
import React from 'react';
import MonacoEditor, { ChangeHandler } from 'react-monaco-editor';

Expand Down Expand Up @@ -32,14 +32,12 @@ function formatDocument(editor: any) {
export function Monaco(props: IMonaco) {

let { body } = props;
const { onChange, verb, language, readOnly } = props;
const { onChange, language, readOnly } = props;

if (body && typeof body !== 'string') {
body = JSON.stringify(body);
}

const verbIsGet = verb === 'GET';

return (
<FocusZone disabled={true}>
<div className='monaco-editor'>
Expand Down
22 changes: 17 additions & 5 deletions src/app/views/query-response/pivot-items/pivot-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Snippets } from '../snippets';
export const getPivotItems = (properties: any) => {

const { headers, body, verb, messages, mobileScreen, mode, sampleQuery } = properties;
const resultComponent = displayResultComponent(headers, body, verb);
const resultComponent = displayResultComponent(headers, body);

const pivotItems = [
<PivotItem
Expand Down Expand Up @@ -105,13 +105,25 @@ function adaptiveCardPresentDot(sampleQuery: IQuery) {
return null;
}

function displayResultComponent(headers: any, body: any, verb: string) {
function displayResultComponent(headers: any, body: any) {
const language = 'json';
let contentType = null;

if (headers) {
const contentType = headers['content-type'].split(';')[0];
const contentTypes = headers['content-type'];
if (contentTypes) {
/* Example: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8
* Take the first option after splitting since it is the only value useful in the description of the content
*/
const splitContentTypes = contentTypes.split(';');
if (splitContentTypes.length > 0) {
contentType = splitContentTypes[0];
}
}

switch (contentType) {
case ContentType.XML:
return <Monaco body={formatXml(body)} verb={verb} language='xml' />;
return <Monaco body={formatXml(body)} language='xml' />;

default:
if (isImageResponse(contentType)) {
Expand All @@ -121,7 +133,7 @@ function displayResultComponent(headers: any, body: any, verb: string) {
alt='profile image'
/>;
}
return <Monaco body={body} verb={verb} language={language} />;
return <Monaco body={body} language={language} />;
}
}
}
Expand Down

0 comments on commit d0de298

Please sign in to comment.