From 20f67242038e4e1ea1b879ff1d2b6b73fcf14d1a Mon Sep 17 00:00:00 2001 From: Charles Wahome Date: Wed, 24 Feb 2021 12:31:46 +0300 Subject: [PATCH] Feature: make paging easier (#861) --- .../query-response/response/Response.tsx | 78 ++++++++++--------- .../response/ResponseDisplay.tsx | 28 +++++++ src/messages/GE.json | 4 +- 3 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 src/app/views/query-response/response/ResponseDisplay.tsx diff --git a/src/app/views/query-response/response/Response.tsx b/src/app/views/query-response/response/Response.tsx index b20b0a1cb2..859796b3cf 100644 --- a/src/app/views/query-response/response/Response.tsx +++ b/src/app/views/query-response/response/Response.tsx @@ -1,35 +1,61 @@ +import { Link, MessageBar, MessageBarType } from 'office-ui-fabric-react'; import React from 'react'; -import { useSelector } from 'react-redux'; +import { FormattedMessage } from 'react-intl'; +import { useDispatch, useSelector } from 'react-redux'; -import { ContentType } from '../../../../types/enums'; -import { isImageResponse } from '../../../services/actions/query-action-creator-util'; -import { Image, Monaco } from '../../common'; +import { IQuery } from '../../../../types/query-runner'; +import { runQuery } from '../../../services/actions/query-action-creators'; +import { setSampleQuery } from '../../../services/actions/query-input-action-creators'; import { convertVhToPx, getResponseHeight } from '../../common/dimensions-adjustment'; -import { formatXml } from '../../common/monaco/util/format-xml'; +import ResponseDisplay from './ResponseDisplay'; const Response = () => { - const language = 'json'; + const dispatch = useDispatch(); - const { dimensions: { response }, graphResponse, responseAreaExpanded } = useSelector((state: any) => state); + const { dimensions: { response }, graphResponse, responseAreaExpanded, sampleQuery } = useSelector((state: any) => state); const { body, headers } = graphResponse; const height = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 100); + const nextLink = getNextLinkFromBody(body); + + const setQuery = () => { + const query: IQuery = { ...sampleQuery }; + query.sampleUrl = nextLink!; + dispatch(setSampleQuery(query)); + dispatch(runQuery(query)); + } if (headers) { const contentType = getContentType(headers); - return (
- {displayComponent({ - contentType, - body, - height, - language - })} -
); + return ( +
+ {nextLink && + + + setQuery()}> +   + + + } + +
+ ); } return
; }; +function getNextLinkFromBody(body: any) { + if (body && body['@odata.nextLink']) { + return decodeURIComponent(body['@odata.nextLink']); + } + return null; +} + function getContentType(headers: any) { let contentType = null; @@ -46,26 +72,4 @@ function getContentType(headers: any) { return contentType; } -function displayComponent(properties: any) { - const { contentType, body, height, language } = properties; - - switch (contentType) { - case ContentType.XML: - return ; - - case ContentType.HTML: - return ; - - default: - if (isImageResponse(contentType)) { - return profile image; - } - return ; - } -} - export default Response; diff --git a/src/app/views/query-response/response/ResponseDisplay.tsx b/src/app/views/query-response/response/ResponseDisplay.tsx new file mode 100644 index 0000000000..e4e11ef268 --- /dev/null +++ b/src/app/views/query-response/response/ResponseDisplay.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { ContentType } from '../../../../types/enums'; +import { isImageResponse } from '../../../services/actions/query-action-creator-util'; +import { Image, Monaco } from '../../common'; +import { formatXml } from '../../common/monaco/util/format-xml'; + +const ResponseDisplay = (properties: any) => { + const { contentType, body, height } = properties; + + switch (contentType) { + case ContentType.XML: + return ; + + case ContentType.HTML: + return ; + + default: + if (isImageResponse(contentType)) { + return profile image; + } + return ; + } +} + +export default ResponseDisplay; diff --git a/src/messages/GE.json b/src/messages/GE.json index 8984122abe..7bac259a3d 100644 --- a/src/messages/GE.json +++ b/src/messages/GE.json @@ -346,5 +346,7 @@ "JSON Schema": "JSON Schema", "Report an Issue": "Report an Issue", "Maximize sidebar": "Maximize sidebar", - "Getting your access token": "Getting your access token" + "Getting your access token": "Getting your access token", + "This response contains an @odata.nextLink property.": "This response contains an @odata.nextLink property.", + "Click here to go to the next page": "Click here to go to the next page" } \ No newline at end of file