diff --git a/samples/react-graph-webpart-report/src/webparts/GraphService.ts b/samples/react-graph-webpart-report/src/webparts/GraphService.ts index afb35b3e7..ad1fb69ab 100644 --- a/samples/react-graph-webpart-report/src/webparts/GraphService.ts +++ b/samples/react-graph-webpart-report/src/webparts/GraphService.ts @@ -24,23 +24,22 @@ export class GraphService implements IGraphService { public async GetWebParts(siteId: string, pageId: string): Promise { try { const client = await this.Get_Client(); - const rawWebParts: GraphWebPartCollection = await client.api("sites/" + siteId + "/pages/" + pageId + "/webparts").version('beta').get(); - return rawWebParts; + const retrievedWebParts: GraphWebPartCollection = await client.api("sites/" + siteId + "/pages/" + pageId + "/webparts").version('beta').get(); + return retrievedWebParts; } catch (error) { return null; } } public async GetSitePages(siteId: string): Promise { - const pages: GraphSitePage[] = []; const client = await this.Get_Client(); - const rawPages: GraphSitePageCollection = await client.api("sites/" + siteId + "/pages").select("id,title").version('beta').get(); - rawPages.value.forEach(rawPage => { + const retrievedPages: GraphSitePageCollection = await client.api("sites/" + siteId + "/pages").select("id,title").version('beta').get(); + retrievedPages.value.forEach(page => { pages.push( { - id: rawPage.id, - title: rawPage.title + id: page.id, + title: page.title } ) }); diff --git a/samples/react-graph-webpart-report/src/webparts/types.ts b/samples/react-graph-webpart-report/src/webparts/types.ts index c36a042b2..b385c6a85 100644 --- a/samples/react-graph-webpart-report/src/webparts/types.ts +++ b/samples/react-graph-webpart-report/src/webparts/types.ts @@ -28,8 +28,8 @@ export type GraphWebPartData = { } export type AggredatedWebParts = { - titles: string[]; - count: number[]; + WPTitles: string[]; + WPCount: number[]; } export type GraphSitePageCollection = { diff --git a/samples/react-graph-webpart-report/src/webparts/webPartReport/components/IWebPartReportWebPartState.ts b/samples/react-graph-webpart-report/src/webparts/webPartReport/components/IWebPartReportWebPartState.ts index e34c512cf..e735a8310 100644 --- a/samples/react-graph-webpart-report/src/webparts/webPartReport/components/IWebPartReportWebPartState.ts +++ b/samples/react-graph-webpart-report/src/webparts/webPartReport/components/IWebPartReportWebPartState.ts @@ -2,7 +2,7 @@ import { AggredatedWebParts, WebPart } from "../../types"; export interface IWebPartReportWebPartState { webPartList: WebPart[]; - aggregatedWebPartList: AggredatedWebParts; + chartWebPartList: AggredatedWebParts; loading: boolean; page: number; } \ No newline at end of file diff --git a/samples/react-graph-webpart-report/src/webparts/webPartReport/components/WebPartReport.tsx b/samples/react-graph-webpart-report/src/webparts/webPartReport/components/WebPartReport.tsx index 45d081306..593a2c921 100644 --- a/samples/react-graph-webpart-report/src/webparts/webPartReport/components/WebPartReport.tsx +++ b/samples/react-graph-webpart-report/src/webparts/webPartReport/components/WebPartReport.tsx @@ -49,9 +49,6 @@ const options: any = { -let webPartsCounts: number[] = []; -let webPartsTitles: string[] = []; -const aggregatedWebPartData = new Map(); export default class WebPartReport extends React.Component { @@ -60,57 +57,56 @@ export default class WebPartReport extends React.Component { - await this._setChartData(); + await this._getWebParts(); } private loadingData(): Promise { - return new Promise((resolve, _reject) => { - - let countWP: number[] = []; - countWP = this.state.aggregatedWebPartList.count const data: ChartData = { - labels: this.state.aggregatedWebPartList.titles.length > 0 ? this.state.aggregatedWebPartList.titles : [], - datasets: [{ label: "WebParts", data: countWP.length > 0 ? countWP : [] }] + labels: this.state.chartWebPartList.WPTitles.length > 0 ? this.state.chartWebPartList.WPTitles : [], + datasets: [{ + label: "WebParts", + data: this.state.chartWebPartList.WPCount.length > 0 ? this.state.chartWebPartList.WPCount : [] + }] }; resolve(data); - }); } - public async _setChartData(): Promise { - webPartsCounts = []; - webPartsTitles = []; - aggregatedWebPartData.clear(); + public async _getWebParts(): Promise { + + const webPartsCounts: number[] = []; + const webPartsTitles: string[] = []; + const webPartMap = new Map(); + + webPartMap.clear(); const siteWebParts = await _getSiteWebParts(this.props.GraphService, this.props.siteId.toString()); siteWebParts.forEach(e => { - if (!aggregatedWebPartData.has(e.title)) { - aggregatedWebPartData.set(e.title, 1); + if (!webPartMap.has(e.title)) { + webPartMap.set(e.title, 1); } else { - aggregatedWebPartData.set(e.title, aggregatedWebPartData.get(e.title) + 1) + webPartMap.set(e.title, webPartMap.get(e.title) + 1) } }); - aggregatedWebPartData.forEach(a => { - webPartsCounts.push(a); - }); - aggregatedWebPartData.forEach((value, key) => { + webPartMap.forEach((value, key) => { + webPartsCounts.push(value); webPartsTitles.push(key); }); this.setState({ webPartList: siteWebParts, - aggregatedWebPartList: { - titles: webPartsTitles, - count: webPartsCounts + chartWebPartList: { + WPTitles: webPartsTitles, + WPCount: webPartsCounts }, loading: false });