Skip to content

Commit 4597e0b

Browse files
authored
Merge pull request #163 from SharePoint/dev
Prepare v1.14.1
2 parents 56edc34 + bf95c11 commit 4597e0b

File tree

11 files changed

+85
-14
lines changed

11 files changed

+85
-14
lines changed

CHANGELOG.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
{
22
"versions": [
3+
{
4+
"version": "1.14.1",
5+
"changes": {
6+
"new": [],
7+
"enhancements": [],
8+
"fixes": [
9+
"`TaxonomyPicker`: Terms are sorted incorrectly under the wrong parent [#153](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/153)",
10+
"`EnterpriseTermPicker`: Terms are sorted incorrectly under the wrong parent [#156](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/156)"
11+
]
12+
},
13+
"contributions": []
14+
},
315
{
416
"version": "1.14.0",
517
"changes": {

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Releases
22

3+
## 1.14.1
4+
5+
### Fixes
6+
7+
- `TaxonomyPicker`: Terms are sorted incorrectly under the wrong parent [#153](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/153)
8+
- `EnterpriseTermPicker`: Terms are sorted incorrectly under the wrong parent [#156](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/156)
9+
310
## 1.14.0
411

512
### New control(s)

docs/documentation/docs/about/release-notes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Releases
22

3+
## 1.14.1
4+
5+
### Fixes
6+
7+
- `TaxonomyPicker`: Terms are sorted incorrectly under the wrong parent [#153](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/153)
8+
- `EnterpriseTermPicker`: Terms are sorted incorrectly under the wrong parent [#156](https://github.com/SharePoint/sp-dev-fx-property-controls/issues/156)
9+
310
## 1.14.0
411

512
### New control(s)

docs/documentation/docs/controls/PropertyPaneWebPartInformation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This control allows you to specify a description, a 'read more' link, and an opt
1313
2. Import the following modules to your component:
1414

1515
```TypeScript
16-
import { PropertyWebPartInformation } from '@pnp/spfx-property-controls/lib/PropertyPaneWebPartInformation';
16+
import { PropertyPaneWebPartInformation } from '@pnp/spfx-property-controls/lib/PropertyPaneWebPartInformation';
1717
```
1818

1919
3. Create a new property for your web part, for example:

docs/documentation/mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ nav:
66
- PropertyFieldCollectionData: 'controls/PropertyFieldCollectionData.md'
77
- PropertyFieldColorPicker: 'controls/PropertyFieldColorPicker.md'
88
- PropertyFieldDateTimePicker: 'controls/PropertyFieldDateTimePicker.md'
9+
- PropertyFieldEnterpriseTermPicker: 'controls/PropertyFieldEnterpriseTermPicker.md'
910
- PropertyFieldListPicker: 'controls/PropertyFieldListPicker.md'
1011
- PropertyFieldMultiSelect: 'controls/PropertyFieldMultiSelect.md'
1112
- PropertyFieldNumber: 'controls/PropertyFieldNumber.md'

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pnp/spfx-property-controls",
33
"description": "Reusable property pane controls for SharePoint Framework solutions",
4-
"version": "1.14.0",
4+
"version": "1.14.1",
55
"engines": {
66
"node": ">=0.10.0"
77
},

src/common/telemetry/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const version: string = "1.14.0";
1+
export const version: string = "1.14.1";

src/services/ISPTermStorePickerService.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { IPickerTerm } from './../propertyFields/termPicker/IPropertyFieldTermPicker';
2+
import { findIndex } from '@microsoft/sp-lodash-subset';
23

34
/**
45
* Interfaces for Term store, groups and term sets
@@ -159,12 +160,56 @@ export class TermStorePickerServiceHelper {
159160
return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(strGuid);
160161
}
161162

162-
/**
163+
/**
164+
* Sorting terms based on their path and depth
165+
*
166+
* @param terms
167+
*/
168+
public static sortTerms(terms: ITerm[]) {
169+
// Start sorting by depth
170+
let newTermsOrder: ITerm[] = [];
171+
let itemsToSort = true;
172+
let pathLevel = 1;
173+
while (itemsToSort) {
174+
// Get terms for the current level
175+
let crntTerms = terms.filter(term => term.PathDepth === pathLevel);
176+
if (crntTerms && crntTerms.length > 0) {
177+
crntTerms = crntTerms.sort(this.sortTermByPath);
178+
179+
if (pathLevel !== 1) {
180+
crntTerms = crntTerms.reverse();
181+
for (const crntTerm of crntTerms) {
182+
const pathElms = crntTerm.PathOfTerm.split(";");
183+
// Last item is not needed for parent path
184+
pathElms.pop();
185+
// Find the parent item and add the new item
186+
const idx = findIndex(newTermsOrder, term => term.PathOfTerm === pathElms.join(";"));
187+
if (idx !== -1) {
188+
newTermsOrder.splice(idx + 1, 0, crntTerm);
189+
} else {
190+
// Push the item at the end if the parent couldn't be found
191+
newTermsOrder.push(crntTerm);
192+
}
193+
}
194+
} else {
195+
newTermsOrder = crntTerms;
196+
}
197+
198+
++pathLevel;
199+
} else {
200+
itemsToSort = false;
201+
}
202+
}
203+
return newTermsOrder;
204+
}
205+
206+
/**
163207
* Sort the terms by their path
208+
*
164209
* @param a term 2
165210
* @param b term 2
166211
*/
167-
public static sortTerms(a: ITerm, b: ITerm) {
212+
private static sortTermByPath(a: ITerm, b: ITerm) {
168213
if (a.PathOfTerm < b.PathOfTerm) {
169214
return -1;
170215
}

src/services/PnPTermStorePickerService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,7 @@ export default class PnPTermStorePickerService implements ISPTermStorePickerServ
194194
}
195195
await this._ensureTermStores();
196196
const pnpTermStores = this._pnpTermStores;
197-
for (let i = 0, len = pnpTermStores.length; i < len; i++) {
198-
const pnpTermStore = pnpTermStores[i];
197+
for (const pnpTermStore of pnpTermStores) {
199198
const termsResult: any = await this._tryGetAllTerms(pnpTermStore, termSet).catch((error) => { }); // .catch part is needed to proceed if there was a rejected promise
200199
if (!termsResult) { // terms variable will be undefined if the Promise has been rejected. Otherwise it will contain an array
201200
continue;
@@ -226,7 +225,7 @@ export default class PnPTermStorePickerService implements ISPTermStorePickerServ
226225
await labelsBatch.execute();
227226
}
228227

229-
return resultTerms;
228+
return TermStorePickerServiceHelper.sortTerms(resultTerms);
230229
}
231230

232231
}
@@ -397,12 +396,12 @@ export default class PnPTermStorePickerService implements ISPTermStorePickerServ
397396
pnpTerm.termSet.group.inBatch(batch).usingCaching().get().then(pnpTermGroup => {
398397
pickerTerm.termGroup = TermStorePickerServiceHelper.cleanGuid(pnpTermGroup.Id);
399398
});
400-
399+
401400
pnpTerm.termSet.inBatch(batch).usingCaching().get().then(pnpTermSet => {
402401
pickerTerm.termSet = TermStorePickerServiceHelper.cleanGuid(pnpTermSet.Id);
403402
pickerTerm.termSetName = pnpTermSet.Name;
404403
});
405-
404+
406405
if (this.props.includeLabels) {
407406
pnpTerm.labels.inBatch(batch).usingCaching().get().then(labels => {
408407
pickerTerm.labels = labels.map(label => label.Value);
@@ -635,4 +634,4 @@ export default class PnPTermStorePickerService implements ISPTermStorePickerServ
635634

636635
return null;
637636
}
638-
}
637+
}

src/services/SPTermStorePickerService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ export default class SPTermStorePickerService implements ISPTermStorePickerServi
172172
});
173173
// Check if the term set was not empty
174174
if (terms.length > 0) {
175-
// Sort the terms by PathOfTerm
176-
return terms.sort(TermStorePickerServiceHelper.sortTerms);
175+
// Sort the terms by PathOfTerm and their depth
176+
return TermStorePickerServiceHelper.sortTerms(terms);
177177
}
178178
}
179179
return null;

0 commit comments

Comments
 (0)