Skip to content

Commit 6103acd

Browse files
author
Jonas Bjerke Hansen
committed
Extended TaxonomyPicker with the ability to hide deprecated terms and those that are not available for tagging (Issue: 421)
1 parent bc3baf5 commit 6103acd

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

src/controls/taxonomyPicker/ITaxonomyPicker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ export interface ITaxonomyPickerProps {
6464
*/
6565
termActions?: ITermActions;
6666

67+
/**
68+
* Specifies if the tags marked with 'Available for tagging' = false should be hidden
69+
*/
70+
hideTagsNotAvailableForTagging?: boolean;
71+
72+
/**
73+
* Specifies if deprecated tags should be hidden
74+
*/
75+
hideDeprecatedTags?: boolean;
76+
6777
/**
6878
* The method is used to get the validation error message and determine whether the input value is valid or not.
6979
*

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
9090
// });
9191
}
9292

93-
this.termsService.getAllTerms(this.props.termsetNameOrID).then((response: ITermSet) => {
93+
this.termsService.getAllTerms(this.props.termsetNameOrID, this.props.hideDeprecatedTags, this.props.hideTagsNotAvailableForTagging).then((response: ITermSet) => {
9494
// Check if a response was retrieved
9595
let termSetAndTerms = response ? response : null;
9696
this.setState({
@@ -104,7 +104,7 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
104104
* Force update of the taxonomy tree - required by term action in case the term has been added, deleted or moved.
105105
*/
106106
private async updateTaxonomyTree(): Promise<void> {
107-
const termSetAndTerms = await this.termsService.getAllTerms(this.props.termsetNameOrID);
107+
const termSetAndTerms = await this.termsService.getAllTerms(this.props.termsetNameOrID, this.props.hideDeprecatedTags, this.props.hideTagsNotAvailableForTagging);
108108

109109
this.setState({
110110
termSetAndTerms

src/services/SPTermStorePickerService.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export default class SPTermStorePickerService {
146146
* Retrieve all terms for the given term set
147147
* @param termset
148148
*/
149-
public async getAllTerms(termset: string): Promise<ITermSet> {
149+
public async getAllTerms(termset: string, hideDeprecatedTags?: boolean, hideTagsNotAvailableForTagging?: boolean): Promise<ITermSet> {
150150
if (Environment.type === EnvironmentType.Local) {
151151
// If the running environment is local, load the data from the mock
152152
return this.getAllMockTerms();
@@ -190,6 +190,17 @@ export default class SPTermStorePickerService {
190190
if (termStoreResultTerms.length > 0) {
191191
// Retrieve all terms
192192
let terms = termStoreResultTerms[0]._Child_Items_;
193+
194+
if(hideDeprecatedTags === true)
195+
{
196+
terms = terms.filter(d => d["IsDeprecated"] === false);
197+
}
198+
199+
if(hideTagsNotAvailableForTagging === true)
200+
{
201+
terms = terms.filter(d => d["IsAvailableForTagging"] === true);
202+
}
203+
193204
// Clean the term ID and specify the path depth
194205
terms = terms.map(term => {
195206
if (term.IsRoot) {

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
754754
<TaxonomyPicker
755755
initialValues={this.state.initialValues}
756756
allowMultipleSelections={true}
757-
termsetNameOrID="b3e9b754-2593-4ae6-abc2-35345402e186"
757+
termsetNameOrID="313362ca-6813-4433-bcce-7bf74a18b9cb"
758758
// anchorId="0ec2f948-3978-499e-9d3f-e51c4494d44c"
759759
// disabledTermIds={["943fd9f0-3d7c-415c-9192-93c0e54573fb", "0e415292-cce5-44ac-87c7-ef99dd1f01f4"]}
760760
// disabledTermIds={["943fd9f0-3d7c-415c-9192-93c0e54573fb", "73d18756-20af-41de-808c-2a1e21851e44", "0e415292-cce5-44ac-87c7-ef99dd1f01f4"]}
@@ -764,7 +764,9 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
764764
label="Taxonomy Picker"
765765
context={this.props.context}
766766
onChange={this._onTaxPickerChange}
767-
isTermSetSelectable={false} />
767+
isTermSetSelectable={false}
768+
hideDeprecatedTags={true}
769+
hideTagsNotAvailableForTagging={true} />
768770

769771
<DefaultButton text="Add" onClick={() => {
770772
this.setState({

0 commit comments

Comments
 (0)