mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
fixed extension filter and search (#1301)
* fixed extension filter and search
This commit is contained in:
@@ -456,6 +456,8 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
* @param galleryExtensions
|
||||
*/
|
||||
private createQueryResult(query: Query, galleryExtensions: IRawGalleryExtension[]): { galleryExtensions: IRawGalleryExtension[], total: number; } {
|
||||
|
||||
// Filtering
|
||||
let filteredExtensions = galleryExtensions;
|
||||
if (query.criteria) {
|
||||
const ids = query.criteria.filter(x => x.filterType === FilterType.ExtensionId).map(v => v.value.toLocaleLowerCase());
|
||||
@@ -466,12 +468,60 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
|
||||
if (names && names.length > 0) {
|
||||
filteredExtensions = filteredExtensions.filter(e => e.extensionName && e.publisher.publisherName && names.includes(`${e.publisher.publisherName.toLocaleLowerCase()}.${e.extensionName.toLocaleLowerCase()}`));
|
||||
}
|
||||
const searchTexts = query.criteria.filter(x => x.filterType === FilterType.SearchText).map(v => v.value.toLocaleLowerCase());
|
||||
if (searchTexts && searchTexts.length > 0) {
|
||||
searchTexts.forEach(searchText => {
|
||||
if (searchText !== '@allmarketplace') {
|
||||
filteredExtensions = filteredExtensions.filter(
|
||||
e => e.extensionName && e.extensionName.includes(searchText) ||
|
||||
e.publisher && e.publisher.publisherName && e.publisher.publisherName.includes(searchText) ||
|
||||
e.publisher && e.publisher.displayName && e.publisher.displayName.includes(searchText) ||
|
||||
e.displayName && e.displayName.includes(searchText) ||
|
||||
e.shortDescription && e.shortDescription.includes(searchText) ||
|
||||
e.extensionId && e.extensionId.includes(searchText)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Sorting
|
||||
switch (query.sortBy) {
|
||||
case SortBy.PublisherName:
|
||||
filteredExtensions.sort( (a, b) => ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'));
|
||||
break;
|
||||
case SortBy.Title:
|
||||
default:
|
||||
filteredExtensions.sort( (a, b) => ExtensionGalleryService.compareByField(a, b, 'displayName'));
|
||||
break;
|
||||
}
|
||||
|
||||
let actualTotal = filteredExtensions.length;
|
||||
return { galleryExtensions: filteredExtensions, total: actualTotal };
|
||||
}
|
||||
|
||||
public static compareByField(a: any, b: any, fieldName: string): number {
|
||||
if (a && !b) {
|
||||
return 1;
|
||||
}
|
||||
if (b && !a) {
|
||||
return -1;
|
||||
}
|
||||
if (a && a[fieldName] && (!b || !b[fieldName])) {
|
||||
return 1;
|
||||
}
|
||||
if (b && b[fieldName] && (!a || !a[fieldName])) {
|
||||
return -1;
|
||||
}
|
||||
if (!b || !b[fieldName] && (!a || !a[fieldName])) {
|
||||
return 0;
|
||||
}
|
||||
if (a[fieldName] === b[fieldName]) {
|
||||
return 0;
|
||||
}
|
||||
return a[fieldName] < b[fieldName] ? -1 : 1;
|
||||
}
|
||||
|
||||
private queryGallery(query: Query): TPromise<{ galleryExtensions: IRawGalleryExtension[], total: number; }> {
|
||||
return this.commonHeadersPromise.then(commonHeaders => {
|
||||
const data = JSON.stringify(query.raw);
|
||||
|
||||
@@ -13,7 +13,8 @@ import { parseArgs } from 'vs/platform/environment/node/argv';
|
||||
import { getRandomTestPath } from 'vs/workbench/test/workbenchTestServices';
|
||||
import { join } from 'path';
|
||||
import { mkdirp } from 'vs/base/node/pfs';
|
||||
import { resolveMarketplaceHeaders } from 'vs/platform/extensionManagement/node/extensionGalleryService';
|
||||
// {{SQL CARBON EDIT}}
|
||||
import { resolveMarketplaceHeaders, ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService';
|
||||
import { isUUID } from 'vs/base/common/uuid';
|
||||
|
||||
suite('Extension Gallery Service', () => {
|
||||
@@ -48,4 +49,49 @@ suite('Extension Gallery Service', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// {{SQL CARBON EDIT}}
|
||||
test('sortByField', () => {
|
||||
let a = {
|
||||
extensionId: undefined,
|
||||
extensionName: undefined,
|
||||
displayName: undefined,
|
||||
shortDescription: undefined,
|
||||
publisher: undefined
|
||||
};
|
||||
let b = {
|
||||
extensionId: undefined,
|
||||
extensionName: undefined,
|
||||
displayName: undefined,
|
||||
shortDescription: undefined,
|
||||
publisher: undefined
|
||||
};
|
||||
|
||||
|
||||
assert.equal(ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'), 0);
|
||||
|
||||
a.publisher = { displayName: undefined, publisherId: undefined, publisherName: undefined};
|
||||
assert.equal(ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'), 1);
|
||||
|
||||
b.publisher = { displayName: undefined, publisherId: undefined, publisherName: undefined};
|
||||
assert.equal(ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'), 0);
|
||||
|
||||
a.publisher.publisherName = 'a';
|
||||
assert.equal(ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'), 1);
|
||||
|
||||
b.publisher.publisherName = 'b';
|
||||
assert.equal(ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'), -1);
|
||||
|
||||
b.publisher.publisherName = 'a';
|
||||
assert.equal(ExtensionGalleryService.compareByField(a.publisher, b.publisher, 'publisherName'), 0);
|
||||
|
||||
a.displayName = 'test1';
|
||||
assert.equal(ExtensionGalleryService.compareByField(a, b, 'displayName'), 1);
|
||||
|
||||
b.displayName = 'test2';
|
||||
assert.equal(ExtensionGalleryService.compareByField(a, b, 'displayName'), -1);
|
||||
|
||||
b.displayName = 'test1';
|
||||
assert.equal(ExtensionGalleryService.compareByField(a, b, 'displayName'), 0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user