Skip to content

Commit 62609d0

Browse files
committed
Enhancement #82
1 parent 3b6a60b commit 62609d0

File tree

10 files changed

+68
-27
lines changed

10 files changed

+68
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Releases
22

3+
## 1.5.0
4+
5+
**Enhancements**
6+
7+
- Added a property to the `TaxonomyPicker` to specify which terms are disabled/not-selectable [#82](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/82)
8+
39
## 1.4.0
410

511
**New Controls**

docs/documentation/docs/about/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Releases
22

3+
## 1.5.0
4+
5+
**Enhancements**
6+
7+
- Added a property to the `TaxonomyPicker` to specify which terms are disabled/not-selectable [#82](https://github.com/SharePoint/sp-dev-fx-controls-react/issues/82)
8+
39
## 1.4.0
410

511
**New Controls**

docs/documentation/docs/controls/TaxonomyPicker.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ The TaxonomyPicker control can be configured with the following properties:
6868
| termsetNameOrID | string | yes | The name or Id of your TermSet that you would like the Taxonomy Picker to chose terms from. |
6969
| onChange | function | no | captures the event of when the terms in the picker has changed. |
7070
| isTermSetSelectable | boolean | no | Specify if the TermSet itself is selectable in the tree view. |
71+
| disabledTermIds | string[] | no | Specify which terms should be disabled in the term set so that they cannot be selected. |
7172
| anchorId | string | no | Set the anchorid to a child term in the TermSet to be able to select terms from that level and below. |
7273

7374
Interface `IPickerTerm`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pnp/spfx-controls-react",
33
"description": "Reusable React controls for SharePoint Framework solutions",
4-
"version": "1.4.0",
4+
"version": "1.5.0",
55
"engines": {
66
"node": ">=0.10.0"
77
},

src/controls/taxonomyPicker/ITaxonomyPicker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export interface ITaxonomyPickerProps {
4040
* Specify if the term set itself is selectable in the tree view
4141
*/
4242
isTermSetSelectable?: boolean;
43+
/**
44+
* Specify which terms should be disabled in the term set so that they cannot be selected
45+
*/
46+
disabledTermIds?: string[];
4347
/**
4448
* Whether the property pane field is enabled or not.
4549
*/
@@ -80,6 +84,7 @@ export interface ITaxonomyPickerState {
8084
export interface ITermChanges {
8185
changedCallback: (term: ITerm, checked: boolean) => void;
8286
activeNodes?: IPickerTerms;
87+
disabledTermIds?: string[];
8388
}
8489

8590

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import * as React from 'react';
2-
import { IWebPartContext } from '@microsoft/sp-webpart-base';
3-
import { PrimaryButton, DefaultButton, IconButton, IButtonProps } from 'office-ui-fabric-react/lib/Button';
2+
import { PrimaryButton, DefaultButton, IconButton } from 'office-ui-fabric-react/lib/Button';
43
import { Panel, PanelType } from 'office-ui-fabric-react/lib/Panel';
54
import { Spinner, SpinnerType } from 'office-ui-fabric-react/lib/Spinner';
6-
import { SPHttpClient, SPHttpClientResponse, ISPHttpClientOptions } from '@microsoft/sp-http';
75
import { Label } from 'office-ui-fabric-react/lib/Label';
86
import TermPicker from './TermPicker';
9-
import { BasePicker, IBasePickerProps, IPickerItemProps } from 'office-ui-fabric-react/lib/Pickers';
107
import { IPickerTerms, IPickerTerm } from './ITermPicker';
11-
import { ITaxonomyPickerProps, ITaxonomyPickerState, ITermParentProps, ITermParentState, ITermProps, ITermState } from './ITaxonomyPicker';
8+
import { ITaxonomyPickerProps, ITaxonomyPickerState } from './ITaxonomyPicker';
129
import SPTermStorePickerService from './../../services/SPTermStorePickerService';
1310
import { ITermSet, IGroup, ITerm } from './../../services/ISPTermStorePickerService';
1411
import styles from './TaxonomyPicker.module.scss';
@@ -31,7 +28,6 @@ export const TERM_IMG = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQC
3128
* Renders the controls for PropertyFieldTermPicker component
3229
*/
3330
export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxonomyPickerState> {
34-
private delayedValidate: (value: IPickerTerms) => void;
3531
private termsService: SPTermStorePickerService;
3632
private previousValues: IPickerTerms = [];
3733
private cancel: boolean = true;
@@ -244,7 +240,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
244240
isTermSetSelectable={this.props.isTermSetSelectable}
245241
onChanged={this.termsFromPickerChanged}
246242
allowMultipleSelections={this.props.allowMultipleSelections}
247-
/>
243+
disabledTermIds={this.props.disabledTermIds} />
248244
</td>
249245
<td className={styles.termFieldRow}>
250246
<IconButton disabled={this.props.disabled} iconProps={{ iconName: 'Tag' }} onClick={this.onOpenPanel} />
@@ -286,6 +282,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
286282
isTermSetSelectable={this.props.isTermSetSelectable}
287283
termSetSelectedChange={this.termSetSelectedChange}
288284
activeNodes={this.state.activeNodes}
285+
disabledTermIds={this.props.disabledTermIds}
289286
changedCallback={this.termsChanged}
290287
multiSelection={this.props.allowMultipleSelections} />
291288
</div>

src/controls/taxonomyPicker/Term.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,22 @@ export default class Term extends React.Component<ITermProps, ITermState> {
4848
}
4949
}
5050

51+
/**
52+
* Check if the current term needs to be disabled
53+
*/
54+
private checkIfTermIsDisabled(): boolean {
55+
// Check if disabled term IDs are provided
56+
if (this.props.disabledTermIds && this.props.disabledTermIds.length > 0) {
57+
// Check if the current term ID exists in the disabled term IDs array
58+
return this.props.disabledTermIds.indexOf(this.props.term.Id) !== -1;
59+
}
5160

61+
return false;
62+
}
63+
64+
/**
65+
* Default React render
66+
*/
5267
public render(): JSX.Element {
5368
const styleProps: React.CSSProperties = {
5469
marginLeft: `${(this.props.term.PathDepth * 30)}px`
@@ -58,7 +73,7 @@ export default class Term extends React.Component<ITermProps, ITermState> {
5873
<div className={`${styles.listItem} ${styles.term}`} style={styleProps}>
5974
<Checkbox
6075
checked={this.state.selected}
61-
disabled={this.props.term.IsDeprecated}
76+
disabled={this.props.term.IsDeprecated || this.checkIfTermIsDisabled()}
6277
className={this.props.term.IsDeprecated ? styles.termDisabled : styles.termEnabled}
6378
label={this.props.term.Name}
6479
onChange={this._handleChange} />

src/controls/taxonomyPicker/TermParent.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,35 @@ export default class TermParent extends React.Component<ITermParentProps, ITermP
7373
}
7474

7575

76+
/**
77+
* Default React render method
78+
*/
7679
public render(): JSX.Element {
7780
// Specify the inline styling to show or hide the termsets
7881
const styleProps: React.CSSProperties = {
7982
display: this.state.expanded ? 'block' : 'none'
8083
};
8184

8285
let termElm: JSX.Element = <div />;
83-
// Check if the terms have been loaded
8486

85-
if (this.state.loaded) {
86-
if (this._terms.length > 0) {
87-
termElm = (
88-
<div style={styleProps}>
89-
{
90-
this._terms.map(term => {
91-
return <Term key={term.Id} term={term} termset={this.props.termset.Id} activeNodes={this.props.activeNodes} changedCallback={this.props.changedCallback} multiSelection={this.props.multiSelection} />;
92-
})
93-
}
94-
</div>
95-
);
96-
} else {
97-
termElm = <div className={`${styles.listItem} ${styles.term}`}>{strings.TaxonomyPickerNoTerms}</div>;
98-
}
87+
// Check if the terms have been loaded
88+
if (this.state.loaded) {
89+
if (this._terms.length > 0) {
90+
termElm = (
91+
<div style={styleProps}>
92+
{
93+
this._terms.map(term => {
94+
return <Term key={term.Id} term={term} termset={this.props.termset.Id} activeNodes={this.props.activeNodes} changedCallback={this.props.changedCallback} multiSelection={this.props.multiSelection} disabledTermIds={this.props.disabledTermIds} />;
95+
})
96+
}
97+
</div>
98+
);
9999
} else {
100-
termElm = <Spinner type={SpinnerType.normal} />;
100+
termElm = <div className={`${styles.listItem} ${styles.term}`}>{strings.TaxonomyPickerNoTerms}</div>;
101101
}
102+
} else {
103+
termElm = <Spinner type={SpinnerType.normal} />;
104+
}
102105

103106

104107
return (

src/controls/taxonomyPicker/TermPicker.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export interface ITermPickerProps {
2525
value: IPickerTerms;
2626
allowMultipleSelections : boolean;
2727
isTermSetSelectable?: boolean;
28+
disabledTermIds?: string[];
29+
2830
onChanged: (items: IPickerTerm[]) => void;
2931
}
3032

@@ -83,7 +85,7 @@ export default class TermPicker extends React.Component<ITermPickerProps, ITermP
8385
/**
8486
* Renders the suggestions in the picker
8587
*/
86-
protected onRenderSuggestionsItem(term: IPickerTerm, props) {
88+
protected onRenderSuggestionsItem(term: IPickerTerm) {
8789
let termParent = term.termSetName;
8890
let termTitle = `${term.name} [${term.termSetName}]`;
8991
if (term.path.indexOf(";") !== -1) {
@@ -125,6 +127,11 @@ export default class TermPicker extends React.Component<ITermPickerProps, ITermP
125127
// Filter out the terms which are already set
126128
const filteredTerms = [];
127129
for (const term of terms) {
130+
// Check if term is not disabled
131+
if (this.props.disabledTermIds && this.props.disabledTermIds.length > 0 && this.props.disabledTermIds.indexOf(term.key) !== -1) {
132+
break;
133+
}
134+
// Only retrieve the terms which are not yet tagged
128135
if (tagList.filter(tag => tag.key === term.key).length === 0) {
129136
filteredTerms.push(term);
130137
}

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
221221
<div className="ms-font-m">TaxonomyPicker tester:
222222
<TaxonomyPicker
223223
allowMultipleSelections={true}
224-
termsetNameOrID="8ed8c9ea-7052-4c1d-a4d7-b9c10bffea6f"
224+
termsetNameOrID="b3e9b754-2593-4ae6-abc2-35345402e186"
225225
// anchorId="0ec2f948-3978-499e-9d3f-e51c4494d44c"
226+
disabledTermIds={["943fd9f0-3d7c-415c-9192-93c0e54573fb", "0e415292-cce5-44ac-87c7-ef99dd1f01f4"]}
226227
panelTitle="Select Term"
227228
label="Taxonomy Picker"
228229
context={this.props.context}

0 commit comments

Comments
 (0)