Fix sorting by Item Type and feed item itemID
Regression from a8ed30ce80
This commit is contained in:
parent
3a160b2630
commit
56e7f0a10f
2 changed files with 18 additions and 7 deletions
|
@ -1826,6 +1826,10 @@ var ItemTree = class ItemTree extends LibraryTree {
|
|||
|
||||
getSortFields() {
|
||||
var fields = [this.getSortField()];
|
||||
if (!this._isValidSortField(fields[0])) {
|
||||
Zotero.logError(`'${fields[0]}' is not a valid sort field -- skipping`);
|
||||
fields.shift();
|
||||
}
|
||||
var secondaryField = this._getSecondarySortField();
|
||||
if (secondaryField) {
|
||||
fields.push(secondaryField);
|
||||
|
@ -1849,12 +1853,8 @@ var ItemTree = class ItemTree extends LibraryTree {
|
|||
fallbackFields = Zotero.Prefs.get('fallbackSort').split(',');
|
||||
}
|
||||
fields = Zotero.Utilities.arrayUnique(fields.concat(fallbackFields));
|
||||
var validFields = fields.filter(x => this._isValidSortField(x));
|
||||
if (validFields.length) {
|
||||
fields = validFields;
|
||||
}
|
||||
// If no valid fields, use default fallback
|
||||
else {
|
||||
if (!fields.length) {
|
||||
Zotero.logError(`No valid fields in getSortFields() (${fields.join(',')}) `
|
||||
+ '-- resetting');
|
||||
Zotero.Prefs.clear('fallbackSort');
|
||||
|
@ -1874,7 +1874,9 @@ var ItemTree = class ItemTree extends LibraryTree {
|
|||
}
|
||||
|
||||
_isValidSortField(field) {
|
||||
return field == 'year'
|
||||
return field == 'itemType'
|
||||
|| field == 'year'
|
||||
|| field == 'id' // feeds
|
||||
|| !!Zotero.ItemFields.getID(field)
|
||||
|| Zotero.Items.primaryFields.includes(field);
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ describe("Zotero.ItemTree", function() {
|
|||
})
|
||||
|
||||
describe("#getSortFields()", function () {
|
||||
before(async function () {
|
||||
beforeEach(async function () {
|
||||
itemsView = zp.itemsView;
|
||||
|
||||
// Sort by title
|
||||
|
@ -183,6 +183,15 @@ describe("Zotero.ItemTree", function() {
|
|||
// fallbackSort pref with title moved to beginning
|
||||
assert.sameMembers(['title', 'firstCreator', 'date', 'dateAdded'], fields);
|
||||
});
|
||||
|
||||
it("should sort by item type", async function () {
|
||||
// Sort by item type
|
||||
const colIndex = itemsView.tree._getColumns().findIndex(column => column.dataKey == 'itemType');
|
||||
await itemsView.tree._columns.toggleSort(colIndex);
|
||||
|
||||
var fields = itemsView.getSortFields();
|
||||
assert.sameMembers(['itemType', 'firstCreator', 'date', 'title', 'dateAdded'], fields);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#notify()", function () {
|
||||
|
|
Loading…
Reference in a new issue