replace 'any'
This commit is contained in:
parent
8665d4665a
commit
1d0187c06f
File diff suppressed because it is too large
Load Diff
|
@ -1,62 +1,50 @@
|
|||
import { MSGraphClientV3 } from "@microsoft/sp-http";
|
||||
import { SitePage } from "./types";
|
||||
|
||||
import { GraphSitePage, GraphSitePageCollection, GraphWebPartCollection } from "./types";
|
||||
import { BaseComponentContext } from "@microsoft/sp-component-base";
|
||||
|
||||
export interface IGraphService {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
GetWebParts(client: MSGraphClientV3, siteId: string, pageId: string): Promise<any>;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
GetSitePages(client: MSGraphClientV3, siteId: string): Promise<any>;
|
||||
GetWebParts(siteId: string, pageId: string): Promise<GraphWebPartCollection>;
|
||||
GetSitePages(siteId: string): Promise<GraphSitePage[]>;
|
||||
}
|
||||
|
||||
export class GraphService implements IGraphService {
|
||||
private MSGraphClient: MSGraphClientV3;
|
||||
private Context: BaseComponentContext;
|
||||
|
||||
|
||||
class GraphService implements IGraphService {
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public async GetWebParts(client: MSGraphClientV3, siteId: string, pageId: string): Promise<any> {
|
||||
try{
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const rawWebParts: any = await this.GET(client, "sites/" + siteId + "/pages/" + pageId + "/webparts","","");
|
||||
return rawWebParts;
|
||||
} catch (error){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
constructor(Context: BaseComponentContext) {
|
||||
this.Context = Context;
|
||||
}
|
||||
|
||||
public async GetSitePages(client: MSGraphClientV3, siteId: string): Promise<SitePage[]> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const rawPages: any = await this.GET(client, "sites/" + siteId + "/pages", "", "id,title");
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return rawPages.value.flatMap((rawPage: any) => (
|
||||
[
|
||||
private async Get_Client(): Promise<MSGraphClientV3> {
|
||||
if (this.MSGraphClient === undefined)
|
||||
this.MSGraphClient = await this.Context.msGraphClientFactory.getClient("3");
|
||||
return this.MSGraphClient;
|
||||
}
|
||||
|
||||
public async GetWebParts(siteId: string, pageId: string): Promise<GraphWebPartCollection> {
|
||||
try {
|
||||
const client = await this.Get_Client();
|
||||
const rawWebParts: GraphWebPartCollection = await client.api("sites/" + siteId + "/pages/" + pageId + "/webparts").version('beta').get();
|
||||
return rawWebParts;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async GetSitePages(siteId: string): Promise<GraphSitePage[]> {
|
||||
|
||||
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 => {
|
||||
pages.push(
|
||||
{
|
||||
id: rawPage.id,
|
||||
title: rawPage.title
|
||||
}
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
private GET(client: MSGraphClientV3, api: string, filter?: string, select?: string, top?: number, responseType?: any): Promise<any> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
client.api(api).version("beta").select(select).filter(filter).responseType(responseType)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.get((error: any, response: any) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
resolve(response);
|
||||
});
|
||||
)
|
||||
});
|
||||
return pages;
|
||||
}
|
||||
}
|
||||
export const GraphServiceInstance = new GraphService();
|
||||
|
||||
|
|
|
@ -1,35 +1,28 @@
|
|||
import { SitePage, WebPart } from "./types";
|
||||
import { GraphServiceInstance } from "./GraphService";
|
||||
import { MSGraphClientV3 } from "@microsoft/sp-http";
|
||||
import { GraphWebPartCollection, WebPart } from "./types";
|
||||
import { IGraphService } from "./GraphService";
|
||||
import {SitePage} from "@microsoft/microsoft-graph-types-beta"
|
||||
|
||||
|
||||
export async function _getSiteWebParts(graphClient: MSGraphClientV3, siteId: string): Promise<WebPart[]> {
|
||||
export async function _getSiteWebParts(service: IGraphService, siteId: string): Promise<WebPart[]> {
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const siteWebParts: any = [];
|
||||
const sitePages: SitePage[] = await GraphServiceInstance.GetSitePages(graphClient, siteId);
|
||||
for (let i: number = 0; i<sitePages.length-1; i++){
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const r: any = await GraphServiceInstance.GetWebParts(graphClient, siteId, sitePages[i].id);
|
||||
if (r !== null){
|
||||
siteWebParts.push(
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
r.value.flatMap((siteWebPart: any) => ([
|
||||
const siteWebParts: WebPart[] = [];
|
||||
const sitePages: SitePage[] = await service.GetSitePages(siteId);
|
||||
for (let i: number = 0; i < sitePages.length - 1; i++) {
|
||||
const graphWebParts: GraphWebPartCollection | null = await service.GetWebParts(siteId, sitePages[i].id);
|
||||
if (graphWebParts !== null) {
|
||||
graphWebParts.value.forEach(siteWebPart => {
|
||||
siteWebParts.push(
|
||||
{
|
||||
siteId: siteId,
|
||||
pageTitle: sitePages[i].title,
|
||||
id: siteWebPart.id,
|
||||
title: siteWebPart.data.title,
|
||||
title: siteWebPart.innerHtml !== undefined ? "Text" : siteWebPart.data.title,
|
||||
}
|
||||
]))
|
||||
);
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return siteWebParts.flatMap((t: any)=>t);
|
||||
|
||||
|
||||
return siteWebParts;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return null;
|
||||
|
|
|
@ -5,12 +5,38 @@ export type WebPart = {
|
|||
title: string;
|
||||
}
|
||||
|
||||
export type GraphWebPart = {
|
||||
data?: GraphWebPartData;
|
||||
id: string;
|
||||
webPartType: string;
|
||||
innerHtml?: string;
|
||||
}
|
||||
|
||||
export type GraphWebPartCollection = {
|
||||
value: GraphWebPart[];
|
||||
}
|
||||
|
||||
export type GraphWebPartData = {
|
||||
audiences: string[];
|
||||
dataVersion: string[];
|
||||
description: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
properties: any;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
serverProcessedContent: any;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export type AggredatedWebParts = {
|
||||
titles: string[];
|
||||
count: number[];
|
||||
}
|
||||
|
||||
export type SitePage = {
|
||||
export type GraphSitePageCollection = {
|
||||
value: GraphSitePage[];
|
||||
}
|
||||
|
||||
export type GraphSitePage = {
|
||||
id: string;
|
||||
title: string;
|
||||
}
|
||||
|
@ -22,6 +48,6 @@ export type ChartDataCustom = {
|
|||
|
||||
export type DataSet = {
|
||||
label: string;
|
||||
data: number [];
|
||||
data: number[];
|
||||
//backgroundColor: string[];
|
||||
}
|
|
@ -11,7 +11,7 @@ import * as strings from 'WebPartReportWebPartStrings';
|
|||
import WebPartReport from './components/WebPartReport';
|
||||
import { IWebPartReportProps } from './components/IWebPartReportProps';
|
||||
import { ITopActions, TopActionsFieldType } from '@microsoft/sp-top-actions';
|
||||
import { MSGraphClientV3 } from "@microsoft/sp-http";
|
||||
import {GraphService} from "./../GraphService"
|
||||
|
||||
export interface IWebPartReportWebPartProps {
|
||||
description: string;
|
||||
|
@ -20,7 +20,6 @@ export interface IWebPartReportWebPartProps {
|
|||
}
|
||||
|
||||
export default class WebPartReportWebPart extends BaseClientSideWebPart<IWebPartReportWebPartProps> {
|
||||
private graphClient: MSGraphClientV3;
|
||||
private _isDarkTheme: boolean = false;
|
||||
|
||||
public render(): void {
|
||||
|
@ -33,24 +32,15 @@ export default class WebPartReportWebPart extends BaseClientSideWebPart<IWebPart
|
|||
hasTeamsContext: !!this.context.sdks.microsoftTeams,
|
||||
userDisplayName: this.context.pageContext.user.displayName,
|
||||
siteId: this.context.pageContext.site.id.toString(),
|
||||
graphClient: this.graphClient
|
||||
GraphService: new GraphService(this.context),
|
||||
}
|
||||
);
|
||||
|
||||
ReactDom.render(element, this.domElement);
|
||||
}
|
||||
|
||||
protected async onInit(): Promise<void> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return new Promise<void>((resolve: () => void, reject: (error: any) => void): void => {
|
||||
this.context.msGraphClientFactory
|
||||
.getClient("3")
|
||||
.then((client: MSGraphClientV3): void => {
|
||||
this.graphClient = client;
|
||||
resolve();
|
||||
}, err => reject(err));
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
protected async onInit(): Promise<void> {}
|
||||
|
||||
protected onThemeChanged(currentTheme: IReadonlyTheme | undefined): void {
|
||||
if (!currentTheme) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { MSGraphClientV3 } from "@microsoft/sp-http";
|
||||
import { IGraphService } from "../../GraphService";
|
||||
|
||||
export interface IWebPartReportProps {
|
||||
description: string;
|
||||
|
@ -7,5 +7,6 @@ export interface IWebPartReportProps {
|
|||
hasTeamsContext: boolean;
|
||||
userDisplayName: string;
|
||||
siteId: string;
|
||||
graphClient: MSGraphClientV3;
|
||||
GraphService: IGraphService;
|
||||
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ export default class WebPartReport extends React.Component<IWebPartReportProps,
|
|||
webPartsTitles = [];
|
||||
aggregatedWebPartData.clear();
|
||||
|
||||
siteWebParts = await _getSiteWebParts(this.props.graphClient, this.props.siteId.toString());
|
||||
siteWebParts = await _getSiteWebParts(this.props.GraphService, this.props.siteId.toString());
|
||||
siteWebParts.forEach(e => {
|
||||
if (!aggregatedWebPartData.has(e.title)) {
|
||||
aggregatedWebPartData.set(e.title, 1);
|
||||
|
|
Loading…
Reference in New Issue