mirror of
https://github.com/pnp/sp-dev-fx-webparts.git
synced 2025-02-28 16:59:11 +00:00
Minor updates
This commit is contained in:
parent
823f273e95
commit
a4fb9b6e20
@ -2,5 +2,8 @@
|
||||
"$schema": "https://raw.githubusercontent.com/s-KaiNet/spfx-fast-serve/master/schema/config.latest.schema.json",
|
||||
"cli": {
|
||||
"isLibraryComponent": false
|
||||
},
|
||||
"serve": {
|
||||
"open": false
|
||||
}
|
||||
}
|
@ -16,8 +16,12 @@ export default class CascadingManagedMetadataWebPart extends BaseClientSideWebPa
|
||||
|
||||
private _placeholder = null;
|
||||
|
||||
public async render(): Promise<void> {
|
||||
protected async onInit(): Promise<void> {
|
||||
await MSGraph.Init(this.context);
|
||||
return super.onInit();
|
||||
}
|
||||
|
||||
public async render(): Promise<void> {
|
||||
let renderElement = null;
|
||||
if (this.properties.termSetId) {
|
||||
renderElement = React.createElement(
|
||||
|
@ -29,7 +29,7 @@ const CascadingManagedMetadata: React.SFC<ICascadingManagedMetadataProps> = (pro
|
||||
//* Check if the term set has a property called UsedForShowingMaps
|
||||
const _checkIfTermsetIsUsedForShowingMaps = async (): Promise<boolean> => {
|
||||
try {
|
||||
const termsetData = await MSGraph.Get(`/termStore/sets/${props.termSetId}`, "beta", ["properties"]);
|
||||
const termsetData = await MSGraph.Call('get', `/termStore/sets/${props.termSetId}`, "beta", {}, ["properties"]);
|
||||
const termsetProperties: IProperty[] = termsetData.properties;
|
||||
console.debug("%s Retrieved termset properties. %o", LOG_SOURCE, termsetProperties);
|
||||
|
||||
@ -53,7 +53,7 @@ const CascadingManagedMetadata: React.SFC<ICascadingManagedMetadataProps> = (pro
|
||||
//* Get the country terms i.e. level 1 children using Graph
|
||||
const _getCountries = async (): Promise<ITerms> => {
|
||||
try {
|
||||
let countries: ITerms = await MSGraph.Get(`/termStore/sets/${props.termSetId}/children`, "beta");
|
||||
let countries: ITerms = await MSGraph.Call('get', `/termStore/sets/${props.termSetId}/children`, "beta");
|
||||
setMessageBarStatus(state => ({ ...state, show: false }));
|
||||
console.debug("%s Retrieved countries. %o", LOG_SOURCE, countries);
|
||||
return countries;
|
||||
|
@ -25,7 +25,7 @@ export class MMDService {
|
||||
|
||||
private static async _getTermsAsDropdownOptionsUsingGraph(apiUrl: string, selectProperties: string[], parent: string): Promise<ICMMDDropdownOption[]> {
|
||||
try {
|
||||
let terms: ITerms = await MSGraph.Get(apiUrl, "beta", selectProperties);
|
||||
let terms: ITerms = await MSGraph.Call("get", apiUrl, "beta", {}, selectProperties);
|
||||
if (terms.value) {
|
||||
const options: ICMMDDropdownOption[] = terms.value.map(t => ({
|
||||
key: t.id,
|
||||
|
@ -1,3 +1,5 @@
|
||||
//* Helper wrapper for calling Graph
|
||||
//* based on https://gist.github.com/wobba/37416d3107b85675d896105554b3df28
|
||||
//* Thank you Mikael Svenson
|
||||
|
||||
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||
@ -6,87 +8,32 @@ import { MSGraphClient } from '@microsoft/sp-http';
|
||||
|
||||
export class MSGraph {
|
||||
private static _graphClient: MSGraphClient;
|
||||
|
||||
public static async Init(context: WebPartContext) {
|
||||
this._graphClient = await context.msGraphClientFactory.getClient();
|
||||
}
|
||||
|
||||
public static async Get(apiUrl: string, version: string = "v1.0", selectProperties?: string[], expandProperties?: string[], filter?: string, count?: boolean): Promise<any> {
|
||||
public static async Call(
|
||||
method: "get" | "post" | "patch" | "delete",
|
||||
apiUrl: string,
|
||||
version: "v1.0" | "beta",
|
||||
content?: any,
|
||||
selectProperties?: string[],
|
||||
expandProperties?: string[],
|
||||
filter?: string,
|
||||
count?: boolean
|
||||
): Promise<any> {
|
||||
|
||||
var p = new Promise<string>(async (resolve, reject) => {
|
||||
let query = this._graphClient.api(apiUrl).version(version);
|
||||
if (selectProperties && selectProperties.length > 0) {
|
||||
query = query.select(selectProperties);
|
||||
}
|
||||
if (filter && filter.length > 0) {
|
||||
query = query.filter(filter);
|
||||
}
|
||||
if (expandProperties && expandProperties.length > 0) {
|
||||
query = query.expand(expandProperties);
|
||||
}
|
||||
if (count) {
|
||||
query = query.count(true);
|
||||
}
|
||||
|
||||
let callback = (error: GraphError, response: any, rawResponse?: any) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
};
|
||||
await query.get(callback);
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
public static async Patch(apiUrl: string, version: string = "v1.0", content: any): Promise<any> {
|
||||
var p = new Promise<string>(async (resolve, reject) => {
|
||||
if (typeof (content) === "object") {
|
||||
content = JSON.stringify(content);
|
||||
}
|
||||
|
||||
let query = this._graphClient.api(apiUrl).version(version);
|
||||
let callback = (error: GraphError, _response: any, rawResponse?: any) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(_response);
|
||||
}
|
||||
};
|
||||
await query.update(content, callback);
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
public static async Post(apiUrl: string, version: string = "v1.0", content: any): Promise<any> {
|
||||
var p = new Promise<string>(async (resolve, reject) => {
|
||||
if (typeof (content) === "object") {
|
||||
content = JSON.stringify(content);
|
||||
}
|
||||
|
||||
let query = this._graphClient.api(apiUrl).version(version);
|
||||
let callback = (error: GraphError, response: any, rawResponse?: any) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
};
|
||||
await query.post(content, callback);
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
public static async Delete(apiUrl: string, version: string = "v1.0"): Promise<any> {
|
||||
var p = new Promise<string>(async (resolve, reject) => {
|
||||
let query = this._graphClient.api(apiUrl).version(version);
|
||||
let callback = (error: GraphError, response: any, rawResponse?: any) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
resolve(response);
|
||||
}
|
||||
};
|
||||
await query.delete(callback);
|
||||
typeof(content) === "object" && (content = JSON.stringify(content));
|
||||
selectProperties && selectProperties.length > 0 && (query = query.select(selectProperties));
|
||||
filter && filter.length > 0 && (query = query.filter(filter));
|
||||
expandProperties && expandProperties.length > 0 && (query = query.expand(expandProperties));
|
||||
count && (query = query.count(count));
|
||||
let callback = (error: GraphError, response: any, rawResponse?: any) => error ? reject(error) : resolve(response);
|
||||
//* ES2016
|
||||
["post", "patch"].includes(method) ? await query[method](content, callback) : await query[method](callback);
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
@ -25,7 +25,8 @@
|
||||
"es5",
|
||||
"dom",
|
||||
"es2015.collection",
|
||||
"es2015.promise"
|
||||
"es2015.promise",
|
||||
"ES2016.Array.Include"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user