Skip to content

Commit d552081

Browse files
committed
#578 - TaxonomyPicker enhancements
1 parent 2ee1c1d commit d552081

File tree

9 files changed

+162
-14
lines changed

9 files changed

+162
-14
lines changed

CHANGELOG.JSON

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"`FolderExplorer`: Add clear button to filter text box [#553](https://github.com/pnp/sp-dev-fx-controls-react/pull/553)",
1111
"`TreeView`: there should be possibility to collapse the first level nodes by default [#561](https://github.com/pnp/sp-dev-fx-controls-react/issues/561)",
1212
"`TreeView`: Expand to selected [#559](https://github.com/pnp/sp-dev-fx-controls-react/issues/559)",
13-
"`DateTimePicker`: When using the datetimePicker I would like to have an opportunity to set maximum/minimum date like in Office UI Fabric [497](https://github.com/pnp/sp-dev-fx-controls-react/issues/497)"
13+
"`DateTimePicker`: When using the datetimePicker I would like to have an opportunity to set maximum/minimum date like in Office UI Fabric [#497](https://github.com/pnp/sp-dev-fx-controls-react/issues/497)",
14+
"`TaxonomyPicker`: Added the `hideTerm` and `disableTerm` actions [#578](https://github.com/pnp/sp-dev-fx-controls-react/issues/578)"
1415
],
1516
"fixes": [
1617
"`TaxonomyPicker`: Correct the AnchorID getting all TermSet search options [#150](https://github.com/pnp/sp-dev-fx-controls-react/issues/150)",

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
- `FolderExplorer`: Add clear button to filter text box [#553](https://github.com/pnp/sp-dev-fx-controls-react/pull/553)
99
- `TreeView`: there should be possibility to collapse the first level nodes by default [#561](https://github.com/pnp/sp-dev-fx-controls-react/issues/561)
1010
- `TreeView`: Expand to selected [#559](https://github.com/pnp/sp-dev-fx-controls-react/issues/559)
11-
- `DateTimePicker`: When using the datetimePicker I would like to have an opportunity to set maximum/minimum date like in Office UI Fabric [497](https://github.com/pnp/sp-dev-fx-controls-react/issues/497)
11+
- `DateTimePicker`: When using the datetimePicker I would like to have an opportunity to set maximum/minimum date like in Office UI Fabric [#497](https://github.com/pnp/sp-dev-fx-controls-react/issues/497)
12+
- `TaxonomyPicker`: Added the `hideTerm` and `disableTerm` actions [#578](https://github.com/pnp/sp-dev-fx-controls-react/issues/578)
1213

1314
### Fixes
1415

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
- `FolderExplorer`: Add clear button to filter text box [#553](https://github.com/pnp/sp-dev-fx-controls-react/pull/553)
99
- `TreeView`: there should be possibility to collapse the first level nodes by default [#561](https://github.com/pnp/sp-dev-fx-controls-react/issues/561)
1010
- `TreeView`: Expand to selected [#559](https://github.com/pnp/sp-dev-fx-controls-react/issues/559)
11-
- `DateTimePicker`: When using the datetimePicker I would like to have an opportunity to set maximum/minimum date like in Office UI Fabric [497](https://github.com/pnp/sp-dev-fx-controls-react/issues/497)
11+
- `DateTimePicker`: When using the datetimePicker I would like to have an opportunity to set maximum/minimum date like in Office UI Fabric [#497](https://github.com/pnp/sp-dev-fx-controls-react/issues/497)
12+
- `TaxonomyPicker`: Added the `hideTerm` and `disableTerm` actions [#578](https://github.com/pnp/sp-dev-fx-controls-react/issues/578)
1213

1314
### Fixes
1415

docs/documentation/docs/controls/TaxonomyPicker.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { TaxonomyPicker, IPickerTerms } from "@pnp/spfx-controls-react/lib/Taxon
4747

4848
```typescript
4949
private onTaxPickerChange(terms : IPickerTerms) {
50-
console.log("Terms", terms);
50+
console.log("Terms", terms);
5151
}
5252
```
5353

@@ -65,16 +65,64 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones
6565
isTermSetSelectable={false}
6666
termActions={{
6767
actions: [{
68-
title: "Update term label",
68+
title: "Get term labels",
6969
iconName: "LocaleLanguage",
70-
id: "UpdateTermLabel",
70+
id: "test",
71+
invokeActionOnRender: true,
72+
hidden: true,
7173
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
74+
console.log(term.Name, term.TermsCount);
7275
return {
7376
updateActionType: UpdateType.updateTermLabel,
7477
value: `${term.Name} (updated)`
7578
};
7679
},
77-
applyToTerm: (term: ITerm) => (true) // Applying the action to all terms
80+
applyToTerm: (term: ITerm) => (term && term.Name && term.Name === "internal")
81+
},
82+
{
83+
title: "Hide term",
84+
id: "hideTerm",
85+
invokeActionOnRender: true,
86+
hidden: true,
87+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
88+
return {
89+
updateActionType: UpdateType.hideTerm,
90+
value: true
91+
};
92+
},
93+
applyToTerm: (term: ITerm) => (term && term.Name && (term.Name.toLowerCase() === "help desk" || term.Name.toLowerCase() === "multi-column valo site page"))
94+
},
95+
{
96+
title: "Disable term",
97+
id: "disableTerm",
98+
invokeActionOnRender: true,
99+
hidden: true,
100+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
101+
return {
102+
updateActionType: UpdateType.disableTerm,
103+
value: true
104+
};
105+
},
106+
applyToTerm: (term: ITerm) => (term && term.Name && term.Name.toLowerCase() === "secured")
107+
},
108+
{
109+
title: "Disable or hide term",
110+
id: "disableOrHideTerm",
111+
invokeActionOnRender: true,
112+
hidden: true,
113+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
114+
if (term.TermsCount > 0) {
115+
return {
116+
updateActionType: UpdateType.disableTerm,
117+
value: true
118+
};
119+
}
120+
return {
121+
updateActionType: UpdateType.hideTerm,
122+
value: true
123+
};
124+
},
125+
applyToTerm: (term: ITerm) => true
78126
}]
79127
}} />
80128
```
@@ -160,13 +208,15 @@ Interface `UpdateAction`
160208
| Property | Type | Required | Description |
161209
| ---- | ---- | ---- | ---- |
162210
| updateActionType | UpdateType | yes | Defines the type of update you want to perform |
163-
| value | string | no | New term label value to update. Only required when you want to update the term |
211+
| value | string \| boolean | no | When `updateTermLabel` is used, it should return a string. When `hideTerm` or `disableTerm` are used, you should return a boolean. |
164212

165213
Enum `UpdateType`
166214

167215
| Value |
168216
| ---- |
169217
| updateTermLabel |
170218
| updateTermsTree |
219+
| hideTerm |
220+
| disableTerm |
171221

172222
![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/Placeholder)

src/controls/taxonomyPicker/ITaxonomyPicker.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,6 @@ export interface ITermProps extends ITermChanges {
152152
export interface ITermState {
153153
selected?: boolean;
154154
termLabel: string;
155+
hidden?: boolean;
156+
disabled?: boolean;
155157
}

src/controls/taxonomyPicker/Term.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export default class Term extends React.Component<ITermProps, ITermState> {
2121

2222
this.state = {
2323
selected: active.length > 0,
24-
termLabel: this.props.term.Name
24+
termLabel: this.props.term.Name,
25+
hidden: false,
26+
disabled: false
2527
};
2628

2729
this._handleChange = this._handleChange.bind(this);
@@ -75,7 +77,15 @@ export default class Term extends React.Component<ITermProps, ITermState> {
7577

7678
if (updateAction.updateActionType === UpdateType.updateTermLabel) {
7779
this.setState({
78-
termLabel: updateAction.value
80+
termLabel: updateAction.value as string
81+
});
82+
} else if (updateAction.updateActionType === UpdateType.hideTerm) {
83+
this.setState({
84+
hidden: updateAction.value as boolean
85+
});
86+
} else if (updateAction.updateActionType === UpdateType.disableTerm) {
87+
this.setState({
88+
disabled: updateAction.value as boolean
7989
});
8090
} else {
8191
this.props.updateTaxonomyTree();
@@ -93,14 +103,18 @@ export default class Term extends React.Component<ITermProps, ITermState> {
93103
display: "inline-flex"
94104
};
95105

106+
if (this.state.hidden) {
107+
return null;
108+
}
109+
96110
return (
97111
<div>
98112
<div className={`${styles.listItem} ${styles.term}`} style={styleProps}>
99113
<div>
100114
<Checkbox
101115
checked={this.state.selected}
102116
style={checkBoxStyle}
103-
disabled={this.props.term.IsDeprecated || !this.props.term.IsAvailableForTagging || this.props.disabled}
117+
disabled={this.props.term.IsDeprecated || !this.props.term.IsAvailableForTagging || this.props.disabled || this.state.disabled}
104118
className={this.getClassName()}
105119
label={this.state.termLabel}
106120
onChange={this._handleChange} />

src/controls/taxonomyPicker/termActions/ITermsActions.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,29 @@ export enum TermActionsDisplayStyle {
6464
* Specifies the action that should be applied after executing the action callback.
6565
*/
6666
export enum UpdateType {
67+
/**
68+
* Allows you to update the label of the term
69+
*/
6770
updateTermLabel = 1,
68-
updateTermsTree
71+
/**
72+
* Allows you to update part of the taxonomy tree
73+
*/
74+
updateTermsTree,
75+
/**
76+
* Allows you to hide the term
77+
*/
78+
hideTerm,
79+
/**
80+
* Allows you to disable the term
81+
*/
82+
disableTerm
6983
}
7084
/**
7185
* Specifies the result that will be returned to the Term after the execution of the callback.
7286
*/
7387
export interface UpdateAction {
7488
updateActionType: UpdateType;
75-
value?: string;
89+
value?: string | boolean;
7690
}
7791

7892
export interface ITermActions {

src/services/ISPTermStorePickerService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface ITerm {
7575
CustomSortOrderIndex?: number;
7676
PathDepth?: number;
7777
ParentId?: string;
78+
TermsCount?: number;
7879
LocalCustomProperties?: {
7980
[property: string]: any
8081
};

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,71 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
665665
onChange={this._onTaxPickerChange}
666666
isTermSetSelectable={false}
667667
hideDeprecatedTags={true}
668-
hideTagsNotAvailableForTagging={true} />
668+
hideTagsNotAvailableForTagging={true}
669+
termActions={{
670+
actions: [{
671+
title: "Get term labels",
672+
iconName: "LocaleLanguage",
673+
id: "test",
674+
invokeActionOnRender: true,
675+
hidden: true,
676+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
677+
console.log(term.Name, term.TermsCount);
678+
return {
679+
updateActionType: UpdateType.updateTermLabel,
680+
value: `${term.Name} (updated)`
681+
};
682+
},
683+
applyToTerm: (term: ITerm) => (term && term.Name && term.Name === "internal")
684+
},
685+
{
686+
title: "Hide term",
687+
id: "hideTerm",
688+
invokeActionOnRender: true,
689+
hidden: true,
690+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
691+
return {
692+
updateActionType: UpdateType.hideTerm,
693+
value: true
694+
};
695+
},
696+
applyToTerm: (term: ITerm) => (term && term.Name && (term.Name.toLowerCase() === "help desk" || term.Name.toLowerCase() === "multi-column valo site page"))
697+
},
698+
{
699+
title: "Disable term",
700+
id: "disableTerm",
701+
invokeActionOnRender: true,
702+
hidden: true,
703+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
704+
return {
705+
updateActionType: UpdateType.disableTerm,
706+
value: true
707+
};
708+
},
709+
applyToTerm: (term: ITerm) => (term && term.Name && term.Name.toLowerCase() === "secured")
710+
},
711+
{
712+
title: "Disable or hide term",
713+
id: "disableOrHideTerm",
714+
invokeActionOnRender: true,
715+
hidden: true,
716+
actionCallback: async (taxService: SPTermStorePickerService, term: ITerm) => {
717+
if (term.TermsCount > 0) {
718+
return {
719+
updateActionType: UpdateType.disableTerm,
720+
value: true
721+
};
722+
}
723+
return {
724+
updateActionType: UpdateType.hideTerm,
725+
value: true
726+
};
727+
},
728+
applyToTerm: (term: ITerm) => true
729+
}],
730+
termActionsDisplayMode: TermActionsDisplayMode.buttons,
731+
termActionsDisplayStyle: TermActionsDisplayStyle.textAndIcon
732+
}} />
669733

670734
<DefaultButton text="Add" onClick={() => {
671735
this.setState({

0 commit comments

Comments
 (0)