From 2cd1e750f3782770eb439d1f8b0b2bc9c7c9884c Mon Sep 17 00:00:00 2001 From: Elio Struyf Date: Fri, 12 Jun 2020 14:45:00 +0200 Subject: [PATCH] #578 - Added selectTerm action for TaxonomyPicker --- docs/documentation/docs/controls/TaxonomyPicker.md | 9 +++++---- src/controls/taxonomyPicker/Term.tsx | 5 +++++ src/controls/taxonomyPicker/termActions/ITermsActions.ts | 8 ++++++-- .../taxonomyPicker/termActions/TermActionsControl.tsx | 2 +- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/documentation/docs/controls/TaxonomyPicker.md b/docs/documentation/docs/controls/TaxonomyPicker.md index 3d957b086..1bdd3622c 100644 --- a/docs/documentation/docs/controls/TaxonomyPicker.md +++ b/docs/documentation/docs/controls/TaxonomyPicker.md @@ -77,7 +77,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones value: `${term.Name} (updated)` }; }, - applyToTerm: (term: ITerm) => (term && term.Name && term.Name === "internal") + applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => (term && term.Name && term.Name === "internal") }, { title: "Hide term", @@ -90,7 +90,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones value: true }; }, - applyToTerm: (term: ITerm) => (term && term.Name && (term.Name.toLowerCase() === "help desk" || term.Name.toLowerCase() === "multi-column valo site page")) + applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => (term && term.Name && (term.Name.toLowerCase() === "help desk" || term.Name.toLowerCase() === "multi-column valo site page")) }, { title: "Disable term", @@ -103,7 +103,7 @@ Since version `1.12.0`, you can apply term actions to all terms or specific ones value: true }; }, - applyToTerm: (term: ITerm) => (term && term.Name && term.Name.toLowerCase() === "secured") + applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => (term && term.Name && term.Name.toLowerCase() === "secured") }, { 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 value: true }; }, - applyToTerm: (term: ITerm) => true + applyToTerm: (term: ITerm, triggerActionCb: (updateAction: UpdateAction) => void) => true }] }} /> ``` @@ -218,5 +218,6 @@ Enum `UpdateType` | updateTermsTree | | hideTerm | | disableTerm | +| selectTerm | ![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/Placeholder) diff --git a/src/controls/taxonomyPicker/Term.tsx b/src/controls/taxonomyPicker/Term.tsx index 27ab1ebf1..c8a95f996 100644 --- a/src/controls/taxonomyPicker/Term.tsx +++ b/src/controls/taxonomyPicker/Term.tsx @@ -87,6 +87,11 @@ export default class Term extends React.Component { this.setState({ disabled: updateAction.value as boolean }); + } else if (updateAction.updateActionType === UpdateType.selectTerm) { + this.setState({ + selected: updateAction.value as boolean + }); + this.props.changedCallback(this.props.term, updateAction.value as boolean); } else { this.props.updateTaxonomyTree(); } diff --git a/src/controls/taxonomyPicker/termActions/ITermsActions.ts b/src/controls/taxonomyPicker/termActions/ITermsActions.ts index 403b161fa..6b319caec 100644 --- a/src/controls/taxonomyPicker/termActions/ITermsActions.ts +++ b/src/controls/taxonomyPicker/termActions/ITermsActions.ts @@ -79,7 +79,11 @@ export enum UpdateType { /** * Allows you to disable the term */ - disableTerm + disableTerm, + /** + * Allows you to select the term + */ + selectTerm } /** * Specifies the result that will be returned to the Term after the execution of the callback. @@ -128,7 +132,7 @@ export interface ITermAction { * Method checks if the current term is supported. * @param currentTerm */ - applyToTerm: (currentTerm: ITerm) => Promise | boolean; + applyToTerm: (currentTerm: ITerm, triggerActionCallback: (updateAction: UpdateAction) => void) => Promise | boolean; /** * Method to be executed when action is fired. */ diff --git a/src/controls/taxonomyPicker/termActions/TermActionsControl.tsx b/src/controls/taxonomyPicker/termActions/TermActionsControl.tsx index 7d18b191e..b74068091 100644 --- a/src/controls/taxonomyPicker/termActions/TermActionsControl.tsx +++ b/src/controls/taxonomyPicker/termActions/TermActionsControl.tsx @@ -38,7 +38,7 @@ export default class TermActionsControl extends React.Component