Taxonomy panel picker webpart (#546)

* Taxonomy panel picker web part

Code sample for the Taxonomy panel picker web part added.

* GIF path updated

GIF path in the readme file updated.

* Sample for pre-populated control added.

Sample for pre-populated control added.

* Update README.md
This commit is contained in:
Vipul Kelkar 2018-07-02 15:16:54 +05:30 committed by Vesa Juvonen
parent 48ac608381
commit 5fe4521c21
24 changed files with 18907 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,11 @@
{
"@microsoft/generator-sharepoint": {
"isCreatingSolution": true,
"environment": "spo",
"version": "1.5.0",
"libraryName": "react-taxonomypicker-panel",
"libraryId": "285e2b44-e2e0-4f31-b458-b5edd111cdf7",
"packageManager": "npm",
"componentType": "webpart"
}
}

View File

@ -0,0 +1,74 @@
# SPFx webpart with Taxonomy picker Office UI Fabric Panel.
## Summary
Sample webpart with Single and Multi-select taxonomy pickers using Office UI Fabric panel. The webpart uses the Taxonomy API support available in the SP-PNP-JS.
![TaxonomyPickerPanel webpart](https://github.com/vipulkelkar/sp-dev-fx-webparts/blob/TaxonomyPanelPicker/samples/react-taxonomypicker-panel/assets/TaxonomyPicker.gif)
## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/version-GA-green.svg)
## Applies to
* [SharePoint Framework](https:/dev.office.com/sharepoint)
* [Office 365 tenant](https://dev.office.com/sharepoint/docs/spfx/set-up-your-development-environment)
## Prerequisites
- sp-pnp-js
- Office UI Fabric React
## Solution
Solution|Author(s)
--------|---------
react-taxonomypicker-panel | Vipul Kelkar @vipulkelkar
## Version history
Version|Date|Comments
-------|----|--------
1.0|June 22, 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 repository
- Navigate to the file 'src/webparts/components/TermsPickerComponent.tsx'
- In the method "GetTerms", replace the <TERM_STORE_NAME> with the term store name in your tenant.
- Navigate to the file 'src/webparts/components/ReactTaxonomyPickerpanel.tsx'
- In the RENDER method of the webpart, a custom taxonomy picker component is used. Please replace the "TermSetId" property with the desired term set id in your tenant.
- in the command line run:
- `npm install`
- `gulp serve`
- Navigate to - <Your SP site>/_layouts/workbench.aspx and add the "react-taxonomypicker-panel"
## Features
- This webpart demonstrates the use of a custom taxonomy picker control built with Office UI Fabric React Panel and Tagpicker that enables users to select terms for a single-select or multi-select taxonomy field in a controlled manner.
- The custom taxonomy picker control is a reusable React component and can be easily placed in a SPFx webpart just by providing the TermSetId as a property to the component.
<TermsPickerComponent IsMultiValue={false} TermSetId='<TERM-SET-ID>' LabelText='Single-select field' SelectedTerms={<State variable>}/>
- By supplying the "SelectedTerms" property, the control can also be used in scenarios where pre-filled choices are to be shown such as the Edit form of a list item etc.
- The selected terms can be supplied as an array of a custom object
{
name : "<Term Name>",
key : "<Term ID>"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0",
"bundles": {
"react-taxonomypicker-panel-web-part": {
"components": [
{
"entrypoint": "./lib/webparts/reactTaxonomypickerPanel/ReactTaxonomypickerPanelWebPart.js",
"manifest": "./src/webparts/reactTaxonomypickerPanel/ReactTaxonomypickerPanelWebPart.manifest.json"
}
]
}
},
"externals": {},
"localizedResources": {
"ReactTaxonomypickerPanelWebPartStrings": "lib/webparts/reactTaxonomypickerPanel/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-taxonomypicker-panel",
"accessKey": "<!-- ACCESS KEY -->"
}

View File

@ -0,0 +1,12 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "react-taxonomypicker-panel-client-side-solution",
"id": "285e2b44-e2e0-4f31-b458-b5edd111cdf7",
"version": "1.0.0.0",
"includeClientSideAssets": true
},
"paths": {
"zippedPackage": "solution/react-taxonomypicker-panel.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,45 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/tslint.schema.json",
// Display errors as warnings
"displayAsWarning": true,
// The TSLint task may have been configured with several custom lint rules
// before this config file is read (for example lint rules from the tslint-microsoft-contrib
// project). If true, this flag will deactivate any of these rules.
"removeExistingRules": true,
// When true, the TSLint task is configured with some default TSLint "rules.":
"useDefaultConfigAsBase": false,
// Since removeExistingRules=true and useDefaultConfigAsBase=false, there will be no lint rules
// which are active, other than the list of rules below.
"lintConfig": {
// Opt-in to Lint rules which help to eliminate bugs in JavaScript
"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-case": true,
"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,
"valid-typeof": true,
"variable-name": false,
"whitespace": false
}
}
}

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

View File

@ -0,0 +1,41 @@
{
"name": "react-taxonomypicker-panel",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"build": "gulp bundle",
"clean": "gulp clean",
"test": "gulp test"
},
"dependencies": {
"@microsoft/sp-core-library": "1.5.0",
"@microsoft/sp-lodash-subset": "1.5.0",
"@microsoft/sp-office-ui-fabric-core": "1.5.0",
"@microsoft/sp-webpart-base": "1.5.0",
"@pnp/common": "^1.1.1",
"@pnp/logging": "^1.1.1",
"@pnp/odata": "^1.1.1",
"@pnp/sp": "^1.1.1",
"@pnp/sp-clientsvc": "^1.1.1",
"@pnp/sp-taxonomy": "^1.1.1",
"@types/es6-promise": "0.0.33",
"@types/react": "15.6.6",
"@types/react-dom": "15.5.6",
"@types/webpack-env": "1.13.1",
"react": "15.6.2",
"react-dom": "15.6.2",
"sp-pnp-js": "^3.0.9"
},
"devDependencies": {
"@microsoft/sp-build-web": "1.5.0",
"@microsoft/sp-module-interfaces": "1.5.0",
"@microsoft/sp-webpart-workbench": "1.5.0",
"gulp": "~3.9.1",
"@types/chai": "3.4.34",
"@types/mocha": "2.2.38",
"ajv": "~5.2.2"
}
}

View File

@ -0,0 +1,26 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "012d5b93-289d-4a0b-ae3b-c05bd274f80c",
"alias": "ReactTaxonomypickerPanelWebPart",
"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": "react-taxonomypicker-panel" },
"description": { "default": "Sample webpart for a taxonomy picker using Office-UI fabric panel component and sp-pnp-js taxonomy support." },
"officeFabricIconFontName": "Page",
"properties": {
"description": "react-taxonomypicker-panel"
}
}]
}

