Skip to content

Commit

Permalink
Fix: Share query errors (#501)
Browse files Browse the repository at this point in the history
* fixes header undefined error when sharing link

* add null check for headers passed from url
  • Loading branch information
thewahome committed May 6, 2020
1 parent df7d325 commit 13e244c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
26 changes: 3 additions & 23 deletions src/app/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { clearQueryStatus } from '../services/actions/query-status-action-creato
import { clearTermsOfUse } from '../services/actions/terms-of-use-action-creator';
import { changeThemeSuccess } from '../services/actions/theme-action-creator';
import { toggleSidebar } from '../services/actions/toggle-sidebar-action-creator';
import { getLoginType, logIn } from '../services/graph-client/msal-service';
import { logIn } from '../services/graph-client/msal-service';
import { parseSampleUrl } from '../utils/sample-url-generation';
import { substituteTokens } from '../utils/token-helpers';
import { appTitleDisplayOnFullScreen, appTitleDisplayOnMobileScreen } from './app-sections/AppTitle';
Expand Down Expand Up @@ -155,7 +155,7 @@ class App extends Component<IAppProps, IAppState> {
selectedVerb: method,
selectedVersion: version,
sampleBody: this.hashDecode(requestBody),
sampleHeaders: JSON.parse(this.hashDecode(headers)),
sampleHeaders: (headers) ? JSON.parse(this.hashDecode(headers)) : [],
};
}

Expand Down Expand Up @@ -246,25 +246,6 @@ class App extends Component<IAppProps, IAppState> {
});
};

public promptNewLogin = async () => {
this.closeDialog();
localStorage.clear();
const { mscc } = (window as any);

if (mscc) {
mscc.setConsent();
}

setTimeout(async () => {
const authResponse = await logIn();
if (authResponse) {
this.props.actions!.signIn(authResponse.accessToken);
this.props.actions!.storeScopes(authResponse.scopes);
}
}, 700);

}

public toggleSidebar = (): void => {
const { sidebarProperties } = this.props;
const properties = { ...sidebarProperties };
Expand Down Expand Up @@ -324,7 +305,6 @@ class App extends Component<IAppProps, IAppState> {
const historyHeaderText = messages['History'];
const { mobileScreen, showSidebar } = sidebarProperties;
const language = navigator.language || 'en-US';
const loginType = getLoginType();

let displayContent = true;
if (graphExplorerMode === Mode.Complete) {
Expand Down Expand Up @@ -391,7 +371,7 @@ class App extends Component<IAppProps, IAppState> {
</div>
)}
<div className={layout}>
{graphExplorerMode.TryIt && headerMessaging(loginType, classes, query)}
{graphExplorerMode === Mode.TryIt && headerMessaging(classes, query)}

{displayContent && <>
<div style={{ marginBottom: 8 }}>
Expand Down
7 changes: 6 additions & 1 deletion src/app/views/app-sections/HeaderMessaging.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { MessageBar, MessageBarType } from 'office-ui-fabric-react';
import React from 'react';
import { FormattedMessage } from 'react-intl';

import { LoginType } from '../../../types/enums';
import { getLoginType } from '../../services/graph-client/msal-service';
import { Authentication } from '../authentication';
export function headerMessaging(loginType: LoginType, classes: any, query: string): React.ReactNode {

export function headerMessaging(classes: any, query: string): React.ReactNode {
const loginType = getLoginType();

return (
<div style={{ marginBottom: 8 }}>
{loginType === LoginType.Popup && <>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/common/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const createShareLink = (sampleQuery: IQuery, authenticated?: boolean): s
// tslint:disable-next-line:max-line-length
`${appUrl}?request=${graphUrlRequest}&method=${selectedVerb}&version=${queryVersion}&GraphUrl=${graphUrl}&requestBody=${requestBody}`;

if (sampleHeaders.length > 0) {
if (sampleHeaders && sampleHeaders.length > 0) {
const headers = hashEncode(JSON.stringify(sampleHeaders));
shareLink = `${shareLink}&headers=${headers}`;
}
Expand Down

0 comments on commit 13e244c

Please sign in to comment.