Skip to content

Commit 2cd1e75

Browse files
committed
#578 - Added selectTerm action for TaxonomyPicker
1 parent d552081 commit 2cd1e75

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

docs/documentation/docs/controls/TaxonomyPicker.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones
7777
value: `${term.Name} (updated)`
7878
};
7979
},
80-
applyToTerm: (term: ITerm) => (term && term.Name && term.Name === "internal")
80+
applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => (term && term.Name && term.Name === "internal")
8181
},
8282
{
8383
title: "Hide term",
@@ -90,7 +90,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones
9090
value: true
9191
};
9292
},
93-
applyToTerm: (term: ITerm) => (term && term.Name && (term.Name.toLowerCase() === "help desk" || term.Name.toLowerCase() === "multi-column valo site page"))
93+
applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => (term && term.Name && (term.Name.toLowerCase() === "help desk" || term.Name.toLowerCase() === "multi-column valo site page"))
9494
},
9595
{
9696
title: "Disable term",
@@ -103,7 +103,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones
103103
value: true
104104
};
105105
},
106-
applyToTerm: (term: ITerm) => (term && term.Name && term.Name.toLowerCase() === "secured")
106+
applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => (term && term.Name && term.Name.toLowerCase() === "secured")
107107
},
108108
{
109109
title: "Disable or hide term",
@@ -122,7 +122,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones
122122
value: true
123123
};
124124
},
125-
applyToTerm: (term: ITerm) => true
125+
applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => true
126126
}]
127127
}} />
128128
```
@@ -218,5 +218,6 @@ Enum `UpdateType`
218218
| updateTermsTree |
219219
| hideTerm |
220220
| disableTerm |
221+
| selectTerm |
221222

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

src/controls/taxonomyPicker/Term.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ export default class Term extends React.Component<ITermProps, ITermState> {
8787
this.setState({
8888
disabled: updateAction.value as boolean
8989
});
90+
} else if (updateAction.updateActionType === UpdateType.selectTerm) {
91+
this.setState({
92+
selected: updateAction.value as boolean
93+
});
94+
this.props.changedCallback(this.props.term, updateAction.value as boolean);
9095
} else {
9196
this.props.updateTaxonomyTree();
9297
}

src/controls/taxonomyPicker/termActions/ITermsActions.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ export enum UpdateType {
7979
/**
8080
* Allows you to disable the term
8181
*/
82-
disableTerm
82+
disableTerm,
83+
/**
84+
* Allows you to select the term
85+
*/
86+
selectTerm
8387
}
8488
/**
8589
* Specifies the result that will be returned to the Term after the execution of the callback.
@@ -128,7 +132,7 @@ export interface ITermAction {
128132
* Method checks if the current term is supported.
129133
* @param currentTerm
130134
*/
131-
applyToTerm: (currentTerm: ITerm) => Promise<boolean> | boolean;
135+
applyToTerm: (currentTerm: ITerm, triggerActionCallback: (updateAction: UpdateAction) => void) => Promise<boolean> | boolean;
132136
/**
133137
* Method to be executed when action is fired.
134138
*/

src/controls/taxonomyPicker/termActions/TermActionsControl.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class TermActionsControl extends React.Component<ITermActionsCont
3838

3939
if (termActions.actions) {
4040
for (const action of termActions.actions) {
41-
const available = await action.applyToTerm(term);
41+
const available = await action.applyToTerm(term, this.props.termActionCallback);
4242
if (available) {
4343
availableActions.push(action);
4444
}

0 commit comments

Comments
 (0)