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

Enhancement: Add more info to code snippets #1540

Merged
merged 29 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
953c1ae
add more information to code snippets
Onokaev Mar 4, 2022
947c33a
add shortened links to code snippets
Onokaev Mar 7, 2022
6e070e9
update GE json file
Onokaev Mar 8, 2022
3d663de
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 8, 2022
b94c979
add shortened links to snippets
Onokaev Mar 8, 2022
ce48f6f
add telemetry to cnode snippet links
Onokaev Mar 14, 2022
5ead9d4
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 14, 2022
e19a2be
fix console error
Onokaev Mar 15, 2022
add73d2
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 15, 2022
860641a
add noopener property
Onokaev Mar 15, 2022
091c873
fix code smell
Onokaev Mar 16, 2022
6819605
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 16, 2022
51fae85
adjust left margin
Onokaev Mar 16, 2022
97f29ee
remove condition
Onokaev Mar 16, 2022
c7fe0e1
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 28, 2022
6dd7ad6
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 29, 2022
be7043a
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 29, 2022
d3a03cf
Merge branch 'enhancement/code-snippets' of https://github.com/micros…
Onokaev Mar 29, 2022
035dab1
add colors for different themes
Onokaev Mar 30, 2022
83dd42f
add specific telemetry information for sdk links
Onokaev Mar 30, 2022
8c961eb
Merge branch 'dev' into enhancement/code-snippets
Onokaev Mar 30, 2022
9f8cbec
remove redundant code
Onokaev Mar 31, 2022
51949e7
Merge branch 'dev' into enhancement/code-snippets
Onokaev Apr 1, 2022
c1f1203
include telemetry for snippet doc links
Onokaev Apr 4, 2022
4cec235
Merge branch 'enhancement/code-snippets' of https://github.com/micros…
Onokaev Apr 4, 2022
d67191e
Merge branch 'dev' into enhancement/code-snippets
Onokaev Apr 4, 2022
415a8a4
update PR
Onokaev Apr 5, 2022
e8994d1
Merge branch 'dev' into enhancement/code-snippets
Onokaev Apr 6, 2022
06655d6
Merge branch 'dev' into enhancement/code-snippets
thewahome Apr 7, 2022
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
2 changes: 2 additions & 0 deletions src/app/views/common/monaco/Monaco.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface IMonaco {
language?: string;
readOnly?: boolean;
height?: string;
extraInfoElement?: JSX.Element;
}

