Skip to content

Commit

Permalink
show delta links when property is present (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Jun 7, 2021
1 parent 267cf08 commit df6425b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
32 changes: 23 additions & 9 deletions src/app/views/query-response/response/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ import { setSampleQuery } from '../../../services/actions/query-input-action-cre
import { convertVhToPx, getResponseHeight } from '../../common/dimensions-adjustment';
import ResponseDisplay from './ResponseDisplay';

interface OdataLink {
link: string;
name: string;
};

const Response = () => {
const dispatch = useDispatch();

const { dimensions: { response }, graphResponse, responseAreaExpanded, sampleQuery } = useSelector((state: IRootState) => state);
const { body, headers } = graphResponse;

const height = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 100);
const nextLink = getNextLinkFromBody(body);
const odataLink = getOdataLinkFromBody(body);

const setQuery = () => {
const query: IQuery = { ...sampleQuery };
query.sampleUrl = nextLink!;
query.sampleUrl = odataLink!.link;
dispatch(setSampleQuery(query));
dispatch(runQuery(query));
}
Expand All @@ -31,11 +36,11 @@ const Response = () => {
const contentType = getContentType(headers);
return (
<div style={{ display: 'block' }}>
{nextLink &&
{odataLink &&
<MessageBar messageBarType={MessageBarType.info}>
<FormattedMessage id='This response contains an @odata.nextLink property.' />
<FormattedMessage id={`This response contains an @odata property`} />: @odata.{odataLink!.name}
<Link onClick={() => setQuery()}>
&nbsp;<FormattedMessage id='Click here to go to the next page' />
&nbsp;<FormattedMessage id='Click here to follow the link' />
</Link>
</MessageBar>
}
Expand All @@ -50,11 +55,20 @@ const Response = () => {
return <div />;
};

function getNextLinkFromBody(body: any) {
if (body && body['@odata.nextLink']) {
return decodeURIComponent(body['@odata.nextLink']);
function getOdataLinkFromBody(body: any): OdataLink | null {
const odataLinks = ['nextLink', 'deltaLink'];
let data = null;
if (body) {
odataLinks.forEach(link => {
if (body[`@odata.${link}`]) {
data = {
link: decodeURIComponent(body[`@odata.${link}`]),
name: link
};
}
});
}
return null;
return data;
}

function getContentType(headers: any) {
Expand Down
4 changes: 2 additions & 2 deletions src/messages/GE.json
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@
"Report an Issue": "Report an Issue",
"Maximize sidebar": "Maximize sidebar",
"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",
"and experiment on": " and experiment on",
"Scope consent failed": "Scope consent failed",
"Missing url": "Please enter a valid url to run the query",
"This response contains an @odata property.": "This response contains an @odata property.",
"Click here to follow the link": "Click here to follow the link",
"Signing you out...": "Signing you out..."
}

0 comments on commit df6425b

Please sign in to comment.