View File

@ -0,0 +1,60 @@
import * as React from 'react';
import * as ReactDom from 'react-dom';
import { Version } from '@microsoft/sp-core-library';
import {
BaseClientSideWebPart,
IPropertyPaneConfiguration,
PropertyPaneTextField
} from '@microsoft/sp-webpart-base';
import * as strings from 'ReactTaxonomypickerPanelWebPartStrings';
import ReactTaxonomypickerPanel from './components/ReactTaxonomypickerPanel';
import { IReactTaxonomypickerPanelProps } from './components/IReactTaxonomypickerPanelProps';
export interface IReactTaxonomypickerPanelWebPartProps {
description: string;
}
export default class ReactTaxonomypickerPanelWebPart extends BaseClientSideWebPart<IReactTaxonomypickerPanelWebPartProps> {
public render(): void {
const element: React.ReactElement<IReactTaxonomypickerPanelProps > = React.createElement(
ReactTaxonomypickerPanel,
{
description: this.properties.description
}
);
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,3 @@
export interface IReactTaxonomypickerPanelProps {
description: string;
}

View File

@ -0,0 +1,74 @@
@import '~@microsoft/sp-office-ui-fabric-core/dist/sass/SPFabricCore.scss';
.reactTaxonomypickerPanel {
.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;
}
}
}

View File

