Skip to content

Commit 2b95956

Browse files
waldekmastykarzVesaJuvonen
authored andcommitted
Updated guidance (SharePoint#839)
* Updated tutorial on sharing data between web parts * Updated guidance on sharing data between web parts * Updated guidance on migrating jQuery DataTables solutions * Updated guidance on migrating jQuery FullCalendar solutions
1 parent 110a75c commit 2b95956

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

docs/spfx/web-parts/guidance/migrate-jquery-datatables-script-to-spfx.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export default class ItRequestsWebPart extends BaseClientSideWebPart<IItRequests
189189
public render(): void {
190190
this.domElement.innerHTML = `
191191
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" />
192-
<table id="requests" class="display ${styles.helloWorld}" cellspacing="0" width="100%">
192+
<table id="requests" class="display ${styles.itRequests}" cellspacing="0" width="100%">
193193
<thead>
194194
<tr>
195195
<th>ID</th>
@@ -505,7 +505,7 @@ To function properly, TypeScript requires type definitions for the different lib
505505
Start by installing type definitions for jQuery and DataTables by executing in the command line:
506506

507507
```sh
508-
npm install --save-dev @types/jquery @types/jquery.datatables
508+
npm install --save-dev @types/jquery@1 @types/datatables.net
509509
```
510510

511511
Type definitions for Moment.js are distributed together with the Moment.js package. Even though, you're loading Moment.js from a URL, in order to use its typings, you still need to install the Moment.js package in the project.
@@ -530,7 +530,7 @@ Having defined **$** as jQuery you can now remove the local definition of **$**
530530
var $: any = (window as any).$;
531531
```
532532

533-
Because DataTables is a jQuery plugin that attaches itself to jQuery you cannot load its type definition directly. Instead, you have to add it to the list of types loaded globally. In the code editor, open the **./tsconfig.json** file and to the **types** array add **jquery.datatables**:
533+
Because DataTables is a jQuery plugin that attaches itself to jQuery you cannot load its type definition directly. Instead, you have to add it to the list of types loaded globally. In the code editor, open the **./tsconfig.json** file and to the **types** array add **datatables.net**:
534534

535535
```json
536536
{
@@ -544,7 +544,7 @@ Because DataTables is a jQuery plugin that attaches itself to jQuery you cannot
544544
"types": [
545545
"es6-promise",
546546
"es6-collections",
547-
"jquery.datatables",
547+
"datatables.net",
548548
"webpack-env"
549549
]
550550
}
@@ -607,7 +607,7 @@ export default class ItRequestsWebPart extends BaseClientSideWebPart<IItRequests
607607
},
608608
columnDefs: [{
609609
targets: 4,
610-
render: $.fn.dataTable.render.moment('YYYY/MM/DD')
610+
render: ($.fn as any).dataTable.render.moment('YYYY/MM/DD')
611611
}]
612612
});
613613
}
@@ -629,7 +629,7 @@ import * as $ from 'jquery';
629629
import * as moment from 'moment';
630630

631631
/* tslint:disable:no-function-expression */
632-
$.fn.dataTable.render.moment = function (from: string, to: string, locale: string): (d: any, type: string, row: any) => string {
632+
($.fn as any).dataTable.render.moment = function (from: string, to: string, locale: string): (d: any, type: string, row: any) => string {
633633
/* tslint:enable */
634634
// Argument shifting
635635
if (arguments.length === 1) {

docs/spfx/web-parts/guidance/migrate-jquery-fullcalendar-script-to-spfx.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ When prompted, define values as follows:
185185
- **WebPart** as the client-side component to create
186186
- **Tasks calendar** as your web part name
187187
- **Shows tasks in the calendar view** as your web part description
188-
- **No javaScript web framework** as the starting point to build the web part
188+
- **No JavaScript web framework** as the starting point to build the web part
189189

190190
![SharePoint Framework Yeoman generator with the default choices](../../../../images/fullcalendar-yeoman.png)
191191

@@ -365,7 +365,7 @@ function updateTask(id, startDate, dueDate) {
365365
}
366366
```
367367

368-
This code is almost identical with the original code of the Script Editor Web Part customization. The only difference is that where the original code retrieved the URL of the current web from the global **\_spPageContextInfo** variable set by SharePoint (lines 8, 45, 96 and 104), the code in the SharePoint Framework uses a custom variable that you will have to set in the web part. SharePoint Framework client-side web parts can be used both on classic and modern pages. While the **_spPageContextInfo** variable is present on classic pages, it's not available on modern pages which is why you can't rely on it and need a custom property that you can control yourself instead.
368+
This code is almost identical with the original code of the Script Editor Web Part customization. The only difference is that where the original code retrieved the URL of the current web from the global **\_spPageContextInfo** variable set by SharePoint (lines 8, 45, 96 and 104), the code in the SharePoint Framework uses a custom variable that you will have to set in the web part. SharePoint Framework client-side web parts can be used both on classic and modern pages. While the **\_spPageContextInfo** variable is present on classic pages, it's not available on modern pages which is why you can't rely on it and need a custom property that you can control yourself instead.
369369

370370
In order to reference this file in the web part, in the code editor, open the **./src/webparts/tasksCalendar/TasksCalendarWebPart.ts** file and change the **render** method to:
371371

docs/spfx/web-parts/guidance/share-data-between-web-parts.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Share Data Between Client-Side Web Parts
22

3-
> Note. This article has not yet been verified with the SPFx GA version, so you might have challenges making this work as described using the latest release.
4-
53
When building client-side web parts, loading data once and reusing it across different web parts will help you improve the performance of your pages and decrease the load on your network. This article describes a number of approaches that you can use to share data across multiple web parts.
64

75
## Why Share Data Between Web Parts
@@ -327,12 +325,14 @@ SharePoint Framework services can be built using the same project build system a
327325

328326
```json
329327
{
330-
"$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json",
328+
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-library-manifest.schema.json",
331329

332330
"id": "69b1aacd-68f2-4147-8433-8efb08eae331",
333331
"alias": "DocumentsService",
334332
"componentType": "Library",
335-
"version": "0.0.1",
333+
334+
// The "*" signifies that the version should be taken from the package.json
335+
"version": "*",
336336
"manifestVersion": 2
337337
}
338338
```

docs/spfx/web-parts/guidance/tutorial-share-data-between-web-parts-global-variable.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,21 @@ Remove the standard `description` property from the web part manifest. Open the
6262

6363
```json
6464
{
65-
"$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json",
65+
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
6666

6767
"id": "7a7e3aa9-5d8a-4155-936b-0b0e06e9ca11",
6868
"alias": "RecentDocumentsWebPart",
6969
"componentType": "WebPart",
70-
"version": "0.0.1",
70+
71+
// The "*" signifies that the version should be taken from the package.json
72+
"version": "*",
7173
"manifestVersion": 2,
7274

75+
// If true, the component can only be installed on sites where Custom Script is allowed.
76+
// Components that allow authors to embed arbitrary script code should set this to true.
77+
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
78+
"requiresCustomScript": false,
79+
7380
"preconfiguredEntries": [{
7481
"groupId": "7a7e3aa9-5d8a-4155-936b-0b0e06e9ca11",
7582
"group": { "default": "Under Development" },
@@ -372,14 +379,21 @@ Remove the standard `description` property from the web part manifest. Open the
372379

373380
```json
374381
{
375-
"$schema": "../../../node_modules/@microsoft/sp-module-interfaces/lib/manifestSchemas/jsonSchemas/clientSideComponentManifestSchema.json",
382+
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
376383

377384
"id": "71a6f643-1ac1-47ee-a9f1-502ef52f26d4",
378385
"alias": "RecentDocumentWebPart",
379386
"componentType": "WebPart",
380-
"version": "0.0.1",
387+
388+
// The "*" signifies that the version should be taken from the package.json
389+
"version": "*",
381390
"manifestVersion": 2,
382391

392+
// If true, the component can only be installed on sites where Custom Script is allowed.
393+
// Components that allow authors to embed arbitrary script code should set this to true.
394+
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
395+
"requiresCustomScript": false,
396+
383397
"preconfiguredEntries": [{
384398
"groupId": "71a6f643-1ac1-47ee-a9f1-502ef52f26d4",
385399
"group": { "default": "Under Development" },
@@ -490,19 +504,19 @@ import {
490504
DocumentCard,
491505
DocumentCardPreview,
492506
DocumentCardTitle,
493-
DocumentCardActivity,
494-
ImageFit
495-
} from 'office-ui-fabric-react';
507+
DocumentCardActivity
508+
} from 'office-ui-fabric-react/lib/DocumentCard';
509+
import { ImageFit } from 'office-ui-fabric-react/lib/Image';
496510
import { IDocument } from '../../IDocument';
497511
import styles from './RecentDocument.module.scss';
498512
import { IRecentDocumentProps } from './IRecentDocumentProps';
499513

500-
export default class RecentDocument extends React.Component<IRecentDocumentProps, void> {
514+
export default class RecentDocument extends React.Component<IRecentDocumentProps, {}> {
501515
public render(): React.ReactElement<IRecentDocumentProps> {
502516
const document: IDocument = this.props.document;
503517

504518
return (
505-
<div className={styles.helloWorld}>
519+
<div className={styles.recentDocument}>
506520
<DocumentCard onClickHref={document.url}>
507521
<DocumentCardPreview previewImages={[{
508522
name: document.title,
@@ -719,7 +733,7 @@ import { IDocument } from '../services/documentsService';
719733
instead of:
720734

721735
```ts
722-
import { IDocument } from '../services/documentsService/IDocument.ts';
736+
import { IDocument } from '../services/documentsService/IDocument';
723737
```
724738

725739
If at some point you decided that it's better to move the **IDocument.ts** file to a subfolder or merge a few files together, the only thing that you would change is the path in the barrel definition (**./src/services/documentsService/index.ts**). All elements in the project could still use the exact same relative path to the **documentsService** folder to reference the `IDocument` interface.

0 commit comments

Comments
 (0)