Skip to content

Commit

Permalink
#205 - Sort order fix in TermPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Dec 21, 2018
1 parent 194adda commit 100a876
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
6 changes: 2 additions & 4 deletions src/controls/taxonomyPicker/TermParent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ export default class TermParent extends React.Component<ITermParentProps, ITermP
/**
* componentWillMount
*/
public componentWillMount()
{
public componentWillMount() {
// fix term depth if anchroid for rendering
if (this.props.anchorId)
{
const anchorTerm = this._terms.filter(t => t.Id.toLowerCase() === this.props.anchorId.toLowerCase()).shift();
if (anchorTerm)
{
if (anchorTerm) {
const anchorDepth = anchorTerm.PathDepth;
this._anchorName = anchorTerm.Name;
var anchorTerms : ITerm[] = this._terms.filter(t => t.PathOfTerm.substring(0, anchorTerm.PathOfTerm.length) === anchorTerm.PathOfTerm && t.Id !== anchorTerm.Id);
Expand Down
17 changes: 8 additions & 9 deletions src/services/SPTermStorePickerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class SPTermStorePickerService {
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
return serviceResponse.json().then((serviceJSONResponse: any) => {
// Construct results
let termStoreResult: ITermStore[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermStore');
let termStoreResult: ITermStore[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermStore');
// Check if term store was retrieved
if (termStoreResult.length > 0) {
// Check if the termstore needs to be filtered or limited
Expand Down Expand Up @@ -146,13 +146,13 @@ export default class SPTermStorePickerService {

return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
return serviceResponse.json().then((serviceJSONResponse: any) => {
const termStoreResultTermSets: ITermSet[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermSet');
const termStoreResultTermSets: ITermSet[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermSet');

if (termStoreResultTermSets.length > 0) {
var termStoreResultTermSet = termStoreResultTermSets[0];
termStoreResultTermSet.Terms = [];
// Retrieve the term collection results
const termStoreResultTerms: ITerms[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
const termStoreResultTerms: ITerms[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
if (termStoreResultTerms.length > 0) {
// Retrieve all terms
let terms = termStoreResultTerms[0]._Child_Items_;
Expand Down Expand Up @@ -264,7 +264,7 @@ export default class SPTermStorePickerService {
return this.context.spHttpClient.post(this.clientServiceUrl, SPHttpClient.configurations.v1, httpPostOptions).then((serviceResponse: SPHttpClientResponse) => {
return serviceResponse.json().then((serviceJSONResponse: any) => {
// Retrieve the term collection results
const termStoreResult: ITerms[] = serviceJSONResponse.filter(r => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
const termStoreResult: ITerms[] = serviceJSONResponse.filter((r: { [x: string]: string; }) => r['_ObjectType_'] === 'SP.Taxonomy.TermCollection');
if (termStoreResult.length > 0) {
// Retrieve all terms

Expand Down Expand Up @@ -302,15 +302,15 @@ export default class SPTermStorePickerService {
* @param b term 2
*/
private _sortTerms(a: ITerm, b: ITerm) {
if(a.CustomSortOrderIndex === -1){
if (a.PathOfTerm < b.PathOfTerm) {
if (a.CustomSortOrderIndex === -1) {
if (a.PathOfTerm.toLowerCase() < b.PathOfTerm.toLowerCase()) {
return -1;
}
if (a.PathOfTerm > b.PathOfTerm) {
if (a.PathOfTerm.toLowerCase() > b.PathOfTerm.toLowerCase()) {
return 1;
}
return 0;
}else{
} else {
if (a.CustomSortOrderIndex < b.CustomSortOrderIndex) {
return -1;
}
Expand All @@ -319,7 +319,6 @@ export default class SPTermStorePickerService {
}
return 0;
}

}

/**
Expand Down

0 comments on commit 100a876

Please sign in to comment.