Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: show delta link #978

Merged
merged 2 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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..."
}