@ -0,0 +1,71 @@
import * as React from 'react';
import styles from './ReactTaxonomypickerPanel.module.scss';
import { IReactTaxonomypickerPanelProps } from './IReactTaxonomypickerPanelProps';
import { escape } from '@microsoft/sp-lodash-subset';
// Controls
import TermsPickerComponent, { ITaxonomyTerm } from './TermsPickerComponent';
import { DefaultButton, IButtonProps, Button } from 'office-ui-fabric-react/lib/Button';
export interface ITaxonomyPickerWebpartState{
SingleSelectFieldTerms:ITaxonomyTerm[],
MultiSelectFieldTerms:ITaxonomyTerm[]
}
export default class ReactTaxonomypickerPanel extends React.Component<IReactTaxonomypickerPanelProps, ITaxonomyPickerWebpartState> {
constructor(props, state:ITaxonomyPickerWebpartState){
super(props);
this.state = {
SingleSelectFieldTerms:[],
MultiSelectFieldTerms:[]
// Supply array in the below format for a pre-populated control.
//SingleSelectFieldTerms:[{name:"<Term-Label>", key="<Term-GUID>"}],
//MultiSelectFieldTerms:[{name:"<Term-Label>", key="<Term-GUID>"}, {name:"<Term-Label>", key="<Term-GUID>"}]
}
}
public render(): React.ReactElement<IReactTaxonomypickerPanelProps> {
return (
<div>
<div className="ms-Grid">
<div className="ms-Grid-row">
<div className="ms-Grid-col ms-sm12 ms-lg12">
<TermsPickerComponent IsMultiValue={false} TermSetId='<TERM-SET-ID>' LabelText='Single-select field' SelectedTerms={this.state.SingleSelectFieldTerms}/>
</div>
</div>
<div className="ms-Grid-row">
<div className="ms-Grid-col ms-sm12 ms-lg12">
<TermsPickerComponent IsMultiValue={true} TermSetId='<TERM-SET-ID>' LabelText='Multi-select field' SelectedTerms={this.state.MultiSelectFieldTerms}/>
</div>
</div>
</div>
<div>
</div>
<br/>
<br/>
<DefaultButton
primary={true}
text="Show selected values"
onClick={this._showTaxonomyControlValues.bind(this)}
/>
</div>
);
}
private _showTaxonomyControlValues(){
if(this.state.SingleSelectFieldTerms.length > 0){
alert("Single-Select term Label and GUID : \n" + this.state.SingleSelectFieldTerms[0].name + " - " + this.state.SingleSelectFieldTerms[0].key);
}
if(this.state.MultiSelectFieldTerms.length > 0){
let multiSelectValues = this.state.MultiSelectFieldTerms.map(trm => {
return trm.name + " - " + trm.key
}).join(' | ');
alert("Multi-select term Label and GUID : \n" + multiSelectValues);
}
}
}

View File

