Fixed Web Part doesn't react to property change
This commit is contained in:
parent
9b8d3e2b13
commit
c05e15bc0f
|
@ -21,7 +21,7 @@ export interface IReactHierarchyState {
|
|||
|
||||
export default class ReactHierarchyView extends React.Component<IReactHierarchyViewProps, IReactHierarchyState> {
|
||||
private HierarchyServiceInstance: IHierarchyService;
|
||||
private _listName: string;
|
||||
|
||||
constructor(props: IReactHierarchyViewProps) {
|
||||
super(props);
|
||||
this.state = {
|
||||
|
@ -30,10 +30,18 @@ export default class ReactHierarchyView extends React.Component<IReactHierarchyV
|
|||
showErrorMessage: false,
|
||||
errorMessage: ""
|
||||
};
|
||||
}
|
||||
|
||||
let serviceScope: ServiceScope;
|
||||
serviceScope = this.props.serviceScope;
|
||||
this._listName = this.props.listName;
|
||||
public async componentDidMount() {
|
||||
this.loadHierarchyView(this.props.listName);
|
||||
}
|
||||
|
||||
public componentWillReceiveProps(nextProps: IReactHierarchyViewProps) {
|
||||
this.loadHierarchyView(nextProps.listName);
|
||||
}
|
||||
|
||||
private loadHierarchyView(listName: string): void {
|
||||
let serviceScope: ServiceScope = this.props.serviceScope;
|
||||
|
||||
// Based on the type of environment, return the correct instance of the IHierarchyServiceInstance interface
|
||||
if (Environment.type == EnvironmentType.SharePoint || Environment.type == EnvironmentType.ClassicSharePoint) {
|
||||
|
@ -46,7 +54,7 @@ export default class ReactHierarchyView extends React.Component<IReactHierarchyV
|
|||
this.HierarchyServiceInstance = serviceScope.consume(MockHierarchyService.serviceKey);
|
||||
}
|
||||
|
||||
this.HierarchyServiceInstance.getHierarchyInfo(this._listName).then((hierarchyItems: any) => {
|
||||
this.HierarchyServiceInstance.getHierarchyInfo(listName).then((hierarchyItems: any) => {
|
||||
if (Environment.type == EnvironmentType.SharePoint || Environment.type == EnvironmentType.ClassicSharePoint) {
|
||||
if (hierarchyItems.length > 0) {
|
||||
let hierarchyNodes: Array<Item> = [];
|
||||
|
@ -63,11 +71,13 @@ export default class ReactHierarchyView extends React.Component<IReactHierarchyV
|
|||
|
||||
this.setState({
|
||||
hierarchyItems: JSON.parse(output),
|
||||
isLoading: false
|
||||
isLoading: false,
|
||||
showErrorMessage: false
|
||||
});
|
||||
}
|
||||
else {
|
||||
this.setState({
|
||||
hierarchyItems: [],
|
||||
isLoading: false,
|
||||
showErrorMessage: true,
|
||||
errorMessage: "No records to be displayed"
|
||||
|
@ -77,11 +87,14 @@ export default class ReactHierarchyView extends React.Component<IReactHierarchyV
|
|||
else {
|
||||
this.setState({
|
||||
hierarchyItems: JSON.parse(hierarchyItems),
|
||||
isLoading: false
|
||||
isLoading: false,
|
||||
showErrorMessage: false
|
||||
});
|
||||
}
|
||||
}).catch((error) =>
|
||||
})
|
||||
.catch((error) =>
|
||||
this.setState({
|
||||
hierarchyItems: [],
|
||||
errorMessage: "Please verify web part configuration. Error details: " + error.message,
|
||||
isLoading: false,
|
||||
showErrorMessage: true
|
||||
|
@ -96,7 +109,7 @@ export default class ReactHierarchyView extends React.Component<IReactHierarchyV
|
|||
<div className={styles.row}>
|
||||
<div className={styles.column}>
|
||||
{this.state.isLoading && <Spinner label="Loading Hierarchy View..." />}
|
||||
{this.state.hierarchyItems &&
|
||||
{this.state.hierarchyItems && this.state.hierarchyItems.children &&
|
||||
<OrgChart tree={this.state.hierarchyItems} NodeComponent={this.MyNodeComponent} />
|
||||
}
|
||||
</div>
|
||||
|
|
|
@ -17,7 +17,6 @@ export class HierarchyService implements IHierarchyService {
|
|||
this._spHttpClient = serviceScope.consume(SPHttpClient.serviceKey);
|
||||
this._pageContext = serviceScope.consume(PageContext.serviceKey);
|
||||
this._currentWebUrl = this._pageContext.web.absoluteUrl;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue