New sample - PnP ListView with PnP Field Controls (#1169)

* New sample - PnP ListView with PnP Field Controls

* console.log removed

* small fix
This commit is contained in:
Alex Terentiev 2020-03-10 02:34:52 -07:00 committed by GitHub
parent 5629b6fac3
commit afbd7595a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 18156 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,32 @@
# 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

View File

@ -0,0 +1,12 @@
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.10.0",
"libraryName": "react-pnp-controls-list-view-fields",
"libraryId": "c44d7aff-0bf4-4dbd-b126-49c5d0a277a0",
"packageManager": "npm",
"isDomainIsolated": false,
"componentType": "webpart"
}
}

View File

@ -0,0 +1,61 @@
# React PnP ListView with PnP Field Controls Web Part
Sample web part to display PnP [`ListView`](https://sharepoint.github.io/sp-dev-fx-controls-react/controls/ListView/) control with column rendering using PnP [Field Controls](https://sharepoint.github.io/sp-dev-fx-controls-react/controls/fields/main/).
![PnP List View](./assets/web-part.png)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/drop-1.10.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-pnp-controls-list-view-fields|[AJIXuMuK](https://github.com/AJIXuMuK)
## Version history
Version|Date|Comments
-------|----|--------
1.0|MArch 09, 2020|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
* move to right folder
* in the command line run:
* `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
* create Term Store group as shown on the screenshot below:
![Term Store](./assets/taxonomy.png)
* in the site where you want to test this solution
* create Country list as a standard Custom list and add few items in there
* create Journeys list with the next columns:
* Title - Single line of text
* JorneyDate - Date and Time
* VisitedCountries - Lookup with multiselection. Referenced list - Contry
* Experience - Choice with next choices: Bad, Normal, Good
* Picture - Hyperlink or Picture, display as Picture
* JourneyType - Managed Metadata connected to the Term Set created above
* add the app named _page-sections-navigation-client-side-solution_
* edit a page
* add _Page Sections Navigation_ web part
* add as much _Page Sections Navigation Anchor_ web parts as you want - each anchor adds an item to the navigation
* configure web parts
## Features
This sample demonstrates how to combine different parts of PnP Reusable React controls to create rich solutions. It also partially answers the question from [Issue 493](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/493) in PnP Reusable Controls repo.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 KiB

View File

@ -0,0 +1,19 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"pn-p-list-view-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/pnPListView/PnPListViewWebPart.js",
"manifest": "./src/webparts/pnPListView/PnPListViewWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"PnPListViewWebPartStrings": "lib/webparts/pnPListView/loc/{locale}.js",
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy"
}

View File

@ -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-pnp-controls-list-view-fields",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,14 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "react-pnp-controls-list-view-fields-client-side-solution",
"id": "c44d7aff-0bf4-4dbd-b126-49c5d0a277a0",
"version": "1.0.0.0",
"includeClientSideAssets": true,
"skipFeatureDeployment": true,
"isDomainIsolated": false
},
"paths": {
"zippedPackage": "solution/react-pnp-controls-list-view-fields.sppkg"
}
}

View File

@ -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/"
}
}

View File

@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->"
}

View File

@ -0,0 +1,7 @@
'use strict';
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(require('gulp'));

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
{
"name": "react-pnp-controls-list-view-fields",
"version": "0.0.1",
"private": true,
"main": "lib/index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.10.0",
"@microsoft/sp-lodash-subset": "1.10.0",
"@microsoft/sp-office-ui-fabric-core": "1.10.0",
"@microsoft/sp-property-pane": "1.10.0",
"@microsoft/sp-webpart-base": "1.10.0",
"@pnp/sp": "^2.0.3",
"@pnp/spfx-controls-react": "1.16.0",
"@types/es6-promise": "0.0.33",
"@types/react": "16.8.8",
"@types/react-dom": "16.8.3",
"@types/webpack-env": "1.13.1",
"office-ui-fabric-react": "5.132.0",
"react": "16.8.5",
"react-dom": "16.8.5"
},
"resolutions": {
"@types/react": "16.8.8"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.10.0",
"@microsoft/sp-tslint-rules": "1.10.0",
"@microsoft/sp-module-interfaces": "1.10.0",
"@microsoft/sp-webpart-workbench": "1.10.0",
"@microsoft/rush-stack-compiler-3.3": "0.3.5",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
}
}

View File

@ -0,0 +1 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler

View File

@ -0,0 +1,27 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "a258c763-2a50-4f04-abef-6c86dbc0d13d",
"alias": "PnPListViewWebPart",
"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,
"supportedHosts": ["SharePointWebPart"],
"preconfiguredEntries": [{
"groupId": "5c03119e-3074-46fd-976b-c60198311f70", // Other
"group": { "default": "Other" },
"title": { "default": "PnP ListView" },
"description": { "default": "PnP ListView description" },
"officeFabricIconFontName": "Page",
"properties": {
"description": "PnP ListView"
}
}]
}

View File

@ -0,0 +1,87 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-property-pane';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as strings from 'PnPListViewWebPartStrings';
import PnPListView from './components/PnPListView';
import { IPnPListViewProps } from './components/IPnPListViewProps';
import { sp } from '@pnp/sp';
import '@pnp/sp/webs';
import '@pnp/sp/lists';
import '@pnp/sp/items';
export interface IPnPListViewWebPartProps {
description: string;
}
export default class PnPListViewWebPart extends BaseClientSideWebPart <IPnPListViewWebPartProps> {
private _items: any[];
protected async onInit(): Promise<void> {
await super.onInit();
sp.setup({
spfxContext: this.context
});
const countries = await sp.web.lists.getByTitle('Country').items.get();
this._items = await sp.web.lists.getByTitle('Journeys').getItemsByCAMLQuery({
ViewXml: ''
});
this._items.forEach(item => {
const visitedCountriesIds: number[] = item['VisitedCountriesId'] as number[];
item['VisitedCountries'] = countries.filter(c => visitedCountriesIds.indexOf(c['ID']) !== -1).map(c => c['Title']);
});
}
public render(): void {
const element: React.ReactElement<IPnPListViewProps> = React.createElement(
PnPListView,
{
items: this._items,
context: this.context
}
);
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: [
PropertyPaneTextField('description', {
label: strings.DescriptionFieldLabel
})
]
}
]
}
]
};
}
}

View File

@ -0,0 +1,6 @@
import { WebPartContext } from '@microsoft/sp-webpart-base';
export interface IPnPListViewProps {
items: any[];
context: WebPartContext;
}

View File

@ -0,0 +1,12 @@
@import '~office-ui-fabric-react/dist/sass/References.scss';
.pnPListView {
.image {
max-width: 150px;
max-height: 150px;
img {
width: 150px;
}
}
}

View File

@ -0,0 +1,185 @@
import * as React from 'react';
import styles from './PnPListView.module.scss';
import { IPnPListViewProps } from './IPnPListViewProps';
import { ListView, IViewField } from '@pnp/spfx-controls-react/lib/ListView';
import { FieldTextRenderer } from '@pnp/spfx-controls-react/lib/FieldTextRenderer';
import { FieldDateRenderer } from '@pnp/spfx-controls-react/lib/FieldDateRenderer';
import { FieldLookupRenderer } from '@pnp/spfx-controls-react/lib/FieldLookupRenderer';
import { FieldUrlRenderer } from '@pnp/spfx-controls-react/lib/FieldUrlRenderer';
import { FieldTaxonomyRenderer } from '@pnp/spfx-controls-react/lib/FieldTaxonomyRenderer';
import { ISPFieldLookupValue } from '@pnp/spfx-controls-react/lib/Common';
import { IFrameDialog } from '@pnp/spfx-controls-react/lib/IFrameDialog';
import { DialogType } from 'office-ui-fabric-react/lib/Dialog';
export interface IPnPListViewState {
selectedLookupId?: string;
}
export default class PnPListView extends React.Component<IPnPListViewProps, IPnPListViewState> {
private readonly _countriesLookupFieldId = '5e037cea-aaef-40dd-895f-90442114016f';
private readonly _lookupFieldDispWebRelativeUrl = '/Lists/Country/DispForm.aspx?ID={0}&RootFolder=*&IsDlg=1';
private readonly _fields: IViewField[] = [{
name: 'Title',
displayName: 'Title',
minWidth: 150,
maxWidth: 250,
render: this._renderTitle
}, {
name: 'JourneyDate',
displayName: 'Journey Date',
render: this._renderDate
}, {
name: 'VisitedCountries',
displayName: 'Visited Countries',
minWidth: 100,
render: (item, index) => { return this._renderCountries(item, index); }
}, {
name: 'Experience',
displayName: 'Experience',
minWidth: 100,
render: this._renderExperience
}, {
name: 'Picture',
displayName: 'Picture',
minWidth: 150,
render: this._renderPicture
}, {
name: 'JourneyType',
displayName: 'Journey Type',
minWidth: 100,
render: this._renderJourneyType
}];
constructor(props: IPnPListViewProps) {
super(props);
this.state = {};
}
public render(): React.ReactElement<IPnPListViewProps> {
return (
<div className={styles.pnPListView}>
<ListView items={this.props.items} viewFields={this._fields} />
{this.state.selectedLookupId &&
<IFrameDialog
hidden={false}
url={`${this.props.context.pageContext.web.absoluteUrl}${this._lookupFieldDispWebRelativeUrl.replace('{0}', this.state.selectedLookupId.toString())}`}
iframeOnLoad={iframe => {
const iframeWindow: Window = iframe.contentWindow;
const iframeDocument: Document = iframeWindow.document;
const s4Workspace: HTMLDivElement = iframeDocument.getElementById('s4-workspace') as HTMLDivElement;
s4Workspace.style.height = iframe.style.height;
s4Workspace.scrollIntoView();
}}
onDismiss={() => {
this.setState({
selectedLookupId: undefined
});
}}
modalProps={{
isBlocking: true
}}
dialogContentProps={{
type: DialogType.close,
showCloseButton: true
}}
width={'570px'}
height={'250px'} />}
</div>
);
}
/**
* Title column renderer
* @param item ListView item
*/
private _renderTitle(item?: any): any {
return <FieldTextRenderer
text={item.Title}
/>;
}
/**
* Date column renderer
* @param item ListView item
*/
private _renderDate(item?: any): any {
const date = new Date(item['JourneyDate']);
return <FieldDateRenderer
text={date.toLocaleDateString()} />;
}
/**
* Countries (Multi Lookup) column renderer
* @param item ListView item
* @param index item index
*/
private _renderCountries(item?: any, index?: number): any {
//
// ListView item contains "flattened" information
// So, we're getting original item first
//
const originalItem = this.props.items[index!];
const visitedCountriesIds = originalItem['VisitedCountriesId'];
const visitedCountries = originalItem['VisitedCountries'];
const lookups: ISPFieldLookupValue[] = visitedCountries.map((vc, idx) => {
return {
lookupId: visitedCountriesIds[idx].toString(),
lookupValue: vc
};
});
return <FieldLookupRenderer
lookups={lookups}
onClick={args => {
this.setState({
selectedLookupId: args.lookup.lookupId
});
}} />;
}
/**
* Experience (Choice) column renderer
* @param item ListView item
*/
private _renderExperience(item?: any): any {
const experience: string = item['Expirience'];
return <FieldTextRenderer
text={experience}
/>;
}
/**
* Picture (Hyperlink or Picture) column renderer
* @param item ListView item
*/
private _renderPicture(item?: any): any {
return <FieldUrlRenderer
url={item['Picture.Url']}
isImageUrl={true}
className={styles.image}
text={item['Picture.Description'] || ''} />;
}
/**
* JourneyType (Managed Metadata) column renderer
* @param item ListView item
*/
private _renderJourneyType(item?: any) {
return <FieldTaxonomyRenderer
terms={[{
Label: item['JourneyType.Label'],
TermID: item['JourneyType.TermGuid']
}]} />;
}
}

View File

@ -0,0 +1,7 @@
define([], function() {
return {
"PropertyPaneDescription": "Description",
"BasicGroupName": "Group Name",
"DescriptionFieldLabel": "Description Field"
}
});

View File

@ -0,0 +1,10 @@
declare interface IPnPListViewWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'PnPListViewWebPartStrings' {
const strings: IPnPListViewWebPartStrings;
export = strings;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,38 @@
{
"extends": "./node_modules/@microsoft/rush-stack-compiler-3.3/includes/tsconfig-web.json",
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"outDir": "lib",
"inlineSources": false,
"strictNullChecks": false,
"noUnusedLocals": false,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
}

View File

@ -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
}
}