Skip to content

Commit 61c7a73

Browse files
committed
Added setActionVisibility functionality
1 parent 0ae4bef commit 61c7a73

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/controls/taxonomyPicker/Term.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,7 @@ export default class Term extends React.Component<ITermProps, ITermState> {
9090
} else if (updateAction.updateActionType === UpdateType.selectTerm) {
9191
// Only select the term when not disabled or hidden
9292
if (!this.state.disabled && !this.state.hidden) {
93-
this.setState({
94-
selected: updateAction.value as boolean
95-
});
96-
this.props.changedCallback(this.props.term, updateAction.value as boolean);
93+
this._handleChange(null, updateAction.value as boolean);
9794
}
9895
} else {
9996
this.props.updateTaxonomyTree();

src/controls/taxonomyPicker/termActions/ITermsActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export interface ITermAction {
132132
* Method checks if the current term is supported.
133133
* @param currentTerm
134134
*/
135-
applyToTerm: (currentTerm: ITerm, triggerActionCallback: (updateAction: UpdateAction) => void) => Promise<boolean> | boolean;
135+
applyToTerm: (currentTerm: ITerm, triggerActionCallback: (updateAction: UpdateAction) => void, setVisibility: (actionId: string, isHidden: boolean) => void) => Promise<boolean> | boolean;
136136
/**
137137
* Method to be executed when action is fired.
138138
*/

src/controls/taxonomyPicker/termActions/TermActionsControl.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { ITermAction, ITermActionsControlProps, ITermActionsControlState, TermActionsDisplayMode, TermActionsDisplayStyle } from './ITermsActions';
33
import { DropdownTermAction } from './DropdownTermAction';
44
import ButtonTermAction from './ButtonTermAction';
5+
import { find } from 'office-ui-fabric-react/lib/Utilities';
56

67
export default class TermActionsControl extends React.Component<ITermActionsControlProps, ITermActionsControlState> {
78

@@ -38,7 +39,7 @@ export default class TermActionsControl extends React.Component<ITermActionsCont
3839

3940
if (termActions.actions) {
4041
for (const action of termActions.actions) {
41-
const available = await action.applyToTerm(term, this.props.termActionCallback);
42+
const available = await action.applyToTerm(term, this.props.termActionCallback, this.setActionVisibility);
4243
if (available) {
4344
availableActions.push(action);
4445
}
@@ -50,6 +51,20 @@ export default class TermActionsControl extends React.Component<ITermActionsCont
5051
});
5152
}
5253

54+
/**
55+
* Sets the visibility of a certain action
56+
* @param isHidden
57+
*/
58+
private setActionVisibility(actionId: string, isHidden: boolean) {
59+
this.setState((prevState: ITermActionsControlState) => {
60+
const action = find(prevState.availableActions, a => a.id === actionId);
61+
action.hidden = isHidden;
62+
return {
63+
availableActions: prevState.availableActions
64+
};
65+
});
66+
}
67+
5368
/**
5469
* Default React render method
5570
*/

0 commit comments

Comments
 (0)