diff --git a/samples/react-display-hierarchy/src/webparts/reactHierarchyView/components/ReactHierarchyView.tsx b/samples/react-display-hierarchy/src/webparts/reactHierarchyView/components/ReactHierarchyView.tsx index 6f162455b..c6a623468 100644 --- a/samples/react-display-hierarchy/src/webparts/reactHierarchyView/components/ReactHierarchyView.tsx +++ b/samples/react-display-hierarchy/src/webparts/reactHierarchyView/components/ReactHierarchyView.tsx @@ -21,7 +21,7 @@ export interface IReactHierarchyState { export default class ReactHierarchyView extends React.Component { private HierarchyServiceInstance: IHierarchyService; - private _listName: string; + constructor(props: IReactHierarchyViewProps) { super(props); this.state = { @@ -30,15 +30,23 @@ export default class ReactHierarchyView extends React.Component { + this.HierarchyServiceInstance.getHierarchyInfo(listName).then((hierarchyItems: any) => { if (Environment.type == EnvironmentType.SharePoint || Environment.type == EnvironmentType.ClassicSharePoint) { if (hierarchyItems.length > 0) { let hierarchyNodes: Array = []; @@ -63,11 +71,13 @@ export default class ReactHierarchyView extends React.Component - this.setState({ - errorMessage: "Please verify webpart configuration. Error details: " + error.message, - isLoading: false, - showErrorMessage: true - }) - ); + }) + .catch((error) => + this.setState({ + hierarchyItems: [], + errorMessage: "Please verify web part configuration. Error details: " + error.message, + isLoading: false, + showErrorMessage: true + }) + ); } public render(): React.ReactElement { @@ -94,9 +107,9 @@ export default class ReactHierarchyView extends React.Component
-
+
{this.state.isLoading && } - {this.state.hierarchyItems && + {this.state.hierarchyItems && this.state.hierarchyItems.children && }
diff --git a/samples/react-display-hierarchy/src/webparts/reactHierarchyView/services/HierarchyService.ts b/samples/react-display-hierarchy/src/webparts/reactHierarchyView/services/HierarchyService.ts index 25bb227fc..fcc5755e3 100644 --- a/samples/react-display-hierarchy/src/webparts/reactHierarchyView/services/HierarchyService.ts +++ b/samples/react-display-hierarchy/src/webparts/reactHierarchyView/services/HierarchyService.ts @@ -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; - }); }