Skip to content

Commit 1ca88fa

Browse files
committed
App catalog related updates and streamlined initial tutorial for SPFx
1 parent 4b82ba9 commit 1ca88fa

10 files changed

+118
-154
lines changed
Loading
Loading
Loading

docs/images/sp-app-deploy-trust.png

29.4 KB
Loading
49.2 KB
Loading
11.6 KB
Loading

docs/spfx/set-up-your-developer-tenant.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,8 @@ You need an app catalog to upload and deploy web parts. If you've already set up
4141
4242
1. In the left sidebar, select **More features**
4343
1. Locate the section **Apps** and select **Open**.
44-
1. On the **Apps** page, select **App Catalog**.
45-
1. Select **OK** to create a new app catalog site.
46-
1. On the next page, enter the following details:
4744
48-
- **Title**: Enter **app catalog**.
49-
- **Web Site Address _suffix_**: Enter your preferred suffix for the app catalog; for example: **apps**.
50-
- **Administrator**: Enter your username, and then select the **resolve** button to resolve the username.
51-
52-
1. Select **OK** to create the app catalog site.
53-
54-
SharePoint creates the app catalog site, and you can see its progress in the SharePoint admin center.
45+
This is start the automatic creation of the SharePoint app catalog to the tenant if it does not exist. If the app catalog already exists, you will be redirect to it. SharePoint app catalog is used to manage and deploy SharePoint Framework solutions.
5546
5647
## Create a new site collection
5748
@@ -73,8 +64,8 @@ You also need a site collection and a site for your testing. You can create a ne
7364
7465
1. In the left sidebar, select **Sites > Active sites**.
7566
1. Select **Create** from the toolbar at the top of the page.
76-
1. On the **Create a site** page, select **Team site**.
77-
1. In the panel that appears, enter required details to create the site (*name, owner, and language*):
67+
1. On the **Create a site** panel, select **Team site**.
68+
1. In the new view that appears, enter required details to create the site (*Site name, Group owner, and language*):
7869
1. Select **Next** to create the site collection.
7970
8071
After SharePoint creates the site, you can browse to your site collection by selecting **Finish** & entering the URL of the new site.

docs/spfx/web-parts/get-started/connect-to-sharepoint.md

Lines changed: 25 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,19 @@ this.context.pageContext
4848

