Skip to content

Commit

Permalink
Sort extension based recommendations based on recommended date #34233
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Sep 21, 2017
1 parent b86108e commit 95dbb89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ export class ExtensionTipsService implements IExtensionTipsService {
getRecommendations(): string[] {
const allRecomendations = this._getAllRecommendationsInProduct();
const fileBased = Object.keys(this._fileBasedRecommendations)
.filter(recommendation => allRecomendations.indexOf(recommendation) !== -1);
.filter(recommendation => allRecomendations.indexOf(recommendation) !== -1)
.sort((a, b) => {
return this._fileBasedRecommendations[a] > this._fileBasedRecommendations[b] ? -1 : 1;
});

const exeBased = distinct(this._exeBasedRecommendations);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ export class ExtensionsListView extends CollapsibleView {
}
options.source = 'recommendations-all';
return this.extensionsWorkbenchService.queryGallery(assign(options, { names, pageSize: names.length }))
.then(pager => new PagedModel(pager || []));
.then(pager => {
this.sortFirstPage(pager, names);
return new PagedModel(pager || []);
});
});
});
}
Expand All @@ -321,7 +324,10 @@ export class ExtensionsListView extends CollapsibleView {
}
options.source = 'recommendations';
return this.extensionsWorkbenchService.queryGallery(assign(options, { names, pageSize: names.length }))
.then(pager => new PagedModel(pager || []));
.then(pager => {
this.sortFirstPage(pager, names);
return new PagedModel(pager || []);
});
});
}

Expand Down Expand Up @@ -355,6 +361,21 @@ export class ExtensionsListView extends CollapsibleView {
.then(result => new PagedModel(result));
}

// Sorts the firsPage of the pager in the same order as given array of extension ids
private sortFirstPage(pager: IPager<IExtension>, ids: string[]) {
if (ids.length === pager.pageSize) {
let newArray = new Array(pager.pageSize);
for (let i = 0; i < pager.pageSize; i++) {
let index = ids.indexOf(pager.firstPage[i].id);
if (index === -1) {
return;
}
newArray[index] = pager.firstPage[i];
}
pager.firstPage = newArray;
}
}

private setModel(model: IPagedModel<IExtension>) {
this.list.model = model;
this.list.scrollTop = 0;
Expand Down

0 comments on commit 95dbb89

Please sign in to comment.