Added the real-time documents sample (#670)
This commit is contained in:
parent
0f78f7241b
commit
319523db19
|
@ -0,0 +1,25 @@
|
|||
# EditorConfig helps developers define and maintain consistent
|
||||
# coding styles between different editors and IDEs
|
||||
# editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
|
||||
[*]
|
||||
|
||||
# change these settings to your own preference
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
# we recommend you to keep these unchanged
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[{package,bower}.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,34 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
|
||||
# Build generated files
|
||||
dist
|
||||
lib
|
||||
solution
|
||||
temp
|
||||
*.sppkg
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# OSX
|
||||
.DS_Store
|
||||
|
||||
# Visual Studio files
|
||||
.ntvs_analysis.dat
|
||||
.vs
|
||||
bin
|
||||
obj
|
||||
|
||||
# Resx Generated Code
|
||||
*.resx.ts
|
||||
|
||||
# Styles Generated Code
|
||||
*.scss.ts
|
||||
|
||||
.npmrc
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"@microsoft/generator-sharepoint": {
|
||||
"isCreatingSolution": true,
|
||||
"environment": "spo",
|
||||
"version": "1.7.0-pr.3",
|
||||
"libraryName": "react-realtime-documents",
|
||||
"libraryId": "c36a8a7b-1d47-4ccd-9911-6b8df3ee0a9a",
|
||||
"packageManager": "npm",
|
||||
"isDomainIsolated": false,
|
||||
"componentType": "webpart"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
# List subscription
|
||||
|
||||
Sample web part illustrating using the SharePoint Framework List subscription capability, which allows you to get notified of changes to documents in a SharePoint Document Library and refresh the displayed data.
|
||||
|
||||
![Web parts placed on a modern SharePoint page showing information about documents](./assets/list-subscription-webpart.png)
|
||||
|
||||
## Used SharePoint Framework Version
|
||||
![drop](https://img.shields.io/badge/drop-1.7.0-green.svg)
|
||||
|
||||
## Applies to
|
||||
|
||||
* [SharePoint Framework](http://dev.office.com/sharepoint/docs/spfx/sharepoint-framework-overview)
|
||||
* [Office 365 developer tenant](http://dev.office.com/sharepoint/docs/spfx/set-up-your-developer-tenant)
|
||||
|
||||
## Solution
|
||||
|
||||
Solution|Author(s)
|
||||
--------|---------
|
||||
react-realtime-documents|Waldek Mastykarz (MVP, Rencore, @waldekm)
|
||||
|
||||
## Version history
|
||||
|
||||
Version|Date|Comments
|
||||
-------|----|--------
|
||||
1.0|November 9, 2018|Initial release
|
||||
|
||||
## Disclaimer
|
||||
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||
|
||||
---
|
||||
|
||||
## Minimal Path to Awesome
|
||||
|
||||
* clone this repo
|
||||
* change the working directory to the cloned repository
|
||||
* in the command line execute:
|
||||
* `npm install`
|
||||
* `gulp bundle --ship`
|
||||
* `gulp package-solution --ship`
|
||||
* from the _sharepoint/solution_ folder, deploy the .sppkg file to the App catalog in your tenant
|
||||
* in the site where you want to test this solution
|
||||
* ensure that you have a document library
|
||||
* add the web part to the page
|
||||
* in the web part properties, select the document library and apply the configuration
|
||||
* in the document library, add or update an existing document > web part should automatically update the list of documents
|
||||
|
||||
## Features
|
||||
|
||||
This sample contains a SharePoint Framework client-side web part that illustrates the List subscription capability:
|
||||
|
||||
* subscribing to changes in SharePoint Document Libraries from a SharePoint Framework web part
|
||||
* using [PnPjs](https://pnp.github.io/pnpjs/) to communicate with the SharePoint REST API
|
||||
* using [PnP Reusable property pane controls](https://sharepoint.github.io/sp-dev-fx-property-controls/) for easily managing web part properties
|
||||
* using [PnP Reusable React controls](https://sharepoint.github.io/sp-dev-fx-controls-react/) for building rich web experiences
|
||||
|
||||
<img src="https://telemetry.sharepointpnp.com/sp-dev-fx-webparts/samples/react-realtime-documents" />
|
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||
"version": "2.0",
|
||||
"bundles": {
|
||||
"latest-documents-web-part": {
|
||||
"components": [
|
||||
{
|
||||
"entrypoint": "./lib/webparts/latestDocuments/LatestDocumentsWebPart.js",
|
||||
"manifest": "./src/webparts/latestDocuments/LatestDocumentsWebPart.manifest.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"externals": {},
|
||||
"localizedResources": {
|
||||
"LatestDocumentsWebPartStrings": "lib/webparts/latestDocuments/loc/{locale}.js",
|
||||
"PropertyControlStrings": "node_modules/@pnp/spfx-property-controls/lib/loc/{locale}.js",
|
||||
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
|
||||
"deployCdnPath": "temp/deploy"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||
"workingDir": "./temp/deploy/",
|
||||
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||
"container": "react-realtime-documents",
|
||||
"accessKey": "<!-- ACCESS KEY -->"
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||
"solution": {
|
||||
"name": "react-realtime-documents-client-side-solution",
|
||||
"id": "c36a8a7b-1d47-4ccd-9911-6b8df3ee0a9a",
|
||||
"version": "1.0.0.0",
|
||||
"includeClientSideAssets": true,
|
||||
"skipFeatureDeployment": true,
|
||||
"isDomainIsolated": false
|
||||
},
|
||||
"paths": {
|
||||
"zippedPackage": "solution/react-realtime-documents.sppkg"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
|
||||
"port": 4321,
|
||||
"https": true,
|
||||
"initialPage": "https://localhost:5432/workbench",
|
||||
"api": {
|
||||
"port": 5432,
|
||||
"entryPath": "node_modules/@microsoft/sp-webpart-workbench/lib/api/"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const gulp = require('gulp');
|
||||
const build = require('@microsoft/sp-build-web');
|
||||
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||
|
||||
build.initialize(gulp);
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"name": "react-realtime-documents",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": ">=0.10.0"
|
||||
},
|
||||
"author": {
|
||||
"name": "Waldek Mastykarz",
|
||||
"url": "https://rencore.com"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "gulp bundle",
|
||||
"clean": "gulp clean",
|
||||
"test": "gulp test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@microsoft/sp-core-library": "1.7.0",
|
||||
"@microsoft/sp-list-subscription": "1.7.0",
|
||||
"@microsoft/sp-lodash-subset": "1.7.0",
|
||||
"@microsoft/sp-office-ui-fabric-core": "1.7.0",
|
||||
"@microsoft/sp-webpart-base": "1.7.0",
|
||||
"@pnp/common": "^1.2.3",
|
||||
"@pnp/logging": "^1.2.3",
|
||||
"@pnp/odata": "^1.2.3",
|
||||
"@pnp/sp": "^1.2.3",
|
||||
"@pnp/spfx-controls-react": "1.9.0",
|
||||
"@pnp/spfx-property-controls": "1.11.0",
|
||||
"@types/es6-promise": "0.0.33",
|
||||
"@types/react": "16.4.2",
|
||||
"@types/react-dom": "16.0.5",
|
||||
"@types/webpack-env": "1.13.1",
|
||||
"office-ui-fabric-react": "^5.131.1",
|
||||
"react": "16.3.2",
|
||||
"react-dom": "16.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@microsoft/sp-build-web": "1.7.0",
|
||||
"@microsoft/sp-tslint-rules": "1.7.0",
|
||||
"@microsoft/sp-module-interfaces": "1.7.0",
|
||||
"@microsoft/sp-webpart-workbench": "1.7.0",
|
||||
"gulp": "~3.9.1",
|
||||
"@types/chai": "3.4.34",
|
||||
"@types/mocha": "2.2.38",
|
||||
"ajv": "~5.2.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
|
||||
"id": "b9067965-0083-410e-b57d-1fab447f5eca",
|
||||
"alias": "LatestDocumentsWebPart",
|
||||
"componentType": "WebPart",
|
||||
|
||||
// The "*" signifies that the version should be taken from the package.json
|
||||
"version": "*",
|
||||
"manifestVersion": 2,
|
||||
|
||||
// If true, the component can only be installed on sites where Custom Script is allowed.
|
||||
// Components that allow authors to embed arbitrary script code should set this to true.
|
||||
// https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f
|
||||
"requiresCustomScript": false,
|
||||
|
||||
"preconfiguredEntries": [{
|
||||
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
|
||||
"group": { "default": "Other" },
|
||||
"title": { "default": "Latest documents" },
|
||||
"description": { "default": "Shows always up-to-date list of documents from the selected library" },
|
||||
"officeFabricIconFontName": "Page",
|
||||
"properties": {
|
||||
"title": "Latest documents"
|
||||
}
|
||||
}]
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
import * as React from 'react';
|
||||
import * as ReactDom from 'react-dom';
|
||||
import { Version } from '@microsoft/sp-core-library';
|
||||
import {
|
||||
BaseClientSideWebPart,
|
||||
IPropertyPaneConfiguration
|
||||
} from '@microsoft/sp-webpart-base';
|
||||
|
||||
import * as strings from 'LatestDocumentsWebPartStrings';
|
||||
import LatestDocuments from './components/LatestDocuments';
|
||||
import { ILatestDocumentsProps } from './components/ILatestDocumentsProps';
|
||||
import { PropertyFieldListPicker, PropertyFieldListPickerOrderBy } from '@pnp/spfx-property-controls/lib/PropertyFieldListPicker';
|
||||
import { CalloutTriggers } from '@pnp/spfx-property-controls/lib/PropertyFieldHeader';
|
||||
import { PropertyFieldTextWithCallout } from '@pnp/spfx-property-controls/lib/PropertyFieldTextWithCallout';
|
||||
import { ListSubscriptionFactory } from '@microsoft/sp-list-subscription';
|
||||
import { sp } from '@pnp/sp';
|
||||
|
||||
export interface ILatestDocumentsWebPartProps {
|
||||
libraryId?: string;
|
||||
siteUrl?: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export default class LatestDocumentsWebPart extends BaseClientSideWebPart<ILatestDocumentsWebPartProps> {
|
||||
public onInit(): Promise<void> {
|
||||
sp.setup({
|
||||
spfxContext: this.context
|
||||
});
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public render(): void {
|
||||
const element: React.ReactElement<ILatestDocumentsProps> = React.createElement(
|
||||
LatestDocuments,
|
||||
{
|
||||
displayMode: this.displayMode,
|
||||
libraryId: this.properties.libraryId,
|
||||
listSubscriptionFactory: new ListSubscriptionFactory(this),
|
||||
onConfigure: this._onConfigure,
|
||||
siteUrl: this.properties.siteUrl,
|
||||
title: this.properties.title,
|
||||
updateProperty: value => this.properties.title = value
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected onDispose(): void {
|
||||
ReactDom.unmountComponentAtNode(this.domElement);
|
||||
}
|
||||
|
||||
protected get dataVersion(): Version {
|
||||
return Version.parse('1.0');
|
||||
}
|
||||
|
||||
protected getPropertyPaneConfiguration(): IPropertyPaneConfiguration {
|
||||
return {
|
||||
pages: [
|
||||
{
|
||||
header: {
|
||||
description: strings.PropertyPaneDescription
|
||||
},
|
||||
groups: [
|
||||
{
|
||||
groupName: strings.BasicGroupName,
|
||||
groupFields: [
|
||||
PropertyFieldTextWithCallout('siteUrl', {
|
||||
calloutTrigger: CalloutTriggers.Click,
|
||||
key: 'siteUrlFieldId',
|
||||
label: 'Site URL',
|
||||
calloutContent: React.createElement('span', {}, 'URL of the site where the document library to show documents from is located. Leave empty to connect to a document library from the current site'),
|
||||
calloutWidth: 250,
|
||||
value: this.properties.siteUrl
|
||||
}),
|
||||
PropertyFieldListPicker('libraryId', {
|
||||
label: 'Select a document library',
|
||||
selectedList: this.properties.libraryId,
|
||||
includeHidden: false,
|
||||
orderBy: PropertyFieldListPickerOrderBy.Title,
|
||||
disabled: false,
|
||||
onPropertyChange: this.onPropertyPaneFieldChanged.bind(this),
|
||||
properties: this.properties,
|
||||
context: this.context,
|
||||
onGetErrorMessage: null,
|
||||
deferredValidationTime: 0,
|
||||
key: 'listPickerFieldId',
|
||||
webAbsoluteUrl: this.properties.siteUrl,
|
||||
baseTemplate: 101
|
||||
})
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
protected get disableReactivePropertyChanges(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected onPropertyPaneConfigurationComplete(): void {
|
||||
// ideally, we'd call a refresh here to update the list of properties
|
||||
// but due to a bug in the list picker control, lists are loaded only
|
||||
// on component mount, so this wouldn't do anything
|
||||
// https://github.com/SharePoint/sp-dev-fx-property-controls/issues/109
|
||||
// this.context.propertyPane.refresh();
|
||||
}
|
||||
|
||||
private _onConfigure = () => this.context.propertyPane.open();
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
import { ListSubscriptionFactory } from "@microsoft/sp-list-subscription";
|
||||
import { DisplayMode } from "@microsoft/sp-core-library";
|
||||
|
||||
export interface ILatestDocumentsProps {
|
||||
/**
|
||||
* Web part display mode
|
||||
*/
|
||||
displayMode: DisplayMode;
|
||||
/**
|
||||
* ID of the list to retrieve documents from. Undefined, if no library
|
||||
* has been selected
|
||||
*/
|
||||
libraryId?: string;
|
||||
/**
|
||||
* Instance of the ListSubscriptionFactory to use to create a list
|
||||
* subscription
|
||||
*/
|
||||
listSubscriptionFactory: ListSubscriptionFactory;
|
||||
/**
|
||||
* Event handler after clicking the 'Configure' button in the Placeholder
|
||||
* component
|
||||
*/
|
||||
onConfigure: () => void;
|
||||
/**
|
||||
* URL of the site where the selected library is located. Undefined, if the
|
||||
* selected library is in the current site
|
||||
*/
|
||||
siteUrl?: string;
|
||||
/**
|
||||
* Web part title to show in the body
|
||||
*/
|
||||
title: string;
|
||||
/**
|
||||
* Event handler after updating the web part title
|
||||
*/
|
||||
updateProperty: (value: string) => void;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
export interface ILatestDocumentsState {
|
||||
documents: Document[];
|
||||
error?: string;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export interface Document {
|
||||
Title: string;
|
||||
ServerRelativeUrl: string;
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
|
||||
|
||||
.latestDocuments {
|
||||
.container {
|
||||
max-width: 700px;
|
||||
margin: 0px auto;
|
||||
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2), 0 25px 50px 0 rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.row {
|
||||
@include ms-Grid-row;
|
||||
@include ms-fontColor-white;
|
||||
background-color: $ms-color-themeDark;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.column {
|
||||
@include ms-Grid-col;
|
||||
@include ms-lg10;
|
||||
@include ms-xl8;
|
||||
@include ms-xlPush2;
|
||||
@include ms-lgPush1;
|
||||
}
|
||||
|
||||
.title {
|
||||
@include ms-font-xl;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.subTitle {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.description {
|
||||
@include ms-font-l;
|
||||
@include ms-fontColor-white;
|
||||
}
|
||||
|
||||
.button {
|
||||
// Our button
|
||||
text-decoration: none;
|
||||
height: 32px;
|
||||
|
||||
// Primary Button
|
||||
min-width: 80px;
|
||||
background-color: $ms-color-themePrimary;
|
||||
border-color: $ms-color-themePrimary;
|
||||
color: $ms-color-white;
|
||||
|
||||
// Basic Button
|
||||
outline: transparent;
|
||||
position: relative;
|
||||
font-family: "Segoe UI WestEuropean","Segoe UI",-apple-system,BlinkMacSystemFont,Roboto,"Helvetica Neue",sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
font-size: $ms-font-size-m;
|
||||
font-weight: $ms-font-weight-regular;
|
||||
border-width: 0;
|
||||
text-align: center;
|
||||
cursor: pointer;
|
||||
display: inline-block;
|
||||
padding: 0 16px;
|
||||
|
||||
.label {
|
||||
font-weight: $ms-font-weight-semibold;
|
||||
font-size: $ms-font-size-m;
|
||||
height: 32px;
|
||||
line-height: 32px;
|
||||
margin: 0 4px;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
import * as React from 'react';
|
||||
import styles from './LatestDocuments.module.scss';
|
||||
import { ILatestDocumentsProps, ILatestDocumentsState } from '.';
|
||||
import { Placeholder } from "@pnp/spfx-controls-react/lib/Placeholder";
|
||||
import { Spinner, SpinnerSize } from 'office-ui-fabric-react/lib/components/Spinner';
|
||||
import { ListView, SelectionMode } from "@pnp/spfx-controls-react/lib/ListView";
|
||||
import { sp, Web, Site } from '@pnp/sp';
|
||||
import { IListSubscription } from '@microsoft/sp-list-subscription';
|
||||
import { Guid } from '@microsoft/sp-core-library';
|
||||
import { WebPartTitle } from "@pnp/spfx-controls-react/lib/WebPartTitle";
|
||||
|
||||
export default class LatestDocuments extends React.Component<ILatestDocumentsProps, ILatestDocumentsState> {
|
||||
private _listSubscription: IListSubscription;
|
||||
|
||||
constructor(props: ILatestDocumentsProps) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
documents: [],
|
||||
error: undefined,
|
||||
loading: true
|
||||
};
|
||||
}
|
||||
|
||||
public componentDidMount(): void {
|
||||
if (!this.props.libraryId) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._configureListSubscription();
|
||||
this._loadDocuments();
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: Readonly<ILatestDocumentsProps>, prevState: Readonly<ILatestDocumentsState>, snapshot?: any): void {
|
||||
if (this.props.libraryId === prevProps.libraryId) {
|
||||
// something has changed but the library id is the same so no need to
|
||||
// reload documents or configure the subscription
|
||||
return;
|
||||
}
|
||||
|
||||
this._configureListSubscription();
|
||||
this._loadDocuments();
|
||||
}
|
||||
|
||||
public render(): React.ReactElement<ILatestDocumentsProps> {
|
||||
const { onConfigure } = this.props;
|
||||
const needsConfiguration: boolean = !this.props.libraryId;
|
||||
const { error, documents, loading } = this.state;
|
||||
|
||||
return (
|
||||
<div className={styles.latestDocuments}>
|
||||
<WebPartTitle displayMode={this.props.displayMode}
|
||||
title={this.props.title}
|
||||
updateProperty={this.props.updateProperty} />
|
||||
{needsConfiguration &&
|
||||
<Placeholder
|
||||
iconName='Edit'
|
||||
iconText='Configure your web part'
|
||||
description='Please configure the web part.'
|
||||
buttonLabel='Configure'
|
||||
onConfigure={onConfigure} />
|
||||
}
|
||||
{!needsConfiguration &&
|
||||
loading &&
|
||||
<div style={{ textAlign: 'center' }}><Spinner size={SpinnerSize.large} label="Loading documents..." /></div>}
|
||||
{!needsConfiguration &&
|
||||
!loading &&
|
||||
error &&
|
||||
<div style={{ textAlign: 'center' }}>The following error has occurred while loading documents: <span>{error}</span></div>}
|
||||
{!needsConfiguration &&
|
||||
!loading &&
|
||||
documents.length === 0 &&
|
||||
<div style={{ textAlign: 'center' }}>No documents found in the selected list</div>}
|
||||
{!needsConfiguration &&
|
||||
!loading &&
|
||||
documents.length > 0 &&
|
||||
<ListView
|
||||
items={documents}
|
||||
viewFields={[{
|
||||
displayName: 'Name',
|
||||
name: 'FileLeafRef',
|
||||
linkPropertyName: 'FileRef'
|
||||
}]}
|
||||
iconFieldName="FileRef"
|
||||
compact={false}
|
||||
selectionMode={SelectionMode.none} />
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads documents from the selected document library
|
||||
*/
|
||||
private _loadDocuments(): void {
|
||||
// communicate loading documents to the user
|
||||
this.setState({
|
||||
documents: [],
|
||||
error: undefined,
|
||||
loading: true
|
||||
});
|
||||
|
||||
// if a site URL has been specified, use that site, otherwise assume,
|
||||
// that the selected list is in the current site
|
||||
const web: Web = this.props.siteUrl ? new Web(this.props.siteUrl) : sp.web;
|
||||
web.lists
|
||||
.getById(this.props.libraryId)
|
||||
// FileLeafRef contains the name of the file, FileRef contains the
|
||||
// server-relative URL of the file to be used in the document link
|
||||
.items.select('FileLeafRef', 'FileRef')
|
||||
.orderBy('Modified', false)
|
||||
.get()
|
||||
// show retrieved documents, if any
|
||||
.then(docs => this.setState({
|
||||
documents: docs,
|
||||
loading: false
|
||||
}))
|
||||
// show error
|
||||
.catch(err => this.setState({
|
||||
error: err,
|
||||
loading: false
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to changes in a list documentary using the SharePoint Framework
|
||||
* ListSubscriptionFactory.
|
||||
*/
|
||||
private _configureListSubscription(): void {
|
||||
if (!this.props.libraryId) {
|
||||
// no library selected. If there is an existing list subscription, remove it
|
||||
if (this._listSubscription) {
|
||||
this.props.listSubscriptionFactory.deleteSubscription(this._listSubscription);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// if the selected library is located in a different site (collection),
|
||||
// we need site collection and site id to setup the list subscription
|
||||
let siteCollectionId: string, siteId: string;
|
||||
this
|
||||
._getSiteCollectionId(this.props.siteUrl)
|
||||
.then((id: string | undefined): Promise<void | string> => {
|
||||
siteCollectionId = id;
|
||||
return this._getSiteId(this.props.siteUrl);
|
||||
})
|
||||
.then((id: string | undefined): void => {
|
||||
siteId = id;
|
||||
// remove existing subscription if any
|
||||
if (this._listSubscription) {
|
||||
this.props.listSubscriptionFactory.deleteSubscription(this._listSubscription);
|
||||
}
|
||||
|
||||
this.props.listSubscriptionFactory.createSubscription({
|
||||
siteId: siteCollectionId ? Guid.parse(siteCollectionId) : undefined,
|
||||
webId: siteId ? Guid.parse(siteId) : undefined,
|
||||
listId: Guid.parse(this.props.libraryId),
|
||||
callbacks: {
|
||||
notification: this._loadDocuments.bind(this)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ID of the specified site collection
|
||||
*
|
||||
* If no URL is specified, returns an empty resolved promise.
|
||||
*
|
||||
* @param siteUrl URL of the site collection for which to retrieve the ID
|
||||
*/
|
||||
private _getSiteCollectionId(siteUrl?: string): Promise<void | string> {
|
||||
if (!siteUrl) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise<string>((resolve: (siteId: string) => void, reject: (error: any) => void): void => {
|
||||
const site: Site = new Site(siteUrl);
|
||||
site.select('Id').get()
|
||||
.then(({ Id }): void => {
|
||||
resolve(Id);
|
||||
})
|
||||
.catch(err => reject(err));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the ID of the specified site
|
||||
*
|
||||
* If no URL is specified, returns a empty resolved promise.
|
||||
*
|
||||
* @param siteUrl URL of the site for which to retrieve the ID
|
||||
*/
|
||||
private _getSiteId(siteUrl?: string): Promise<void | string> {
|
||||
if (!siteUrl) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
return new Promise<string>((resolve: (siteId: string) => void, reject: (error: any) => void): void => {
|
||||
const web: Web = new Web(siteUrl);
|
||||
web.select('Id').get()
|
||||
.then(({ Id }): void => {
|
||||
resolve(Id);
|
||||
})
|
||||
.catch(err => reject(err));
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
export * from './ILatestDocumentsProps';
|
||||
export * from './ILatestDocumentsState';
|
|
@ -0,0 +1,7 @@
|
|||
define([], function() {
|
||||
return {
|
||||
"PropertyPaneDescription": "Description",
|
||||
"BasicGroupName": "Group Name",
|
||||
"DescriptionFieldLabel": "Description Field"
|
||||
}
|
||||
});
|
10
samples/react-realtime-documents/src/webparts/latestDocuments/loc/mystrings.d.ts
vendored
Normal file
10
samples/react-realtime-documents/src/webparts/latestDocuments/loc/mystrings.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
declare interface ILatestDocumentsWebPartStrings {
|
||||
PropertyPaneDescription: string;
|
||||
BasicGroupName: string;
|
||||
DescriptionFieldLabel: string;
|
||||
}
|
||||
|
||||
declare module 'LatestDocumentsWebPartStrings' {
|
||||
const strings: ILatestDocumentsWebPartStrings;
|
||||
export = strings;
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
{
|
||||
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.2/MicrosoftTeams.schema.json",
|
||||
"manifestVersion": "1.2",
|
||||
"packageName": "LatestDocuments",
|
||||
"id": "b9067965-0083-410e-b57d-1fab447f5eca",
|
||||
"version": "0.1",
|
||||
"developer": {
|
||||
"name": "SPFx + Teams Dev",
|
||||
"websiteUrl": "https://products.office.com/en-us/sharepoint/collaboration",
|
||||
"privacyUrl": "https://privacy.microsoft.com/en-us/privacystatement",
|
||||
"termsOfUseUrl": "https://www.microsoft.com/en-us/servicesagreement"
|
||||
},
|
||||
"name": {
|
||||
"short": "LatestDocuments"
|
||||
},
|
||||
"description": {
|
||||
"short": "Shows always up-to-date list of documents from the selected library",
|
||||
"full": "Shows always up-to-date list of documents from the selected library"
|
||||
},
|
||||
"icons": {
|
||||
"outline": "tab20x20.png",
|
||||
"color": "tab96x96.png"
|
||||
},
|
||||
"accentColor": "#004578",
|
||||
"configurableTabs": [
|
||||
{
|
||||
"configurationUrl": "https://{teamSiteDomain}{teamSitePath}/_layouts/15/TeamsLogon.aspx?SPFX=true&dest={teamSitePath}/_layouts/15/teamshostedapp.aspx%3FopenPropertyPane=true%26teams%26componentId=b9067965-0083-410e-b57d-1fab447f5eca",
|
||||
"canUpdateConfiguration": true,
|
||||
"scopes": [
|
||||
"team"
|
||||
]
|
||||
}
|
||||
],
|
||||
"validDomains": [
|
||||
"*.login.microsoftonline.com",
|
||||
"*.sharepoint.com",
|
||||
"*.sharepoint-df.com",
|
||||
"spoppe-a.akamaihd.net",
|
||||
"spoprod-a.akamaihd.net",
|
||||
"resourceseng.blob.core.windows.net",
|
||||
"msft.spoppe.com"
|
||||
],
|
||||
"webApplicationInfo": {
|
||||
"resource": "https://{teamSiteDomain}",
|
||||
"id": "00000003-0000-0ff1-ce00-000000000000"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 933 B |
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"jsx": "react",
|
||||
"declaration": true,
|
||||
"sourceMap": true,
|
||||
"experimentalDecorators": true,
|
||||
"skipLibCheck": true,
|
||||
"outDir": "lib",
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./node_modules/@microsoft"
|
||||
],
|
||||
"types": [
|
||||
"es6-promise",
|
||||
"webpack-env"
|
||||
],
|
||||
"lib": [
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"lib"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"extends": "@microsoft/sp-tslint-rules/base-tslint.json",
|
||||
"rules": {
|
||||
"class-name": false,
|
||||
"export-name": false,
|
||||
"forin": false,
|
||||
"label-position": false,
|
||||
"member-access": true,
|
||||
"no-arg": false,
|
||||
"no-console": false,
|
||||
"no-construct": false,
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": false,
|
||||
"no-function-expression": true,
|
||||
"no-internal-module": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-unnecessary-semicolons": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-with-statement": true,
|
||||
"semicolon": true,
|
||||
"trailing-comma": false,
|
||||
"typedef": false,
|
||||
"typedef-whitespace": false,
|
||||
"use-named-parameter": true,
|
||||
"variable-name": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue