Skip to content

Commit d7143cd

Browse files
committed
bugfix: duplicate properties (#276)
1 parent 6e21062 commit d7143cd

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

app/components/api-index-filter.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export default Component.extend({
4747
if (!this.get('filterData.showDeprecated')) {
4848
items = items.filter(item => item.deprecated !== true);
4949
}
50-
return _.uniq(_.sortBy(items, 'name'), true, (item => item.name));
50+
let sortedUniqueItems = _.uniq(_.sortBy(items, 'name'), true, (item => item.name));
51+
return this.filterMultipleInheritance(sortedUniqueItems)
5152
},
5253

5354
filteredData: computed('filteredMethods', 'filteredProperties', 'filteredEvents', function() {
@@ -56,6 +57,24 @@ export default Component.extend({
5657
properties: this.get('filteredProperties'),
5758
events: this.get('filteredEvents')
5859
};
59-
})
60+
}),
6061

61-
});
62+
/**
63+
* Show the most local property if there are duplicate properties of the same name.
64+
* The docs for the nearest inheritance are typically more helpful to users.
65+
* Ember-jsonapi-docs returns a mix of inherited/local, but once sorted, the
66+
* first item in the list is "most local."
67+
* @method filterMultipleInheritance
68+
*/
69+
filterMultipleInheritance(items) {
70+
return items.filter(function(item, index, arr) {
71+
if (index === 0) {
72+
return true;
73+
} else if (item.name === arr[index - 1].name) {
74+
return false;
75+
} else {
76+
return true;
77+
}
78+
})
79+
}
80+
})

0 commit comments

Comments
 (0)