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