Skip to content

Commit c706b81

Browse files
committed
Merge branch 'AnchorID' of https://github.com/DRamalho92/sp-dev-fx-controls-react into DRamalho92-AnchorID
2 parents ae79b6c + 4737dec commit c706b81

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

src/controls/taxonomyPicker/TermPicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export default class TermPicker extends React.Component<ITermPickerProps, ITermP
112112
private async onFilterChanged(filterText: string, tagList: IPickerTerm[]): Promise<IPickerTerm[]> {
113113
if (filterText !== "") {
114114
let termsService = new SPTermStorePickerService(this.props.termPickerHostProps, this.props.context);
115-
let terms: IPickerTerm[] = await termsService.searchTermsByName(filterText);
115+
let terms: IPickerTerm[] = await termsService.searchTermsByTermId(filterText, this.props.termPickerHostProps.anchorId);
116116
// Check if the termset can be selected
117117
if (this.props.isTermSetSelectable) {
118118
// Retrieve the current termset

src/services/SPTermStorePickerService.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export default class SPTermStorePickerService {
264264
* Retrieve all terms that starts with the searchText
265265
* @param searchText
266266
*/
267-
public searchTermsByName(searchText: string): Promise<IPickerTerm[]> {
267+
public searchTermsByName(searchText: string, termSet: string): Promise<IPickerTerm[]> {
268268
if (Environment.type === EnvironmentType.Local) {
269269
// If the running environment is local, load the data from the mock
270270
return SPTermStoreMockHttpClient.searchTermsByName(searchText);
@@ -273,6 +273,76 @@ export default class SPTermStorePickerService {
273273
}
274274
}
275275

276+
private getTermsById(termId) {
277+
var terms = sessionStorage.getItem(termId);
278+
if(terms)
279+
return JSON.parse(terms);
280+
else
281+
return null;
282+
}
283+
284+
285+
private searchTermsBySearchText(terms, searchText) {
286+
if(terms){
287+
return terms.filter((t) => { return t.name.toLowerCase().indexOf(searchText.toLowerCase()) > -1; });
288+
}
289+
else
290+
return [];
291+
}
292+
293+
294+
public searchTermsByTermId(searchText: string, termId: string): Promise<IPickerTerm[]> {
295+
if (Environment.type === EnvironmentType.Local) {
296+
// If the running environment is local, load the data from the mock
297+
return SPTermStoreMockHttpClient.searchTermsByName(searchText);
298+
} else {
299+
return new Promise<IPickerTerm[]>(resolve => {
300+
var childTerms = this.getTermsById(termId);
301+
if(childTerms){
302+
resolve(this.searchTermsBySearchText(childTerms ,searchText));
303+
}
304+
else{
305+
let data = '<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Javascript Library"><Actions><ObjectPath Id="1" ObjectPathId="0" /><ObjectIdentityQuery Id="2" ObjectPathId="0" /><ObjectPath Id="4" ObjectPathId="3" /><ObjectIdentityQuery Id="5" ObjectPathId="3" /><ObjectPath Id="7" ObjectPathId="6" /><ObjectIdentityQuery Id="8" ObjectPathId="6" /><ObjectPath Id="10" ObjectPathId="9" /><Query Id="11" ObjectPathId="9"><Query SelectAllProperties="false"><Properties /></Query><ChildItemQuery SelectAllProperties="false"><Properties><Property Name="IsRoot" SelectAll="true" /><Property Name="Id" SelectAll="true" /><Property Name="Name" SelectAll="true" /><Property Name="PathOfTerm" SelectAll="true" /><Property Name="TermSet" SelectAll="true" /></Properties></ChildItemQuery></Query></Actions><ObjectPaths><StaticMethod Id="0" Name="GetTaxonomySession" TypeId="{981cbc68-9edc-4f8d-872f-71146fcbb84f}" /><Method Id="3" ParentId="0" Name="GetDefaultSiteCollectionTermStore" /><Method Id="6" ParentId="3" Name="GetTerm"><Parameters><Parameter Type="String">'+termId+'</Parameter></Parameters></Method><Property Id="9" ParentId="6" Name="Terms" /></ObjectPaths></Request>';
306+
307+
const reqHeaders = new Headers();
308+
reqHeaders.append("accept", "application/json");
309+
reqHeaders.append("content-type", "application/xml");
310+
311+
const httpPostOptions: ISPHttpClientOptions = {
312+
headers: reqHeaders,
313+
body: data
314+
};
315+
316+
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
317+
return serviceResponse.json().then((serviceJSONResponse: any) => {
318+
// Retrieve the term collection results
319+
const termStoreResult: ITerms[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
320+
if (termStoreResult.length > 0) {
321+
// Retrieve all terms
322+
323+
let terms = termStoreResult[0]._Child_Items_;
324+
325+
let returnTerms: IPickerTerm[] = [];
326+
terms.forEach(term => {
327+
returnTerms.push({
328+
key: this.cleanGuid(term.Id),
329+
name: term.Name,
330+
path: term.PathOfTerm,
331+
termSet: this.cleanGuid(term.TermSet.Id),
332+
termSetName: term.TermSet.Name
333+
});
334+
});
335+
sessionStorage.setItem(termId, JSON.stringify(returnTerms));
336+
resolve(this.searchTermsBySearchText(returnTerms, searchText));
337+
}
338+
return null;
339+
});
340+
});
341+
}
342+
});
343+
}
344+
}
345+
276346
/**
277347
* Searches terms for the given term set
278348
* @param searchText

0 commit comments

Comments
 (0)