@@ -52,23 +52,53 @@ private onTaxPickerChange(terms : ITermInfo[]) {
52
52
```
53
53
54
54
## Advanced example
55
- Custom rendering of a More actions button that displays a context menu for each term in the term set and the term set itself and with different options for the terms and the term set. This could for example be used to add terms to an open term set. It also shows how to set the initialsValues property when just knowing the name and the id of the term, the rest of the term properties must be provided but doesn't need to be the correct values .
55
+ Custom rendering of a More actions button that displays a context menu for each term in the term set and the term set itself and with different options for the terms and the term set. This could for example be used to add terms to an open term set. It also shows how to set the initialsValues property when just knowing the name and the id of the term.
56
56
57
57
``` TypeScript
58
+ const termSetId = " 36d21c3f-b83b-4acc-a223-4df6fa8e946d" ;
59
+ const [clickedActionTerm, setClickedActionTerm] = React .useState <ITermInfo >();
60
+
61
+ const addChildTerm = (parentTermId , updateTaxonomyTreeViewCallback ): void => {
62
+ spPost (sp .termStore .sets .getById (termSetId ).terms .getById (parentTermId ).children , {
63
+ body: JSON .stringify ({
64
+ " labels" : [
65
+ {
66
+ " languageTag" : " en-US" ,
67
+ " name" : " Test" ,
68
+ " isDefault" : true
69
+ }
70
+ ]
71
+ }),
72
+ })
73
+ .then (addedTerm => {
74
+ return sp .termStore .sets .getById (termSetId ).terms .getById (addedTerm .id ).expand (" parent" )();
75
+ })
76
+ .then (term => {
77
+ updateTaxonomyTreeViewCallback ([term ], null , null );
78
+ });
79
+ }
80
+
81
+ ...
82
+
58
83
< ModernTaxonomyPicker
59
84
allowMultipleSelections = {true }
60
- termSetId = {" 36d21c3f-b83b-4acc-a223-4df6fa8e946d " }
85
+ termSetId = {termSetId }
61
86
panelTitle = " Panel title"
62
87
label = {" Field title" }
63
88
context = {this.props.context }
64
89
required = {false }
65
- initialValues = {[{labels: [{name: " Subprocess A1" , isDefault: true , languageTag: " en-US" }], id: " 29eced8f-cf08-454b-bd9e-6443bc0a0f5e" , childrenCount: 0 , createdDateTime: " " , lastModifiedDateTime: " " , descriptions: [], customSortOrder: [], properties: [], localProperties: [], isDeprecated: false , isAvailableForTagging: [], topicRequested: false }]}
90
+ initialValues = {[{labels: [{name: " Subprocess A1" , isDefault: true , languageTag: " en-US" }], id: " 29eced8f-cf08-454b-bd9e-6443bc0a0f5e" }]}
66
91
onChange={this.onTaxPickerChange}
67
92
disabled={false}
68
93
customPanelWidth={700}
69
94
isLightDismiss={false}
70
95
isBlocking={false}
71
- onRenderActionButton={(termStoreInfo: ITermStoreInfo , termSetInfo: ITermSetInfo , termInfo?: ITermInfo ): JSX .Element => {
96
+ onRenderActionButton={(
97
+ termStoreInfo: ITermStoreInfo ,
98
+ termSetInfo: ITermSetInfo ,
99
+ termInfo: ITermInfo
100
+ updateTaxonomyTreeViewCallback ?: (newTermItems ? : ITermInfo [], updatedTermItems ? : ITermInfo [], deletedTermItems ? : ITermInfo []) => void
101
+ ): JSX .Element => {
72
102
const menuIcon: IIconProps = { iconName: ' MoreVertical' , " aria-label" : " More actions" , style: { fontSize: " medium" } };
73
103
if (termInfo ) {
74
104
const menuProps: IContextualMenuProps = {
@@ -77,13 +107,13 @@ Custom rendering of a More actions button that displays a context menu for each
77
107
key: ' addTerm' ,
78
108
text: ' Add Term' ,
79
109
iconProps: { iconName: ' Tag' },
80
- onClick : () => onContextualMenuClick (termInfo .id )
110
+ onClick : () => addChildTerm (termInfo .id , updateTaxonomyTreeViewCallback )
81
111
},
82
112
{
83
113
key: ' deleteTerm' ,
84
114
text: ' Delete term' ,
85
115
iconProps: { iconName: ' Untag' },
86
- onClick : () => onContextualMenuClick (termInfo .id )
116
+ onClick : () => deleteTerm (termInfo .id , updateTaxonomyTreeViewCallback )
87
117
},
88
118
],
89
119
};
@@ -92,11 +122,11 @@ Custom rendering of a More actions button that displays a context menu for each
92
122
< IconButton
93
123
menuProps = {menuProps }
94
124
menuIconProps = {menuIcon }
95
- style = {this.state. clickedActionTerm && this.state. clickedActionTerm.id === termInfo .id ? {opacity: 1 } : null }
125
+ style = {clickedActionTerm && clickedActionTerm.id === termInfo .id ? {opacity: 1 } : null }
96
126
onMenuClick = {(ev?: React .MouseEvent < HTMLElement , MouseEvent> | React.KeyboardEvent<HTMLElement>, button?: IButtonProps ) => {
97
- this . setState ({clickedActionTerm: termInfo } );
127
+ setClickedActionTerm ( termInfo ) );
98
128
}}
99
- onAfterMenuDismiss = {() => this.setState({ clickedActionTerm : null } )}
129
+ onAfterMenuDismiss = {() => setClickedActionTerm( null )}
100
130
/ >
101
131
);
102
132
}
@@ -107,7 +137,7 @@ Custom rendering of a More actions button that displays a context menu for each
107
137
key: ' addTerm' ,
108
138
text: ' Add term' ,
109
139
iconProps: { iconName: ' Tag' },
110
- onClick : () => onContextualMenuClick ( termSetInfo .id )
140
+ onClick : () => addTerm ( termInfo .id , updateTaxonomyTreeViewCallback )
111
141
},
112
142
],
113
143
};
@@ -177,7 +207,7 @@ You can also use the `TaxonomyTree` control separately to just render a stand-al
177
207
}, []);
178
208
179
209
return (
180
- {currentTermSetInfo && (
210
+ {currentTermStoreInfo && currentTermSetInfo && currentLanguageTag && (
181
211
<TaxonomyTree
182
212
languageTag = {currentLanguageTag }
183
213
onLoadMoreData = {taxonomyService.getTerms }
0 commit comments