Skip to content

Commit 14368a7

Browse files
committed
Check if initial values are not equal
1 parent e594225 commit 14368a7

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/controls/taxonomyPicker/TaxonomyPicker.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export class TaxonomyPicker extends React.Component<ITaxonomyPickerProps, ITaxon
6868
* componentWillUpdate lifecycle hook
6969
*/
7070
public componentDidUpdate(prevProps: ITaxonomyPickerProps): void {
71-
if (isEqual(this.props.initialValues, prevProps.initialValues)) {
71+
// Check if the initial values objects are not equal, if that is the case, data can be refreshed
72+
if (!isEqual(this.props.initialValues, prevProps.initialValues)) {
7273
this.setState({
7374
activeNodes: this.props.initialValues || []
7475
});

src/webparts/controlsTest/components/ControlsTest.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { IControlsTestProps, IControlsTestState } from './IControlsTestProps';
44
import { escape } from '@microsoft/sp-lodash-subset';
55
import { FileTypeIcon, IconType, ApplicationType, ImageSize } from '../../../FileTypeIcon';
66
import { Dropdown, IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
7-
import { PrimaryButton } from 'office-ui-fabric-react/lib/components/Button';
7+
import { PrimaryButton, DefaultButton } from 'office-ui-fabric-react/lib/components/Button';
88
import { DialogType } from 'office-ui-fabric-react/lib/components/Dialog';
99
import { Placeholder } from '../../../Placeholder';
1010
import { ListView, IViewField, SelectionMode, GroupOrder, IGrouping } from '../../../ListView';
@@ -28,7 +28,8 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
2828
this.state = {
2929
imgSize: ImageSize.small,
3030
items: [],
31-
iFrameDialogOpened: false
31+
iFrameDialogOpened: false,
32+
initialValues: []
3233
};
3334

3435
this._onIconSizeChange = this._onIconSizeChange.bind(this);
@@ -78,8 +79,11 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
7879
* Method that retrieves the selected terms from the taxonomy picker
7980
* @param terms
8081
*/
81-
private _onTaxPickerChange(terms : IPickerTerms) {
82-
console.log("Terms:", terms);
82+
private _onTaxPickerChange = (terms : IPickerTerms) => {
83+
this.setState({
84+
initialValues: terms
85+
});
86+
console.log("Terms:", terms);
8387
}
8488

8589
/**
@@ -220,6 +224,7 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
220224

221225
<div className="ms-font-m">TaxonomyPicker tester:
222226
<TaxonomyPicker
227+
initialValues={this.state.initialValues}
223228
allowMultipleSelections={true}
224229
termsetNameOrID="b3e9b754-2593-4ae6-abc2-35345402e186"
225230
// anchorId="0ec2f948-3978-499e-9d3f-e51c4494d44c"
@@ -232,6 +237,17 @@ export default class ControlsTest extends React.Component<IControlsTestProps, IC
232237
context={this.props.context}
233238
onChange={this._onTaxPickerChange}
234239
isTermSetSelectable={false} />
240+
241+
<DefaultButton text="Add" onClick={() => {
242+
this.setState({
243+
initialValues: [{
244+
key: "ab703558-2546-4b23-b8b8-2bcb2c0086f5",
245+
name: "HR",
246+
path: "HR",
247+
termSet: "b3e9b754-2593-4ae6-abc2-35345402e186"
248+
}]
249+
});
250+
}} />
235251
</div>
236252
<div className="ms-font-m">iframe dialog tester:
237253
<PrimaryButton

src/webparts/controlsTest/components/IControlsTestProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export interface IControlsTestProps {
1313
export interface IControlsTestState {
1414
imgSize: ImageSize;
1515
items: any[];
16+
initialValues: any[];
1617
iFrameDialogOpened?: boolean;
1718
}

0 commit comments

Comments
 (0)