You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -20,34 +20,34 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
20
20
## Create an extension project
21
21
22
22
1. Create a new project directory in your favorite location.
23
-
24
-
```
23
+
24
+
```shell
25
25
md command-extension
26
26
```
27
-
28
-
2. Go to the project directory.
29
-
30
-
```
27
+
28
+
1. Go to the project directory.
29
+
30
+
```shell
31
31
cd command-extension
32
32
```
33
-
34
-
3. Create a new HelloWorld extension by running the Yeoman SharePoint Generator.
35
-
36
-
```
33
+
34
+
1. Create a new HelloWorld extension by running the Yeoman SharePoint Generator.
35
+
36
+
```shell
37
37
yo @microsoft/sharepoint
38
38
```
39
-
40
-
4. When prompted:
39
+
40
+
1. When prompted:
41
41
42
42
* Accept the default value of **command-extension** as your solution name, and thenselectEnter.
43
43
* Select **SharePoint Online only (latest)**, and selectEnter.
44
44
* Select **Use the current folder**, and selectEnter.
45
45
* Select **N** to allow solution to be deployed to all sites immediately.
46
46
* Select **N** on the question if solution contains unique permissions.
47
-
* Select **Extension** as the client-side component type to be created.
47
+
* Select **Extension** as the client-side component type to be created.
48
48
* Select **ListView Command Set** as the extension type to be created.
49
49
50
-
5. The next set of prompts ask for specific information about your extension:
50
+
1. The next set of prompts ask for specific information about your extension:
51
51
52
52
* Accept the default value of **HelloWorld** as your extension name, and thenselectEnter.
53
53
* Accept the default value of **HelloWorld description** as your extension description, and selectEnter.
@@ -62,9 +62,9 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
62
62
63
63
For information about troubleshooting any errors, see [Known issues](../../known-issues-and-common-questions.md).
64
64
65
-
6. Next, type the following into the console to start Visual Studio Code.
65
+
1. Next, type the following into the console to start Visual Studio Code.
66
66
67
-
```
67
+
```shell
68
68
code .
69
69
```
70
70
@@ -75,7 +75,7 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
75
75
76
76