@ -0,0 +1,340 @@
import * as React from 'react';
import { escape } from '@microsoft/sp-lodash-subset';
import { taxonomy, ITermStore, ITermSet, ITerms, ITerm, ITermData, ITermStoreData} from "@pnp/sp-taxonomy";
// Office ui fabric react controls
import { TagPicker, ITag } from 'office-ui-fabric-react/lib/components/pickers/TagPicker/TagPicker';
import { DefaultButton, IButtonProps, Button, ActionButton } from 'office-ui-fabric-react/lib/Button';
import { Panel, PanelType } from 'office-ui-fabric-react/lib/Panel';
import { Label } from 'office-ui-fabric-react/lib/Label';
import { ChoiceGroup, IChoiceGroupOption } from 'office-ui-fabric-react/lib/ChoiceGroup';
import { TextField } from 'office-ui-fabric-react/lib/TextField';
// Represents a taxonomy term.
export interface ITaxonomyTerm{
name:string;
key:string;
}
// Represents the properties of the term picker component.
export interface ITermPickerProps{
IsMultiValue:boolean;
TermSetId:string;
LabelText:string;
SelectedTerms:any[]
}
// Represents the local state of the term picker component.
export interface ISelectTermsState{
TaxonomyTerms:ITaxonomyTerm[];
showPanel:boolean;
SelectedChoiceGroupTerm:ITaxonomyTerm;
SelectedTerms:any[];
PickerText:string;
}
let taxonomyOptions:IChoiceGroupOption[] = [];
export default class TermsPickerComponent extends React.Component<ITermPickerProps, ISelectTermsState> {
constructor(props, state:ISelectTermsState){
super(props);
let initialTaxonomyTermsArray:ITaxonomyTerm[] = [];
this.state = {
TaxonomyTerms:initialTaxonomyTermsArray,
showPanel:false,
SelectedChoiceGroupTerm:{name:null,key:null},
SelectedTerms:[],
PickerText:"",
}
}
// Creates the choice group to be displayed in the pciker panel.
public createTaxonomyChoiceGroup(){
taxonomyOptions = [];
if(this.state.TaxonomyTerms.length > 0){
this.state.TaxonomyTerms.forEach(trm=>{
taxonomyOptions.push(
{
key:trm.key,
text:trm.name
}
)
})
}
}
public render(): React.ReactElement<ITermPickerProps> {
this.createTaxonomyChoiceGroup();
return (
<div>
<div className="ms-Grid">
<div className="ms-Grid-row">
<div className="ms-Grid-col ms-sm12 ms-lg12">
<Label>{this.props.LabelText}</Label>
</div>
</div>
<div className="ms-Grid-row">
<div className="ms-Grid-col ms-sm8 ms-lg8">
<TagPicker
onResolveSuggestions={this._onFilterChanged.bind(this)}
selectedItems={this.state.SelectedTerms}
getTextFromItem={this._getTextFromItem.bind(this)}
itemLimit={this.props.IsMultiValue ? 100 : 1}
disabled={true}
/>
</div>
<div className="ms-Grid-col ms-sm4 ms-lg4">
<ActionButton
primary={true}
onClick={this._onShowPanel.bind(this)}
iconProps={{ iconName: 'MultiSelectMirrored' }}
/>
</div>
</div>
</div>
<Panel
isOpen={this.state.showPanel}
type={PanelType.smallFixedFar}
onDismiss={this._handlePanelDismiss.bind(this)}
headerText="Select terms"
closeButtonAriaLabel="Close"
>
<div style={this.state.TaxonomyTerms.length == 0 ? {display:"none"} : {}}>
<ChoiceGroup
options={taxonomyOptions}
onChange={this._onTaxonomyChoiceChange.bind(this)}
required={true}
selectedKey={this.state.SelectedChoiceGroupTerm.key}
/>
<br/>
<DefaultButton
primary={true}
text="Select"
onClick={this._handleSelectedTaxonomyTerm.bind(this)}
/>
<br/>
<br/>
<TextField label="Selected tags : " value={this.state.PickerText} multiline rows={4} onChanged={this._handlePickerTextChange.bind(this)}/>
<br/>
<br/>
<DefaultButton
primary={true}
text="Done"
onClick={this._handlePickerDone.bind(this)}
/>
</div>
<div style={this.state.TaxonomyTerms.length == 0 ? {} : {display:"none"}}>
<Label>No terms available....</Label>
</div>
</Panel>
</div>
);
}
// Component did mount - fetches the available terms from the term set.
// If existing terms are passed to the component through the 'SelectedTerms' property, it resolves
// the terms from the available set and adds them to the local state.
public componentDidMount(){
this.GetTerms().then(resp => {
let setSelectedTerms : ITaxonomyTerm[] = [];
if(this.props.SelectedTerms.length > 0 && this.state.TaxonomyTerms.length > 0){
this.props.SelectedTerms.forEach(selectedTrm => {
// Checks if the selected terms that was send as a property is valid (ie present in the available terms from termstore)
var checkForExistingValidTerm = this.state.TaxonomyTerms.filter(trm => {
return (trm.name.toLowerCase() === selectedTrm.name.toLowerCase() && trm.key === selectedTrm.key)
})
// If valid, add it to the selected terms of LOCAL STATE
if(checkForExistingValidTerm.length > 0){
setSelectedTerms.push(selectedTrm);
}
})
}
this.setState({
SelectedTerms:setSelectedTerms,
PickerText:this._getPickerTextString(setSelectedTerms)
})
})
}
// Fetches the terms from the term set and sets the TaxonomyTerms (available terms) in the local state.
public async GetTerms():Promise<any>{
try{
const store: ITermStore = await taxonomy.termStores.getByName("<TERM_STORE_NAME>");
const setWithData = await store.getTermSetById(this.props.TermSetId);
const terms = await setWithData.terms.get();
let taxonomyTerms:ITaxonomyTerm[] = new Array();
if(terms.length > 0){
terms.forEach(trm => {
taxonomyTerms.push({
name:trm.Name,
key:trm.Id.split('(')[1].replace(')/','')
})
});
this.setState({
TaxonomyTerms:taxonomyTerms
})
}
}
catch(error){
console.log("An error occurred while fetching the terms from the term store....");
}
return "";
}
public _onShowPanel(){
this.setState({ showPanel:true })
}
// This method is called when the panel is dismissed. So on the "DONE" button click,
// this method is automatically called. Also on the 'X' button click.
// On DONE button click in the picker panel, we only set the showPanel value to false.
private _handlePanelDismiss(){
// Push the data into component property.
if(this.state.SelectedTerms.length > 0){
this.props.SelectedTerms.length = 0;
this.state.SelectedTerms.forEach(trm => {
this.props.SelectedTerms.push(trm);
})
}
// Reset the picker text in case it was modified by the user manually.
// The next time it is opened, it will show the text of the selected terms.
this.setState({
PickerText:this._getPickerTextString(this.state.SelectedTerms),
})
}
private _onFilterChanged = (filterText: string,tagList: {key: string; name: string }[]): {key: string; name: string }[] => {
return filterText ? this.state.TaxonomyTerms.filter(tag => tag.name.toLowerCase().indexOf(filterText.toLowerCase()) === 0) : [];
};
public _getTextFromItem(item:any):any{
return item.Text;
}
// Sets the selected term on change of term in the picker panel.
private _onTaxonomyChoiceChange = (ev: React.FormEvent<HTMLInputElement>, option: any): void => {
this.setState({
SelectedChoiceGroupTerm:{ name:option.text, key:option.key }
})
}
private _handleSelectedTaxonomyTerm = (): void => {
let selectedTerms:ITaxonomyTerm[] = this.state.SelectedTerms;
// Handles the state and picker textbox if the field is multi-select
if(this.props.IsMultiValue){
selectedTerms = this.state.SelectedTerms;
// Check if the term is already selected
let existingTerm = selectedTerms.filter(trm => {
return trm.name.toLowerCase() === this.state.SelectedChoiceGroupTerm.name.toLowerCase()
})
if(existingTerm.length == 0){
selectedTerms.push(
{
name:this.state.SelectedChoiceGroupTerm.name,
key:this.state.SelectedChoiceGroupTerm.key
}
);
}
this.setState({
SelectedTerms:selectedTerms,
PickerText:this._getPickerTextString(this.state.SelectedTerms)
})
}
// Handles the state and picker textbox if the field is single-select
else{
selectedTerms = [];
selectedTerms.push(
{
name:this.state.SelectedChoiceGroupTerm.name,
key:this.state.SelectedChoiceGroupTerm.key
}
);
this.setState({
SelectedTerms:selectedTerms,
PickerText:selectedTerms[0].name
})
}
}
// Handle the close panel on "Done" button click
// When the showPanel is set to false, the onDismiss method will be automatically executed.
private _handlePickerDone = (): void => {
this.setState({
showPanel:false
})
}
// Generates the ';' separated string for selected terms
private _getPickerTextString(selectedTerms:any[]):string{
let pickerTextString:string = "";
if(selectedTerms.length > 0){
pickerTextString = selectedTerms.map(trm => {
return trm.name
}).join('; ')
}
return pickerTextString;
}
// Handles manual change to the picker control.
private _handlePickerTextChange(value){
if(value !== ""){
let selectedTerms:any[] = [];
let pickerSelectedTerms:any[] = value.split(';');
pickerSelectedTerms.forEach((pickerSelectedTerm:string) => {
pickerSelectedTerm = pickerSelectedTerm.trim();
let filteredTerm = this.state.TaxonomyTerms.filter((trm)=>{
return trm.name.toLowerCase() == pickerSelectedTerm.toLowerCase()
})
// Push the term only if it resolved.
if(filteredTerm.length > 0){
selectedTerms.push(filteredTerm[0]);
}
})
this.setState({
PickerText:value,
SelectedTerms:selectedTerms
})
}
else{
this.setState({
PickerText:value,
SelectedTerms:[]
})
}
}
}

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 IReactTaxonomypickerPanelWebPartStrings {
PropertyPaneDescription: string;
BasicGroupName: string;
DescriptionFieldLabel: string;
}
declare module 'ReactTaxonomypickerPanelWebPartStrings' {
const strings: IReactTaxonomypickerPanelWebPartStrings;
export = strings;
}

View File

@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"jsx": "react",
"declaration": true,
"sourceMap": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"typeRoots": [
"./node_modules/@types",
"./node_modules/@microsoft"
],
"types": [
"es6-promise",
"webpack-env"
],
"lib": [
"es5",
"dom",
"es2015.collection"
]
}
}