Skip to content

Commit db0572e

Browse files
Linda-EditorVesaJuvonen
authored andcommitted
SPFx edit pass complete (SharePoint#1312)
* Edits in progress * Edit in progress * Edit in progress * Edits in progress * Edits in progress * Edits in progress * Fixed broken links * Fixed broken links * Fixed broken links * Final edit * Edit in progress * Final edit * Fixed errors * Edit in progress * Final edit * Changed ```ts to ```typescript * Changed ```ts to ```typescript
1 parent 53fa577 commit db0572e

File tree

40 files changed

+1890
-1623
lines changed

40 files changed

+1890
-1623
lines changed

docs/spfx/call-microsoft-graph-using-graphhttpclient.md

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
---
2+
title: Tutorial - Use GraphHttpClient to call Microsoft Graph
3+
description: Use the GraphHttpClient class to make calls to the Microsoft Graph REST API by using the get(), post(), and fetch() methods.
4+
ms.date: 02/02/2018
5+
ms.prod: sharepoint
6+
---
7+
18
# Use GraphHttpClient to call Microsoft Graph
9+
210
> [!IMPORTANT]
3-
>The **GraphHttpClient** is currently in preview and is subject to change. It is not currently supported for use in production environments.
11+
> The **GraphHttpClient** is currently in preview and is subject to change. It is not currently supported for use in production environments.
412
5-
Use the **GraphHttpClient** class to make calls to the Microsoft Graph REST API. You can make GET, POST, and PATCH requests using the **get()**, **post()**, and **fetch()** methods. This article shows how to build a web part that uses **GraphHttpClient**, but you can use **GraphHttpClient** in any SharePoint Framework client code.
13+
Use the **GraphHttpClient** class to make calls to the Microsoft Graph REST API. You can make GET, POST, and PATCH requests by using the **get()**, **post()**, and **fetch()** methods. This article shows how to build a web part that uses **GraphHttpClient**, but you can use **GraphHttpClient** in any SharePoint Framework client code.
614

715
## Retrieve Office 365 groups using a GET call
816

@@ -36,11 +44,11 @@ You can use the **get()** method to make a REST call to Microsoft Graph. This ex
3644
* Select **Web Part** as the type of client-side component to create.
3745
* Enter **HelloGraph** as your web part name.
3846
* Enter **Calls the Microsoft Graph Groups API** as the web part description.
39-
* Accept the default **No javascript web framework** as the framework, and choose Enter.
47+
* Accept the default **No javascript web framework** as the framework, and select Enter.
4048

4149
![GraphHttpClient values to enter at command line](../images/graphhttpclient-web-part-create.jpg)
4250

43-
5. The Yeoman generator will build the web part. When the scaffolding is finished, open your project folder in your code editor. This article uses Visual Studio Code in the steps and screenshots, but you can use any editor that you prefer.
51+
5. The Yeoman generator builds the web part. When the scaffolding is finished, open your project folder in your code editor. This article uses Visual Studio Code in the steps and screenshots, but you can use any editor that you prefer.
4452

4553
6. Run the gulp serve command and confirm that it runs in the local workbench correctly.
4654

@@ -49,13 +57,14 @@ You can use the **get()** method to make a REST call to Microsoft Graph. This ex
4957
```
5058

5159
### Add a button and placeholder for results
60+
5261
Next, you'll modify the HTML to provide a button to retrieve Office 365 groups. The HTML also needs a placeholder to display the groups.
5362

5463
1. In your code editor, open the **/src/webparts/helloGraph/HelloGraphWebPart.ts** file.
5564

56-
2. Modify the **render()** method so that it contains a button and a **div** where the code will list the Office 365 groups after they are retrieved.
65+
2. Modify the **render()** method so that it contains a button and a **div** where the code lists the Office 365 groups after they are retrieved.
5766

58-
Your code should look like the following TypeScript.
67+
Your code should look like the following TypeScript:
5968

6069
```typescript
6170
public render(): void {
@@ -96,6 +105,7 @@ Next, you'll modify the HTML to provide a button to retrieve Office 365 groups.
96105
```
97106

98107
### Use the GraphHttpClient.get method to retrieve Office 365 groups
108+
99109
Next, you'll call the **GraphHttpClient.get()** method to make a REST call to Microsoft Graph to retrieve a list of Office 365 groups.
100110

101111
1. Import the **GraphHttpClient** class and related types by adding the following import statement near the top of the **HelloGraphWebPart.ts** file.
@@ -122,13 +132,13 @@ Next, you'll call the **GraphHttpClient.get()** method to make a REST call to Mi
122132
}
123133
```
124134

125-
In the previous code, the context property has the GraphHttpClient instance. When you call the **get()** method, a REST call is made to Microsoft Graph that passes the specified URL. In this case, the URL is **v1.0/groups?orderby=displayName**. This issues a GET request and Microsoft Graph will return all Office 365 groups in the tenant in order by display name.
135+
In the previous code, the context property has the GraphHttpClient instance. When you call the **get()** method, a REST call is made to Microsoft Graph that passes the specified URL. In this case, the URL is **v1.0/groups?orderby=displayName**. This issues a GET request, and Microsoft Graph returns all Office 365 groups in the tenant in order by display name.
126136

127-
You can issue any GET request by using this technique and entering the correct URL values. To find the URL values, see the [Microsoft Graph documentation](https://developer.microsoft.com/en-us/graph/docs/concepts/overview). For example, you can use URL specified in the [Groups GET request](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/group_get) topic to get groups.
137+
You can issue any GET request by using this technique and entering the correct URL values. To find the URL values, see the [Microsoft Graph documentation](https://developer.microsoft.com/en-us/graph/docs/concepts/overview). For example, you can use the URL specified in the [Groups GET request](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/group_get) topic to get groups.
128138

129-
The **get()** method returns an **HttpClientResponse**, which you can use to determine whether the call was successful. The returned JSON is in the **result.value**. Because you expect multiple groups to be returned, you will pass the value to a **_renderTable()** method, which will build a table of rows for each group.
139+
The **get()** method returns an **HttpClientResponse**, which you can use to determine whether the call was successful. The returned JSON is in the **result.value**. Because you expect multiple groups to be returned, you pass the value to a **_renderTable()** method, which builds a table of rows for each group.
130140

131-
3. Create a **_renderTable()** method to render the returned groups in a table where each row represent a group. Add the following method to the **HelloGraphWebPart** class.
141+
3. Create a **_renderTable()** method to render the returned groups in a table where each row represents a group. Add the following method to the **HelloGraphWebPart** class.
132142

133143
```typescript
134144
protected _renderTable(items: IOffice365Group[]): void {
@@ -159,6 +169,7 @@ Next, you'll call the **GraphHttpClient.get()** method to make a REST call to Mi
159169
```
160170

161171
### Run the web part to call Microsoft Graph
172+
162173
The code needs to call the **GraphHttpClient** application that runs on SharePoint, so you can't run it on the local workbench. You have to package and deploy it to SharePoint.
163174

164175
1. Use gulp to package your solution.
@@ -170,34 +181,36 @@ The code needs to call the **GraphHttpClient** application that runs on SharePoi
170181
2. Deploy the solution to your SharePoint tenant:
171182
* Go to your site's App Catalog.
172183
* Upload or drag and drop the **hellograph-webpart.sppkg** to the App Catalog.
173-
* When prompted, if you trust the **hellograph-webpart-client-side-solution**, select **Make this solution available to all sites in the organization**, and choose **Deploy**.
184+
* When prompted, if you trust the **hellograph-webpart-client-side-solution**, select **Make this solution available to all sites in the organization**, and select **Deploy**.
174185

175186
3. Use gulp serve to host the web part.
176187

177188
```
178189
gulp serve --nobrowser
179190
```
180191

181-
4. Add the web part to a web page, or use the SharePoint workbench.
192+
4. Add the web part to a web page, or use the SharePoint Workbench.
182193

183194
You should see the following on your page.
195+
184196
![GraphHttpClient web part showing read groups button and one group listed in a table](../images/graphhttpclient-read-groups-display.jpg)
185197

186-
When you choose **Read Groups**, you will see a list of all the Office 365 groups on your tenant. If no groups are listed, you'll just see a message that indicates that there were no groups. You will create a new group next.
198+
When you select **Read Groups**, you see a list of all the Office 365 groups on your tenant. If no groups are listed, you'll just see a message that indicates that there were no groups. You will create a new group next.
187199

188200
## Create a new Office 365 group using a POST call
189201

190202
You can issue POST calls to the Microsoft Graph API by using the **GraphHttpClient.post()** method. You'll use the **post()** method to create a new Office 365 group.
191203

192204

193205
### Add a button and placeholder for results
194-
Again, you need to modify the HTML to add a button that will create a new group.
206+
207+
Again, you need to modify the HTML to add a button that creates a new group.
195208

196209
1. In your code editor, open the **/src/webparts/helloGraph/HelloGraphWebPart.ts** file.
197210

198-
2. Modify the **render()** method so that it contains a button and a **div** that will indicate whether the creation was successful.
211+
2. Modify the **render()** method so that it contains a button and a **div** that indicates whether the creation was successful.
199212

200-
Your code should look like the following TypeScript.
213+
Your code should look like the following TypeScript:
201214

202215
```typescript
203216
public render(): void {
@@ -254,7 +267,7 @@ Again, you need to modify the HTML to add a button that will create a new group.
254267
}
255268
```
256269

257-
The previous code creates a simple group using the code example from the Microsoft Graph [Create group](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/group_post_groups) article.
270+
The previous code creates a simple group by using the code example from the Microsoft Graph [Create group](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/group_post_groups) article.
258271

259272
The **post()** issues a POST REST API call to the **v1.0/groups** URL. The third parameter is an **IGraphHttpClientOptions** value in which the JSON body is specified to describe the new group. The **HttpClientResponse** is used to determine whether the call was successful, and to display an appropriate result.
260273

@@ -271,24 +284,25 @@ Again, you need to modify the HTML to add a button that will create a new group.
271284
2. Deploy the solution to your SharePoint tenant:
272285
* Go to your site's App Catalog.
273286
* Upload or drag and drop the **hellograph-webpart.sppkg** to the App Catalog.
274-
* Because your solution is already registered, you'll be prompted as to whether you want to replace it. Choose **Replace it**.
275-
* When prompted as to whether you trust the solution, choose **Deploy**.
287+
* Because your solution is already registered, you are prompted as to whether you want to replace it. Select **Replace it**.
288+
* When prompted as to whether you trust the solution, select **Deploy**.
276289

277290
3. Use gulp serve to host the web part.
278291

279292
```
280293
gulp serve --nobrowser
281294
```
282295

283-
4. Add the web part to a web page, or use the SharePoint workbench.
296+
4. Add the web part to a web page, or use the SharePoint Workbench.
284297

285298
You should see the following on your page.
299+
286300
![GraphHttpClient web part with create group button indicating group was created successfully](../images/graphhttpclient-group-created.jpg)
287301

288-
5. When you choose **Create New Group**, the code will create a new Office 365 group.
302+
5. When you select **Create New Group**, the code creates a new Office 365 group.
289303

290304
> [!NOTE]
291-
>If you try to create the same group again, the code will return an error because the group already exists. The error is logged to the console, which you can view in the browser's developer mode.
305+
> If you try to create the same group again, the code returns an error because the group already exists. The error is logged to the console, which you can view in the browser's developer mode.
292306
293307
## Update a group using a PATCH call
294308

@@ -316,3 +330,7 @@ The following code shows how to call the **fetch()** method to update an existin
316330
```
317331

318332
The ID of the group is specified in the URL. Get the ID by using a GET call first. The **method** parameter is set to **PATCH**. The body specifies which group properties to modify.
333+
334+
## See also
335+
336+
- [Overview of the GraphHttpClient class](overview-graphhttpclient.md)

docs/spfx/css-recommendations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To avoid issues, you should always assume that there are multiple instances of y
4646

4747
#### Bad practice
4848

49-
```ts
49+
```typescript
5050
// ...
5151

5252
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
@@ -66,7 +66,7 @@ export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorld
6666

6767
#### Good practice
6868

69-
```ts
69+
```typescript
7070
// ...
7171

7272
export default class HelloWorldWebPart extends BaseClientSideWebPart<IHelloWorldWebPartProps> {
@@ -175,7 +175,7 @@ exports.default = styles;
175175

176176
To use the generated class names in your code, you first import the styles of your component, and then use the property pointing to the particular class:
177177

178-
```ts
178+
```typescript
179179
import styles from './todoList.module.scss';
180180
// ...
181181

docs/spfx/extensions/get-started/building-simple-cmdset-with-dialog-api.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Open the **HelloWorldCommandSet.ts** file in the **src\extensions\helloWorld** f
9494
9595
Notice that the base class for the ListView Command Set is imported from the **sp-listview-extensibility** package, which contains SharePoint Framework code required by the ListView Command Set.
9696
97-
```ts
97+
```typescript
9898
import { override } from '@microsoft/decorators';
9999
import { Log } from '@microsoft/sp-core-library';
100100
import {
@@ -112,7 +112,7 @@ The **onListViewUpdated()** event occurs separately for each command (for exampl
112112

113113
When using the method `tryGetCommand`, you get a Command object, which is a representation of the command that shows in the UI. You can modify its values, such as `title`, or `visible`, to modify the UI element. SPFx uses this information when re-rendering the commands. These objects keep the state from the last render, so if a command is set to `visible = false`, it remains invisible until it is set back to `visible = true`.
114114

115-
```ts
115+
```typescript
116116
@override
117117
public onListViewUpdated(event: IListViewCommandSetListViewUpdatedParameters): void {
118118
const compareOneCommand: Command = this.tryGetCommand('COMMAND_1');
@@ -126,7 +126,7 @@ When using the method `tryGetCommand`, you get a Command object, which is a repr
126126
The **OnExecute()** method defines what happens when a command is executed (for example, the menu item is selected). In the default implementation, different messages are shown based on which button was selected.
127127

128128

129-
```ts
129+
```typescript
130130
@override
131131
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
132132
switch (event.itemId) {
@@ -218,7 +218,7 @@ The default solution takes advantage of a new Dialog API, which can be used to s
218218
219219
5. Update the **onExecute** method as follows:
220220
221-
```ts
221+
```typescript
222222
@override
223223
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
224224
switch (event.commandId) {

docs/spfx/extensions/get-started/building-simple-field-customizer.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Open the **HelloWorldFieldCustomizer.ts** file in the **src\extensions\helloWorl
9393
9494
Notice that the base class for the Field Customizer is imported from the **sp-listview-extensibility** package, which contains SharePoint Framework code required by the Field Customizer.
9595
96-
```ts
96+
```typescript
9797
import { Log } from '@microsoft/sp-core-library';
9898
import { override } from '@microsoft/decorators';
9999
import {
@@ -110,7 +110,7 @@ The logic for your Field Customizer is contained in the **OnInit()**, **onRender
110110

111111
The following are the contents of **onRenderCell()** and **onDisposeCell()** in the default solution:
112112

113-
```ts
113+
```typescript
114114
@override
115115
public onRenderCell(event: IFieldCustomizerCellEventParameters): void {
116116
// Use this method to perform your custom cell rendering.
@@ -227,7 +227,7 @@ Now that we have successfully tested the out-of-the-box starting point of the Fi
227227
228228
2. Open the **HelloWorldFieldCustomizer.ts** file in the **src\extensions\helloWorld** folder, and update the **onRednerCell** method as follows.
229229
230-
```ts
230+
```typescript
231231
@override
232232
public onRenderCell(event: IFieldCustomizerCellEventParameters): void {
233233

docs/spfx/extensions/get-started/using-page-placeholder-with-extensions.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can also follow these steps by watching the video on the [SharePoint PnP You
2323

2424
Application Customizer extensions are supported with `Site`, `Web`, and `List` scopes. You can control the scope by deciding where or how the Application Customizer is registered in your SharePoint tenant. When the Application Customizer exists in the scope and is being rendered, you can use the following method to get access to the placeholder.
2525

26-
```ts
26+
```typescript
2727
// Handling the Bottom placeholder
2828
if (!this._bottomPlaceholder) {
2929
this._bottomPlaceholder =
@@ -44,7 +44,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
4444

4545
2. Add the `PlaceholderContent` and `PlaceholderName` to the import from `@microsoft/sp-application-base` by updating the import statement as follows:
4646

47-
```ts
47+
```typescript
4848
import {
4949
BaseApplicationCustomizer,
5050
PlaceholderContent,
@@ -54,7 +54,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
5454

5555
Also add the following import statements after the `strings` import at the top of the file:
5656

57-
```ts
57+
```typescript
5858
import styles from './AppCustomizer.module.scss';
5959
import { escape } from '@microsoft/sp-lodash-subset';
6060
```
@@ -97,7 +97,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
9797
> [!NOTE]
9898
> If your Command Set uses the ClientSideComponentProperties JSON input, it is deserialized into the `BaseExtension.properties` object. You can define an interface to describe it.
9999

100-
```ts
100+
```typescript
101101
export interface IHelloWorldApplicationCustomizerProperties {
102102
Top: string;
103103
Bottom: string;
@@ -106,7 +106,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
106106

107107
6. Add the following private variables inside the **HelloWorldApplicationCustomizer** class. In this scenario, these can just be local variables in an `onRender` method, but if you want to share them with other objects, define them as private variables.
108108

109-
```ts
109+
```typescript
110110
export default class HelloWorldApplicationCustomizer
111111
extends BaseApplicationCustomizer<IHelloWorldApplicationCustomizerProperties> {
112112

@@ -118,7 +118,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
118118
119119
7. Update the `onInit` method code as follows:
120120
121-
```ts
121+
```typescript
122122
@override
123123
public onInit(): Promise<void> {
124124
Log.info(LOG_SOURCE, `Initialized ${strings.Title}`);
@@ -134,7 +134,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
134134
135135
8. Create a new `_renderPlaceHolders` private method with the following code:
136136
137-
```ts
137+
```typescript
138138
private _renderPlaceHolders(): void {
139139
140140
console.log('HelloWorldApplicationCustomizer._renderPlaceHolders()');
@@ -213,7 +213,7 @@ Notice that you're requesting a well-known placeholder by using the correspondin
213213
214214
9. Add the following method after the `_renderPlaceHolders` method. In this case, you simply output a console message when the extension is removed from the page.
215215
216-
```ts
216+
```typescript
217217
private _onDispose(): void {
218218
console.log('[HelloWorldApplicationCustomizer._onDispose] Disposed custom top and bottom placeholders.');
219219
}

0 commit comments

Comments
 (0)