77
77
78
-
7. Open **HelloWorldCommandSet.manifest.json** in the **src\extensions\helloWorld** folder.
78
+
1. Open **HelloWorldCommandSet.manifest.json**in the **src\extensions\helloWorld** folder.
79
79
80
80
This file defines your extension type and a unique identifier `id`for your extension. You need this unique identifier later when debugging and deploying your extension to SharePoint.
81
81
@@ -85,7 +85,7 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
85
85
86
86
Currently, images are not properly referenced unless you are referring to them from absolute locations in a CDN within your manifest. This will be improved in future releases.
87
87
88
-
## Code your ListView Command Set
88
+
## Code your ListView Command Set
89
89
90
90
Open the **HelloWorldCommandSet.ts** file in the **src\extensions\helloWorld** folder.
91
91
@@ -123,30 +123,30 @@ When using the method `tryGetCommand`, you get a Command object, which is a repr
123
123
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.
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
128
+
switch (event.itemId) {
129
+
case'COMMAND_1':
130
+
Dialog.alert(`${this.properties.sampleTextOne}`);
131
+
break;
132
+
case'COMMAND_2':
133
+
Dialog.alert(`${this.properties.sampleTextTwo}`);
134
+
break;
135
+
default:
136
+
throw new Error('Unknown command');
138
137
}
138
+
}
139
139
```
140
140
141
141
## Debug your ListView Command Set
142
142
143
-
You cannot currently use the local Workbench to test SharePoint Framework Extensions. You'll need to test and develop them directly against a live SharePoint Online site. You don't have to deploy your customization to the app catalog to do this, which makes the debugging experience simple and efficient.
143
+
You cannot currently use the local Workbench to test SharePoint Framework Extensions. You'll need to test and develop them directly against a live SharePoint Online site. You don't have to deploy your customization to the app catalog to do this, which makes the debugging experience simple and efficient.
144
144
145
145
1. Go to any SharePoint list in your SharePoint Online site by using the modern experience or create a new list. Copy the URL of the list to clipboard as we will be needing that in following step.
146
146
147
147
Because our ListView Command Set is hosted from localhost and is running, we can use specific debug query parameters to execute the code in the list view.
148
148
149
-
2. Open **serve.json** file from **config** folder. Update the **pageUrl** attributes to match a URL of the list where you want to test the solution. After edits your serve.json should look somewhat like:
149
+
1. Open **serve.json** file from **config** folder. Update the **pageUrl** attributes to match a URL of the list where you want to test the solution. After edits your serve.json should look somewhat like:
150
150
151
151
```json
152
152
{
@@ -182,98 +182,91 @@ You cannot currently use the local Workbench to test SharePoint Framework Extens
182
182
}
183
183
```
184
184
185
-
2. Compile your code and host the compiled files from the local machine by running this command:
185
+
1. Compile your code and host the compiled files from the local machine by running this command:
186
186
187
-
```
187
+
```shell
188
188
gulp serve
189
189
```
190
190
191
191
When the code compiles without errors, it serves the resulting manifest from https://localhost:4321.
192
192
193
193
This will also start your default browser within the URL defined in**serve.json** file. Notice that at least in Windows, you can control which browser window is used by activating the preferred one before executing this command.
194
194
195
-
4. Accept the loading of debug manifests by selecting **Load debug scripts** when prompted.
196
-
195
+
1. Accept the loading of debug manifests by selecting **Load debug scripts** when prompted.
5. Notice the new **Command Two** button available in the toolbar. Select that button to see the text provided as property for the `sampleTextTwo` property.
198
+
199
+
1. Notice the new **Command Two** button available in the toolbar. Select that button to see the text provided as property for the `sampleTextTwo` property.
200
200
201
201

202
202
203
-
6. The **Command One** button is not visible based on the code, until one row is selected in the document library. Upload or create a document to the library and confirm that the second button is visible.
203
+
1. The **Command One** button is not visible based on the code, until one row is selected in the document library. Upload or create a document to the library and confirm that the second button is visible.
204
204
205
205

206
206
207
-
7. Select **Command Two** to see how the dialog control works, which is used in the default output from the solution scaffolding when the ListView Command Set is selected as the extension type.
207
+
1. Select **Command Two** to see how the dialog control works, which is used in the default output from the solution scaffolding when the ListView Command Set is selected as the extension type.
208
208
209
209

