Skip to content

Commit e040c62

Browse files
Merge pull request SharePoint#4087 from andrewconnell/docfix-issue1916
Correct error in tutorial steps
2 parents ed2dfd3 + 4d75388 commit e040c62

File tree

1 file changed

+88
-100
lines changed

1 file changed

+88
-100
lines changed

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

Lines changed: 88 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,34 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
2020
## Create an extension project
2121

2222
1. Create a new project directory in your favorite location.
23-
24-
```
23+
24+
```shell
2525
md command-extension
2626
```
27-
28-
2. Go to the project directory.
29-
30-
```
27+
28+
1. Go to the project directory.
29+
30+
```shell
3131
cd command-extension
3232
```
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
3737
yo @microsoft/sharepoint
3838
```
39-
40-
4. When prompted:
39+
40+
1. When prompted:
4141

4242
* Accept the default value of **command-extension** as your solution name, and then select Enter.
4343
* Select **SharePoint Online only (latest)**, and select Enter.
4444
* Select **Use the current folder**, and select Enter.
4545
* Select **N** to allow solution to be deployed to all sites immediately.
4646
* 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.
4848
* Select **ListView Command Set** as the extension type to be created.
4949

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:
5151

5252
* Accept the default value of **HelloWorld** as your extension name, and then select Enter.
5353
* Accept the default value of **HelloWorld description** as your extension description, and select Enter.
@@ -62,9 +62,9 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
6262

6363
For information about troubleshooting any errors, see [Known issues](../../known-issues-and-common-questions.md).
6464

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.
6666

67-
```
67+
```shell
6868
code .
6969
```
7070

@@ -75,7 +75,7 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
7575

7676
![SharePoint Framework solution opened after initial scaffolding](../../../images/ext-com-vscode-solution-structure.png)
7777

78-
7. Open **HelloWorldCommandSet.manifest.json** in the **src\extensions\helloWorld** folder.
78+
1. Open **HelloWorldCommandSet.manifest.json** in the **src\extensions\helloWorld** folder.
7979

8080
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.
8181

@@ -85,7 +85,7 @@ You can follow these steps by watching the video on the SharePoint PnP YouTube C
8585

8686
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.
8787

88-
## Code your ListView Command Set
88+
## Code your ListView Command Set
8989

9090
Open the **HelloWorldCommandSet.ts** file in the **src\extensions\helloWorld** folder.
9191

@@ -123,30 +123,30 @@ When using the method `tryGetCommand`, you get a Command object, which is a repr
123123
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.
124124
125125
```typescript
126-
@override
127-
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');
137-
}
126+
@override
127+
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');
138137
}
138+
}
139139
```
140140
141141
## Debug your ListView Command Set
142142
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.
144144
145145
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.
146146
147147
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.
148148
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:
150150
151151
```json
152152
{
@@ -182,98 +182,91 @@ You cannot currently use the local Workbench to test SharePoint Framework Extens
182182
}
183183
```
184184
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:
186186
187-
```
187+
```shell
188188
gulp serve
189189
```
190190
191191
When the code compiles without errors, it serves the resulting manifest from https://localhost:4321.
192192
193193
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.
194194
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.
196+
197197
![Accept loading debugripts](../../../images/ext-com-accept-debug-scripts.png)
198-
199-
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.
200200
201201
![Command Two button visible in the document library toolbar](../../../images/ext-com-default-customizer-output.png)
202202
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.
204204
205205
![Selecting one document to get Command One button visible](../../../images/ext-com-default-customizer-doc-select.png)
206206
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.
208208
209209
![Selecting one document to get Command One button visible](../../../images/ext-com-default-customizer-btn-click.png)
210210
211-
212211
### More details about serve.config options
213212
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 command set 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.
221220
222221
<br/>
223222
224223
## Enhance the ListView Command Set rendering
225224
226225
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.
227226
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:
231230
232-
3. Open **HelloWorldCommandSet.ts** from the **src\extensions\helloWorld** folder.
233-
234-
4. Update the **onExecute** method as follows:
235-
236231
```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');
251245
}
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+
}
256247
```
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
257252
gulp serve
258253
```
259254
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.
261256
262257
![Accept loading debug scripts](../../../images/ext-com-accept-debug-scripts.png)
263258
264259
We still have the same buttons in the toolbar, but you'll notice they behave differently if you select them one-by-one. Now we are using the new Dialog API, which can be easily used with your solutions, even for complex scenarios.
265260
266261
![Accept loading debug scripts OK button](../../../images/ext-com-show-adv-dialog-input.png)
267262
268-
269263
## Add a ListView Command Set to a solution package for deployment
270264
271265
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.
272267
273-
2. Extend the **sharepoint** folder and **assets** sub folder in the root of the solution to see the existing **elements.xml** file.
274-
275268
![assets folder in solution structure](../../../images/ext-com-assets-folder.png)
276-
269+
277270
### Review the elements.xml file
278271
279272
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
294287
ClientSideComponentId="5fc73e12-8085-4a4b-8743-f6d02ffe1240"
295288
ClientSideComponentProperties="{&quot;sampleTextOne&quot;:&quot;One item is selected in the list.&quot;, &quot;sampleTextTwo&quot;:&quot;This command is always visible.&quot;}">
296289
</CustomAction>
297-
290+
298291
</Elements>
299292
```
300293
@@ -376,46 +369,41 @@ Now you are ready to deploy the solution to a SharePoint site and have the `Cust
376369
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.
377370
378371
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
381374
gulp bundle --ship
382375
```
383376
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:
385378
386-
```
379+
```shell
387380
gulp package-solution --ship
388381
```
389382
390383
The command creates the package in the **sharepoint/solution** folder:
391384
392-
```
385+
```shell
393386
command-extension.sppkg
394387
```
395388
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.
401392
402393
![Trust operation in app catalog upload](./../../../images/ext-com-sppkg-deploy-trust.png)
403394
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.
409398
410399
![installing the listview command set to a site](../../../images/ext-com-install-solution-to-site.png)
411400
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**.
415403
416404
![Creating a new list](../../../images/ext-com-create-new-list.png)
417405
418-
12. Provide the name as **Sample**, and then select **Create**.
406+
1. Provide the name as **Sample**, and then select **Create**.
419407
420408
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.
421409
@@ -426,5 +414,5 @@ Since solutions will by default use the **asset packaging** capability, your Jav
426414
427415
## See also
428416
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

Comments
 (0)