Skip to content

Commit

Permalink
Add PowerShell snippets tab (#1273)
Browse files Browse the repository at this point in the history
* Add PowerShell code snippets tab

* Update API endpoint for fetching PowerShell snippets

* Enable PowerShell code snippets syntax highlighting
  • Loading branch information
millicentachieng authored Jan 13, 2022
1 parent ce3d100 commit 8489f75
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ module.exports = function (webpackEnv) {
maxChunks: 1
}),
new MonacoWebpackPlugin({
languages: ['json', 'javascript', 'java', 'objective-c', 'csharp', 'html']
languages: ['json', 'javascript', 'java', 'objective-c', 'csharp', 'html', 'powershell', 'go']
}),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin(
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions src/app/services/actions/snippet-action-creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ export function getSnippet(language: string): Function {
}
if (language !== 'csharp') {
snippetsUrl += `?lang=${language}`;
if (language === 'go') {
snippetsUrl += '&generation=openapi';
}
}
const openApiSnippets: string[] = ['go', 'powershell'];
if (openApiSnippets.includes(language)) {
snippetsUrl += '&generation=openapi';
}

dispatch(getSnippetPending());
Expand All @@ -52,12 +53,17 @@ export function getSnippet(language: string): Function {
const headers = {
'Content-Type': 'application/http'
};
// eslint-disable-next-line max-len

const requestBody =
sampleQuery.sampleBody &&
Object.keys(sampleQuery.sampleBody).length !== 0 && // check if empty object
sampleQuery.sampleBody.trim() !== ''
? JSON.stringify(sampleQuery.sampleBody)
: '';

const body = `${sampleQuery.selectedVerb} /${queryVersion}/${
requestUrl + search
} HTTP/1.1\r\nHost: graph.microsoft.com\r\nContent-Type: application/json\r\n\r\n${JSON.stringify(
sampleQuery.sampleBody
)}`;
} HTTP/1.1\r\nHost: graph.microsoft.com\r\nContent-Type: application/json\r\n\r\n${requestBody}`;
const options: IRequestOptions = { method, headers, body };
const obj: any = {};

Expand Down
3 changes: 2 additions & 1 deletion src/app/views/query-response/snippets/Snippets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function GetSnippets() {
'JavaScript',
'Java',
'Objective-C',
'Go'
'Go',
'PowerShell'
];

return <Pivot>{renderSnippets(supportedLanguages)}</Pivot>;
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"resolveJsonModule": true,
"noEmit": true,
"jsx": "react-jsx"

},
"include": [
"src",
Expand Down

0 comments on commit 8489f75

Please sign in to comment.