Skip to content

Commit

Permalink
Merge branch 'dev' into dependabot-upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed May 3, 2024
2 parents 9c89f18 + 38c3849 commit 5b7e475
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 81 deletions.
99 changes: 58 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/app/services/actions/query-action-creator-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ export async function generateResponseDownloadUrl(
}
}

async function tryParseJson(textValue: string) {
try {
return JSON.parse(textValue);
} catch (error) {
return textValue;
}
}

export function parseResponse(
response: any,
respHeaders: any = {}
Expand All @@ -233,9 +241,10 @@ export function parseResponse(
const contentType = getContentType(response.headers);
switch (contentType) {
case ContentType.Json:
return response.json();
return response.text().then(tryParseJson);
case ContentType.XML:
case ContentType.HTML:
case ContentType.TextCsv:
case ContentType.TextPlain:
return response.text();

Expand Down
4 changes: 2 additions & 2 deletions src/app/services/actions/query-action-creators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export function runQuery(query: IQuery) {
};

if (error instanceof ClientError) {
status.status = 0;
status.statusText = `${error.name}: ${error.message}`;
status.status = error.message;
status.statusText = error.name;
}

if (queryResultsInCorsError(query.sampleUrl)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export const ValidationProvider = ({ children }: ValidationProviderProps) => {
}, [resources])

useEffect(() => {
if (!queryVersion || !query || Object.keys(resources.data).length === 0) {
return;
}
if (version !== queryVersion && GRAPH_API_VERSIONS.includes(queryVersion)
&& resources.data[queryVersion].children!.length > 0) {
setVersionedResources(resources.data[queryVersion].children!);
Expand Down
15 changes: 8 additions & 7 deletions src/app/views/query-response/response/Response.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@

import { useDispatch } from 'react-redux';

import { AppDispatch, useAppSelector } from '../../../../store';
import { useAppSelector } from '../../../../store';
import { getContentType } from '../../../services/actions/query-action-creator-util';
import { convertVhToPx, getResponseEditorHeight,
getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import {
convertVhToPx, getResponseEditorHeight,
getResponseHeight
} from '../../common/dimensions/dimensions-adjustment';
import ResponseDisplay from './ResponseDisplay';
import { ResponseMessages } from './ResponseMessages';

const Response = () => {
const { dimensions: { response }, graphResponse, responseAreaExpanded, sampleQuery, authToken, graphExplorerMode } =
const { dimensions: { response }, graphResponse, responseAreaExpanded} =
useAppSelector((state) => state);
const { body, headers } = graphResponse;
const dispatch: AppDispatch = useDispatch();

const defaultHeight = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 220);
const monacoHeight = getResponseEditorHeight(150);

const contentDownloadUrl = body?.contentDownloadUrl;
const throwsCorsError = body?.throwsCorsError;
const contentType = getContentType(headers);

return (
<div style={{ display: 'block' }}>
{ResponseMessages(graphResponse, sampleQuery, authToken, graphExplorerMode, dispatch)}
<ResponseMessages />
{!contentDownloadUrl && !throwsCorsError && headers &&
<ResponseDisplay
contentType={contentType}
Expand Down
Loading

0 comments on commit 5b7e475

Please sign in to comment.