Skip to content

Commit

Permalink
#578 - Added selectTerm action for TaxonomyPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jun 12, 2020
1 parent d552081 commit 2cd1e75
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 5 additions & 4 deletions docs/documentation/docs/controls/TaxonomyPicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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
}]
}} />
```
Expand Down Expand Up @@ -218,5 +218,6 @@ Enum `UpdateType`
| updateTermsTree |
| hideTerm |
| disableTerm |
| selectTerm |

![](https://telemetry.sharepointpnp.com/sp-dev-fx-controls-react/wiki/controls/Placeholder)
5 changes: 5 additions & 0 deletions src/controls/taxonomyPicker/Term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export default class Term extends React.Component<ITermProps, ITermState> {
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();
}
Expand Down
8 changes: 6 additions & 2 deletions src/controls/taxonomyPicker/termActions/ITermsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -128,7 +132,7 @@ export interface ITermAction {
* Method checks if the current term is supported.
* @param currentTerm
*/
applyToTerm: (currentTerm: ITerm) => Promise<boolean> | boolean;
applyToTerm: (currentTerm: ITerm, triggerActionCallback: (updateAction: UpdateAction) => void) => Promise<boolean> | boolean;
/**
* Method to be executed when action is fired.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class TermActionsControl extends React.Component<ITermActionsCont

if (termActions.actions) {
for (const action of termActions.actions) {
const available = await action.applyToTerm(term);
const available = await action.applyToTerm(term, this.props.termActionCallback);
if (available) {
availableActions.push(action);
}
Expand Down

0 comments on commit 2cd1e75

Please sign in to comment.