210
210
211
-
212
211
### More details about serve.config options
213
212
214
-
- **customActions** simulates a custom action. You can set many properties on this `CustomAction` object that affect the look, feel, and location of your button; we’ll cover them all later.
215
-
- **GUID**: GUID of the extension.
216
-
- **Location**: Where the commands are displayed. The possible values are:
217
-
- **ClientSideExtension.ListViewCommandSet.ContextMenu**: The context menu of the item(s).
218
-
- **ClientSideExtension.ListViewCommandSet.CommandBar**: The top command set menu in a list or library.
219
-
- **ClientSideExtension.ListViewCommandSet**: Both the context menu and the command bar (corresponds to SPUserCustomAction.Location="CommandUI.Ribbon").
220
-
- **Properties**: An optional JSON object containing properties that are available via the `this.properties` member.
213
+
***customActions** simulates a custom action. You can set many properties on this `CustomAction` object that affect the look, feel, and location of your button; we’ll cover them all later.
214
+
***GUID**: GUID of the extension.
215
+
***Location**: Where the commands are displayed. The possible values are:
216
+
***ClientSideExtension.ListViewCommandSet.ContextMenu**: The context menu of the item(s).
217
+
***ClientSideExtension.ListViewCommandSet.CommandBar**: The top commandset menu in a list or library.
218
+
***ClientSideExtension.ListViewCommandSet**: Both the context menu and the command bar (corresponds to SPUserCustomAction.Location="CommandUI.Ribbon").
219
+
***Properties**: An optional JSON object containing properties that are available via the `this.properties` member.
221
220
222
221
<br/>
223
222
224
223
## Enhance the ListView Command Set rendering
225
224
226
225
The default solution takes advantage of a new Dialog API, which can be used to show modal dialogs easily from your code. In the following steps, we'll slightly modify the default experience to demonstrate Dialog API use cases.
227
226
228
-
1. Return to the console, and execute the following command to include the Dialog API in our solution.
229
-
230
-
2. Return to Visual Studio Code (or your preferred editor).
227
+
1. Return to Visual Studio Code (or your preferred editor).
228
+
1. Open **HelloWorldCommandSet.ts** from the **src\extensions\helloWorld** folder.
229
+
1. Update the **onExecute** method as follows:
231
230
232
-
3. Open **HelloWorldCommandSet.ts** from the **src\extensions\helloWorld** folder.
233
-
234
-
4. Update the **onExecute** method as follows:
235
-
236
231
```typescript
237
-
@override
238
-
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
239
-
switch (event.itemId) {
240
-
case 'COMMAND_1':
241
-
Dialog.alert(`Clicked ${strings.Command1}`);
242
-
break;
243
-
case 'COMMAND_2':
244
-
Dialog.prompt(`Clicked ${strings.Command2}. Enter something to alert:`).then((value: string) => {
245
-
Dialog.alert(value);
246
-
});
247
-
break;
248
-
default:
249
-
throw new Error('Unknown command');
250
-
}
232
+
@override
233
+
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
234
+
switch (event.itemId) {
235
+
case 'COMMAND_1':
236
+
Dialog.alert(`Clicked ${strings.Command1}`);
237
+
break;
238
+
case 'COMMAND_2':
239
+
Dialog.prompt(`Clicked ${strings.Command2}. Enter something to alert:`).then((value: string) => {
240
+
Dialog.alert(value);
241
+
});
242
+
break;
243
+
default:
244
+
throw new Error('Unknown command');
251
245
}
252
-
```
253
-
254
-
5. In your console window, ensure that you do not have any exceptions. If you do not already have the solution running in localhost, execute the following command:
255
-
246
+
}
256
247
```
248
+
249
+
1. In your console window, ensure that you do not have any exceptions. If you do not already have the solution running in localhost, execute the following command:
250
+
251
+
```shell
257
252
gulp serve
258
253
```
259
254
260
-
6. Accept the loading of debug manifests by selecting **Load debug scripts** when prompted.
255
+
1. Accept the loading of debug manifests by selecting **Load debug scripts** when prompted.
We still have the same buttons in the toolbar, but you'll notice they behave differently if you selectthem one-by-one. Now we are using the new Dialog API, which can be easily used with your solutions, even for complex scenarios.
265
260
266
261

267
262
268
-
269
263
## Add a ListView Command Set to a solution package for deployment
270
264
271
265
1. Return to your solution in Visual Studio Code (or to your preferred editor).
266
+
1. Extend the **sharepoint** folder and **assets** sub folder in the root of the solution to see the existing **elements.xml** file.
272
267
273
-
2. Extend the **sharepoint** folder and **assets** sub folder in the root of the solution to see the existing **elements.xml** file.
274
-
275
268

276
-
269
+
277
270
### Review the elements.xml file
278
271
279
272
Open the **elements.xml** file inside the **sharepoint\assets** folder.
@@ -294,7 +287,7 @@ Notice that we use a specific location value of `ClientSideExtension.ListViewCom
ClientSideComponentProperties="{"sampleTextOne":"One item is selected in the list.", "sampleTextTwo":"This command is always visible."}">
296
289
</CustomAction>
297
-
290
+
298
291
</Elements>
299
292
```
300
293
@@ -376,46 +369,41 @@ Now you are ready to deploy the solution to a SharePoint site and have the `Cust
376
369
Since solutions will by default use the **asset packaging** capability, your JavaScript files and other assets will be automatically packaged inside of the **sppkg** file and then hosted automatically from Office 365 CDN or from the app catalog site collection.
377
370
378
371
1. In the console window, enter the following command to package your client-side solution that contains the extension so that we get the basic structure ready for packaging:
379
-
380
-
```
372
+
373
+
```shell
381
374
gulp bundle --ship
382
375
```
383
376
384
-
2. Execute the following command so that the solution package is created:
377
+
1. Execute the following command so that the solution package is created:
385
378
386
-
```
379
+
```shell
387
380
gulp package-solution --ship
388
381
```
389
382
390
383
The command creates the package in the **sharepoint/solution** folder:
391
384
392
-
```
385
+
```shell
393
386
command-extension.sppkg
394
387
```
395
388
396
-
3. Deploy the package that was generated to the app catalog. To do this, go to your tenant's **app catalog** and open the **Apps for SharePoint** library.
397
-
398
-
4. Upload or drag-and-drop the `command-extension.sppkg` located in the **sharepoint/solution** folder to the app catalog. SharePoint displays a dialog and asks you to trust the client-side solution.
399
-
400
-
5. Select the **Deploy** button.
389
+
1. Deploy the package that was generated to the app catalog. To do this, go to your tenant's **app catalog** and open the **Apps for SharePoint** library.
390
+
1. Upload or drag-and-drop the `command-extension.sppkg` located in the **sharepoint/solution** folder to the app catalog. SharePoint displays a dialog and asks you to trust the client-side solution.
391
+
1. Select the **Deploy** button.
401
392
402
393

403
394
404
-
7. Go to the site where you want to test SharePoint asset provisioning. This could be any site collection in the tenant where you deployed this solution package.
405
-
406
-
8. Select the gears icon on the top navigation bar on the right, and then select **Add an app** to go to your Apps page.
407
-
408
-
9. In the **Search** box, enter **extension**, and then select Enter to filter your apps.
395
+
1. Go to the site where you want to test SharePoint asset provisioning. This could be any site collection in the tenant where you deployed this solution package.
396
+
1. Select the gears icon on the top navigation bar on the right, and then select **Add an app** to go to your Apps page.
397
+
1. In the **Search** box, enter **extension**, and then select Enter to filter your apps.
409
398
410
399

411
400
412
-
10. Select the **command-extension-client-side-solution** app to install the solution on the site. When the installation is complete, refresh the page by selecting F5.
413
-
414
-
11. When the application has been successfully installed, select **New** from the toolbar on the **Site Contents** page, and then select **List**.
401
+
1. Select the **command-extension-client-side-solution** app to install the solution on the site. When the installation is complete, refresh the page by selecting F5.
402
+
1. When the application has been successfully installed, select **New** from the toolbar on the **Site Contents** page, and then select **List**.
415
403
416
404

417
405
418
-
12. Provide the name as **Sample**, and then select **Create**.
406
+
1. Provide the name as **Sample**, and then select **Create**.
419
407
420
408
Notice how **Command One** and **Command Two** are rendering in the toolbar based on your ListView Command Set customizations. Notice that the extension is also rendered automatically for any existing lists, not only for new ones.
421
409
@@ -426,5 +414,5 @@ Since solutions will by default use the **asset packaging** capability, your Jav
426
414
427
415
## See also
428
416
429
-
- [Build your first Field Customizer extension](./building-simple-field-customizer.md)
430
-
- [Overview of SharePoint Framework Extensions](../overview-extensions.md)
417
+
* [Build your first Field Customizer extension](./building-simple-field-customizer.md)
418
+
* [Overview of SharePoint Framework Extensions](../overview-extensions.md)
0 commit comments