export function Monaco(props: IMonaco) {
Expand All @@ -28,6 +29,7 @@ export function Monaco(props: IMonaco) {
return (
<FocusZone disabled={true}>
<div className='monaco-editor'>
{props.extraInfoElement}
<ThemeContext.Consumer >
{(theme) => (<Editor
width='800 !important'
Expand Down
34 changes: 26 additions & 8 deletions src/app/views/query-response/snippets/Snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,32 @@ import { componentNames, telemetry } from '../../../../telemetry';
import { renderSnippets } from './snippets-helper';

function GetSnippets() {
const supportedLanguages = [
'CSharp',
'JavaScript',
'Java',
'Objective-C',
'Go',
'PowerShell'
];
const supportedLanguages = {
'CSharp': {
sdkDownloadLink: 'https://aka.ms/csharpsdk',
sdkDocLink: 'https://aka.ms/sdk-doc'
},
'JavaScript': {
sdkDownloadLink: 'https://aka.ms/graphjssdk',
sdkDocLink: 'https://aka.ms/sdk-doc'
},
'Java': {
sdkDownloadLink: 'https://aka.ms/graphjavasdk',
sdkDocLink: 'https://aka.ms/sdk-doc'
},
'Objective-C': {
sdkDownloadLink: 'https://aka.ms/objective-c-sdk',
sdkDocLink: 'https://aka.ms/sdk-doc'
},
'Go': {
sdkDownloadLink: 'https://aka.ms/graphgosdk',
sdkDocLink: 'https://aka.ms/sdk-doc'
},
'PowerShell': {
sdkDownloadLink: 'https://aka.ms/pshellsdk',
sdkDocLink: 'https://aka.ms/pshellsdkdocs'
}
};

return <Pivot>{renderSnippets(supportedLanguages)}</Pivot>;
}
Expand Down
54 changes: 51 additions & 3 deletions src/app/views/query-response/snippets/snippets-helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,38 @@ import { convertVhToPx, getResponseHeight } from '../../common/dimensions/dimens
import { IRootState } from '../../../../types/root';
import { CODE_SNIPPETS_COPY_BUTTON } from '../../../../telemetry/component-names';
import { CopyButton } from '../../common/copy/CopyButton';
import { translateMessage } from '../../../utils/translate-messages';
import { componentNames, telemetry } from '../../../../telemetry';

interface ISnippetProps {
language: string;
snippetInfo: ISupportedLanguages;
}

export function renderSnippets(supportedLanguages: string[]) {
return supportedLanguages.map((language: string) => (
interface ISupportedLanguages {
[language: string]: {
sdkDownloadLink: string;
sdkDocLink: string;
};
}

export function renderSnippets(supportedLanguages: ISupportedLanguages) {
return Object.keys(supportedLanguages).map((language: string) => (
<PivotItem
key={language}
headerText={language}
headerButtonProps={{
'aria-controls': `${language}-tab`
}}
>
<Snippet language={language} />
<Snippet language={language} snippetInfo={supportedLanguages} />
</PivotItem>
));
}

function Snippet(props: ISnippetProps) {
let { language } = props;
const { sdkDownloadLink, sdkDocLink } = props.snippetInfo[language];

/**
* Converting language lowercase so that we won't have to call toLowerCase() in multiple places.
Expand Down Expand Up @@ -59,6 +70,42 @@ function Snippet(props: ISnippetProps) {
dispatch(getSnippet(language));
}, [sampleQuery.sampleUrl]);

const setCommentSymbol = (): string => {
return language.trim() === 'powershell' ? '#' : '//';
}

const trackLinkClickedEvent = (link: string, e:any) => {
const isDocumentationLink : boolean = link.includes('doc')
const componentName = isDocumentationLink ? componentNames.CODE_SNIPPET_DOCUMENTATION_LINK :
componentNames.CODE_SNIPPET_SDK_LIBRARY_LINK
telemetry.trackLinkClickEvent(e.currentTarget.href, componentName);
}

const extraSnippetInformation = () : JSX.Element => {
return (
<div style={{marginLeft: '28px', color: '#008000',
Onokaev marked this conversation as resolved.
Show resolved Hide resolved
fontFamily: 'Consolas, monospace', font: '11px', lineHeight: '1.5'}}>

{setCommentSymbol()} {translateMessage('Leverage libraries')} {language} {translateMessage('Client library')}

<a style={{color: '#008000'}} href={sdkDownloadLink}
onClick={(e) => trackLinkClickedEvent(sdkDownloadLink, e)} target={'_blank'}
rel='noreferrer noopener'>
{sdkDownloadLink}
</a>
<br />

{setCommentSymbol()} {translateMessage('SDKs documentation')}

<a style={{color: '#008000'}} href={sdkDocLink}
onClick={(e) => trackLinkClickedEvent(sdkDocLink, e)} target={'_blank'} rel='noreferrer noopener' >
{sdkDocLink}
</a>

</div>
)
}

return (
<div style={{ display: 'block' }} id={`${language}-tab`}>
{loadingState &&
Expand All @@ -74,6 +121,7 @@ function Snippet(props: ISnippetProps) {
language={language}
readOnly={true}
height={height}
extraInfoElement={extraSnippetInformation()}
/>
</>
}
Expand Down
5 changes: 4 additions & 1 deletion src/messages/GE.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,8 @@
"Invalid version in URL": "Invalid version in URL",
"More info": "More info",
"Could not connect to the sandbox": "Could not connect to the sandbox",
"Failed to get profile information": "Failed to get profile information"
"Failed to get profile information": "Failed to get profile information",
"Leverage libraries": "Leverage the power of our client libraries. Download the",
"Client library": "client library here ",
"SDKs documentation": "To read more about our SDKs, go to the documentation page at "
}
2 changes: 2 additions & 0 deletions src/telemetry/component-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const GRAPH_TOOLKIT_PLAYGROUND_LINK = 'Graph toolkit playground link';
export const MICROSOFT_APIS_TERMS_OF_USE_LINK = 'Microsoft APIs terms of use link';
export const MICROSOFT_PRIVACY_STATEMENT_LINK = 'Microsoft privacy statement link';
export const MICROSOFT_GRAPH_API_REFERENCE_DOCS_LINK = 'Microsoft graph API reference docs link';
export const CODE_SNIPPET_DOCUMENTATION_LINK = 'Code snippet documentation link';
export const CODE_SNIPPET_SDK_LIBRARY_LINK = 'Code snippet SDK library link';

// Actions
export const GET_SNIPPET_ACTION = 'Get snippet action';
Expand Down