4949
```tsx
5050
this.domElement.innerHTML = `
51-
<div class="${ styles.helloWorld }">
52-
<div class="${ styles.container }">
53-
<div class="${ styles.row }">
54-
<div class="${ styles.column }">
55-
<span class="${ styles.title }">Welcome to SharePoint!</span>
56-
<p class="${ styles.subTitle }">Customize SharePoint experiences using web parts.</p>
57-
<p class="${ styles.description }">${escape(this.properties.description)}</p>
58-
<p class="${ styles.description }">${escape(this.properties.test)}</p>
59-
<p class="${ styles.description }">Loading from ${escape(this.context.pageContext.web.title)}</p>
60-
<a href="https://aka.ms/spfx" class="${ styles.button }">
61-
<span class="${ styles.label }">Learn more</span>
62-
</a>
63-
</div>
64-
</div>
65-
</div>
66-
</div>`;
51+
<section class="${styles.helloWorld} ${!!this.context.sdks.microsoftTeams ? styles.teams : ''}">
52+
<div class="${styles.welcome}">
53+
<img alt="" src="${this._isDarkTheme ? require('./assets/welcome-dark.png') : require('./assets/welcome-light.png')}" class="${styles.welcomeImage}" />
54+
<h2>Well done, ${escape(this.context.pageContext.user.displayName)}!</h2>
55+
<div>${this._environmentMessage}</div>
56+
</div>
57+
<div>
58+
<h3>Welcome to SharePoint Framework!</h3>
59+
<div>Web part description: <strong>${escape(this.properties.description)}</strong></div>
60+
<div>Web part test: <strong>${escape(this.properties.test)}</strong></div>
61+
<div>Loading from: <strong>${escape(this.context.pageContext.web.title)}</strong></div>
62+
</div>
63+
</section>`;
6764
```
6865

6966
1. Notice how `${ }` is used to output the variable's value in the HTML block. An extra HTML `div` is used to display `this.context.pageContext.web.title`.
@@ -100,63 +97,6 @@ You need a list model to start working with SharePoint list data. To retrieve th
10097

10198
The **ISPList** interface holds the SharePoint list information that we're connecting to.
10299

103-
## Retrieve lists from mock store
104-
105-
To test your mocked data, you'll need a mock store that returns mock data.
106-
107-
### To create a mock store
108-
109-
1. Create a new file **MockHttpClient.ts** in the **src\webparts\helloWorld** folder.
110-
1. Copy the following code into **MockHttpClient.ts**:
111-
112-
```typescript
113-
import { ISPList } from './HelloWorldWebPart';
114-
115-
export default class MockHttpClient {
116-
117-
private static _items: ISPList[] = [{ Title: 'Mock List', Id: '1' },
118-
{ Title: 'Mock List 2', Id: '2' },
119-
{ Title: 'Mock List 3', Id: '3' }];
120-
121-
public static get(): Promise<ISPList[]> {
122-
return new Promise<ISPList[]>((resolve) => {
123-
resolve(MockHttpClient._items);
124-
});
125-
}
126-
}
127-
```
128-
129-
Things to note about the code:
130-
131-
- It exports the `MockHttpClient` class as a default module so that it can be imported in other files.
132-
- It builds the initial `ISPList` mock array and returns an array of items.
133-
134-
1. Save the file.
135-
136-
You can now use the `MockHttpClient` class in the `HelloWorldWebPart` class. You first need to import the `MockHttpClient` module.
137-
138-
### Import the MockHttpClient class
139-
140-
1. Locate and open the **HelloWorldWebPart.ts** file.
141-
1. Locate the line `import * as strings from 'HelloWorldWebPartStrings';` and add the following code immediately after it:
142-
143-
```typescript
144-
import MockHttpClient from './MockHttpClient';
145-
```
146-
147-
1. Add the following method that mocks the list retrieval inside the `HelloWorldWebPart` class.
148-
149-
```typescript
150-
private _getMockListData(): Promise<ISPLists> {
151-
return MockHttpClient.get()
152-
.then((data: ISPList[]) => {
153-
var listData: ISPLists = { value: data };
154-
return listData;
155-
}) as Promise<ISPLists>;
156-
}
157-
```
158-
159-
1. Save the file.
160100

161101
## Retrieve lists from SharePoint site
162102

@@ -167,7 +107,7 @@ SharePoint Framework includes a helper class `spHttpClient` to execute REST API
167107
### To use this helper class, import them from the @microsoft/sp-http module
168108

169109
1. Scroll to the top of the **HelloWorldWebPart.ts** file.
170-
1. Locate the line `import MockHttpClient from './MockHttpClient';` and add the following code immediately after it:
110+
1. Locate the line `import * as strings from 'HelloWorldWebPartStrings';` and add the following code immediately after it:
171111

172112
```typescript
173113
import {
@@ -202,7 +142,7 @@ The SharePoint Framework uses [Sass](http://sass-lang.com/) as the CSS pre-proce
202142

203143
By default, the styles are scoped to your web part. You can see that as the styles are defined under `.helloWorld`.
204144

205-
1. Add the following styles after the `.button` style, but still inside the main `.helloWorld` style section:
145+
2. Add the following styles after the `.links` style:
206146

207147
```css
208148
.list {
@@ -234,7 +174,7 @@ The SharePoint Framework uses [Sass](http://sass-lang.com/) as the CSS pre-proce
234174
}
235175
```
236176
237-
1. Save the file.
177+
3. Save the file.
238178
239179
Gulp rebuilds the code in the console as soon as you save the file. This generates the corresponding typings in the **HelloWorldWebPart.module.scss.ts** file. After compiled to TypeScript, you can then import and reference these styles in your web part code.
240180
@@ -251,18 +191,8 @@ The SharePoint Framework uses [Sass](http://sass-lang.com/) as the CSS pre-proce
251191

252192
Open the `HelloWorldWebPart` class.
253193

254-
SharePoint workbench gives you the flexibility to test web parts in your local environment and from a SharePoint site. SharePoint Framework aids this capability by helping you understand which environment your web part is running from by using the `isServedFromLocalhost` property.
255-
256-
### Use the `isServedFromLocalhost` property
257-
258-
1. Import the `Environment` and the `EnvironmentType` modules from the **\@microsoft/sp-core-library** bundle. Add it to the `import` section at the top as shown in the following code:
259-
260-
```typescript
261-
import {
262-
Environment,
263-
EnvironmentType
264-
} from '@microsoft/sp-core-library';
265-
```
194+
> [!NOTE]
195+
> SharePoint Framework provides you options to detect environment details and host ___location using the `isServedFromLocalhost` property or with EnvironmentType details. In this case we'll focus on connecting to the data in the site which is hosting the online workbench.
266196

267197
1. Add the following private method inside the `HelloWorldWebPart` class:
268198

@@ -285,38 +215,20 @@ SharePoint workbench gives you the flexibility to test web parts in your local e
285215

286216
This method references the new CSS styles added earlier by using the `styles` variable and is used to render list information that will be received from REST API.
287217

288-
1. Save the file.
289-
1. Add the following private method inside the `HelloWorldWebPart` class to call the respective methods to retrieve list data:
218+
2. Save the file.
219+
3. Add the following private method inside the `HelloWorldWebPart` class to call the method to retrieve list data:
290220

291221
```typescript
292222
private _renderListAsync(): void {
293-
// Local environment
294-
if (this.context.isServedFromLocalhost) {
295-
this._getMockListData().then((response) => {
223+
this._getListData()
224+
.then((response) => {
296225
this._renderList(response.value);
297226
});
298-
}
299-
else if (Environment.type == EnvironmentType.SharePoint ||
300-
Environment.type == EnvironmentType.ClassicSharePoint) {
301-
this._getListData()
302-
.then((response) => {
303-
this._renderList(response.value);
304-
});
305-
}
306227
}
307228
```
308229

309-
Things to note about `EnvironmentType` in the `_renderListAsync()` method:
310-
311-
- The `Environment.type` property helps you check if you are in a local or SharePoint environment.
312-
- The correct method is called depending on where your workbench is hosted.
313-
314-
1. Save the file.
230+
4. Save the file.
315231

316-
> [!IMPORTANT]
317-
> The above code is intended to work only when you're working with the SharePoint Framework v1.14 or later.
318-
>
319-
> This is because the `isServedFromLocalhost` property was introduced in SPFx v1.14.
320232

321233
## Retrieve list data
322234

@@ -348,9 +260,9 @@ SharePoint workbench gives you the flexibility to test web parts in your local e
348260

349261
1. If you're using the SharePoint Framework v1.12.1 or earlier, for instance if you're on SharePoint Server on-premises, switch to your local workbench and add the HelloWorld web part.
350262

351-
You should see the mock data returned.
263+
You should see the list data returned.
352264

353-
![Render lists data from localhost](../../../images/sp-lists-render-localhost.png)
265+
![Render lists data from localhost](../../../images/sp-lists-render-online-workbench.png)
354266

355267
1. Now you can stop the server from running. Switch to the console and stop **gulp serve**. Select <kbd>CTRL</kbd>+<kbd>C</kbd> to stop the gulp task.
356268

docs/spfx/web-parts/get-started/hosting-webpart-from-office-365-cdn.md

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,47 @@ For information on enabling and configuring the Microsoft 365 CDN in your ShareP
5050
The **package-solution.json** file defines the package metadata as shown in the following code:
5151

5252
```json
53-
{
54-
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
55-
"solution": {
56-
"name": "helloword-webpart-client-side-solution",
57-
"id": "3c1af394-bbf0-473c-bb7d-0798f0587cb7",
58-
"version": "1.0.0.0",
59-
"includeClientSideAssets": true,
60-
"isDomainIsolated": false
61-
},
62-
"paths": {
63-
"zippedPackage": "solution/helloword-webpart.sppkg"
64-
}
53+
{
54+
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
55+
"solution": {
56+
"name": "mysolution-client-side-solution",
57+
"id": "ee1a495d-c7bb-499b-bd71-728aaeb79cd2",
58+
"version": "1.0.0.0",
59+
"includeClientSideAssets": true,
60+
"skipFeatureDeployment": true,
61+
"isDomainIsolated": false,
62+
"developer": {
63+
"name": "",
64+
"websiteUrl": "",
65+
"privacyUrl": "",
66+
"termsOfUseUrl": "",
67+
"mpnId": "Undefined-1.14.0"
68+
},
69+
"metadata": {
70+
"shortDescription": {
71+
"default": "mysolution description"
72+
},
73+
"longDescription": {
74+
"default": "mysolution description"
75+
},
76+
"screenshotPaths": [],
77+
"videoUrl": "",
78+
"categories": []
79+
},
80+
"features": [
81+
{
82+
"title": "mysolution Feature",
83+
"description": "The feature that activates elements of the mysolution solution.",
84+
"id": "d72e47b2-d5a2-479f-9f9a-85e1e7472dee",
85+
"version": "1.0.0.0"
86+
}
87+
]
88+
},
89+
"paths": {
90+
"zippedPackage": "solution/mysolution.sppkg"
91+
}
6592
}
93+
6694
```
6795

6896
The default value for the `includeClientSideAssets` is `true`, which means that static assets are packaged automatically in the **\*.sppkg** files, and you don't need to separately host your assets from an external system.
@@ -89,15 +117,15 @@ If Microsoft 365 CDN *is enabled*, it's used automatically with default settings
89117
> If you're interested in what actually got packaged inside of the **\*.sppkg** file, you can look in the content of the **sharepoint/solution/debug** folder.
90118

91119
1. Upload or drag and drop the newly created client-side solution package to the app catalog in your tenant.
92-
1. Because you already deployed the package, you're prompted as to whether to replace the existing package. Select **Replace It**.
120+
1. Because you already deployed the package, you're prompted as to whether to replace the existing package. Select **Replace**.
93121

94122
![Override existing solution](../../../images/cdn-override-helloworld-webpart-package.png)
95123

96-
1. Notice how the **___domain** list in the prompt says *SharePoint Online*. This is because the content is either served from the Microsoft 365 CDN or from the app catalog, depending on the tenant settings. Select **Deploy**.
124+
1. Notice how the **___domain** list in the prompt says *SharePoint Online*. This is because the content is either served from the Microsoft 365 CDN or from the app catalog, depending on the tenant settings. Select **Enable app**.
97125

98126
![Installation popup from app catalog for the SPFx solution](../../../images/cnd-trust-helloworld-webpart-solution.png)
99127

100-
1. Open the site where you previously installed the **helloworld-webpart-client-side-solution** or installed the solution to a new site.
128+
1. Open the site where you previously installed the **helloworld-webpart-client-side-solution** or install the solution to a new site.
101129
1. After the solution has been installed, select **Add a page** from the *gear* menu, and select **HelloWorld** from the modern page web part picker to add your custom web part to page.
102130

103131
![HelloWorld web part visible in web part picker for modern page](../../../images/cdn-web-part-picker.png)

0 commit comments

Comments
 (0)